简体   繁体   中英

How do you use an iOS Google ID Token to fetch a user's full profile from the backend (Node JS)?

I'm using the Google Login iOS SDK to login, then passing GIDGoogleUser.authentication.idToken to the server, which I'm then verifying in Node JS. The verification in the code below works fine. "payload" var ends up being correct with basic information about the user.

How do I translate the idToken into credentials that I can use to git the people.get endpoint? (I want to know whether the user is using the default Google profile photo or not, and that is available from the people.get endpoint.) This does not seem to be documented anywhere. https://developers.google.com/people/api/rest/v1/people/get

var auth = new GoogleAuth;
      var client = new auth.OAuth2(GoogleUtils.clientIDs, '', '');
      client.verifyIdToken(
          token,
          GoogleUtils.clientIDs,
          // Or, if multiple clients access the backend:
          //[CLIENT_ID_1, CLIENT_ID_2, CLIENT_ID_3],
          function(e, login) {
            if (e) {
              return next(e, null);
            }
            var payload = login.getPayload();
            return next(null, payload);
          });

Thanks for your help. I can't seem to find any of this info in the documentation. Google's APIs are very poorly documented it seems.

Unfortunately, as noted, the current ID token payload does not say whether the photo is the default one (probably something we should add). If you need an access token to call Google's REST APIs (such as people.get) for more user data, then you need to obtain an OAuth auth code, and exchange it for access and refresh tokens, as documented at https://developers.google.com/identity/sign-in/ios/offline-access

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