Search code examples
javascriptoauth-2.0google-oauthgoogle-identitygoogle-smartlockpasswords

Google one-tap sign-in/sign-up, Access personal Data


I just started using google on-tap sing-in/sign-up in my new app. It works perfectly except that I don't know how can I ask user permissions to access scoped data?

client.verifyIdToken(
    token,
    CLIENT_ID,
    function(e, login) {
      var payload = login.getPayload(); // <-- payload just containt name,email and picture. I want more
      var userid = payload['sub']; 
    });

Solution

  • You can use Google Sign-In to authorize more scopes. Pass the email address of the account returned by One-Tap as the login_hint parameter to the gapi.auth2.init call, then call gapi.auth2.getAuthInstance().signIn() so that the user can grant access to the other scopes your app require.

    You can also use gapi.auth2.authorize for One-Off authorization (if you use gapi.client to perform requests to Google APIs, you generally want to use init/signIn).