MayQuartet
MayQuartet

Reputation: 51

How can I Get AWS Cognito id token From Google Login?

I looked it up for a month but couldn't find it. Unity and Google login links, Google and aws cognito links, and cognito and unity links exist, respectively, but I have not found a way to handle them at once.

I could follow this Document and get AWS Credentials. However, it only provides access tokens for authorization, not ID token for authentication.

So, How can I Get AWS Cognito id token From Google Login?

I don't want to use the hosting UI provided by this post. I learned how to get an ID token from a post, but I want to know how to find it without opening an external browser in the app.

Upvotes: 1

Views: 675

Answers (1)

Isha Narola
Isha Narola

Reputation: 1

Create a custom Auth token provider which is helpful to get cognito token for various federated service provider.

import { Amplify } from 'aws-amplify';
import { TokenProvider, decodeJWT } from 'aws-amplify/auth';

const myTokenProvider: TokenProvider = {
  async getTokens({ forceRefresh } = {}) {
    if (forceRefresh) {
      // try to obtain new tokens if possible
    }

    const accessTokenString = '<insert JWT from provider>'; // google token
    const idTokenString = '<insert JWT from provider>'; // google token
    
    return {
      accessToken: decodeJWT(accessTokenString),
      idToken: decodeJWT(idTokenString),
    };
  },
};

Amplify.configure(awsconfig, {
  Auth: {
    tokenProvider: myTokenProvider
  }
});

Here is the link of documentation , visit it https://docs.amplify.aws/javascript/build-a-backend/auth/advanced-workflows/#custom-token-providers

Upvotes: 0

Related Questions