Search code examples
google-cloud-platformoauth-2.0nestjsgoogle-oauth

id Token vs access_token google login api in web


I was using access_token after sign in with Google, but the Google login has changed and I am trying to use it as id_token.

I received the email and id through the existing code below.

const userInfoClient = google.oauth2('v2').userinfo;

      this.oauthClient.setCredentials({
        access_token: tokenData.token,
      });

      const userInfoResponse = await userInfoClient.get({
        auth: this.oauthClient,
      });

The changed code is as follows. I receive various values ​​through the payload. I need email and id, but id value does not exist. Is nbf equal to id in access_token?

const ticket = await client.verifyIdToken({
          idToken: tokenData.token,
          audience: process.env.GOOGLE_CLIENT_ID,
        });

payload has values ​​such as iss,nbf,aud,sub,email,azp,name,picture,iat,exp,jti


Solution

  • The nbf stands for "Not Before" and it's a timestamp that specifies the time before which token cannot be used. The sub means "Subject" and is usually the user's UID that you might be looking for. Checkout RFC 7519 to learn more about the properties present in a JWT.