简体   繁体   中英

How can I get a user's Google account photo using IAP and the People API? (NodeJS preferred)

I have an application that uses Google Cloud IAP to authenticate users. IAP requires the user to authenticate using their Google account, and then headers are passed to the application afterwards that identify that user (user id, user email, and a token).

I would like to get the user's Google account photo after authentication using the People API (would use the Plus api, but it is being shut down).

NodeJS code examples would help a ton, but either a high level guide or examples in other languages would also be very helpful. Thanks in advance!

For anyone that may come across this, here is the solution I found.

You will need to enable the People API in your GCP console. Then create an API key for it.

Get the 'x-goog-authenticated-user-id' header and strip the 'accounts.google.com:' portion of it to just leave the id.

Pass that id and your api key to a GET request, like so:

https://content-people.googleapis.com/v1/people/${userId}?personFields=photos&key=${apiKey}

Hope this helps someone else, too!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM