How to get SUB from aws cognito token

Viewed 1963

I am trying to use the cognito generated unique id knows as SUB to be a PK in my tables. But I am not able to get this SUB in the response of the first sign-up call. I am using the latest version of the sdk for android:

aws-android-sdk-cognitoidentityprovider:2.9.1

Can somebody guide me on how or where I can get this id?

The same question was asked on this thread but none of them works https://github.com/amazon-archives/amazon-cognito-identity-js/issues/335

2 Answers

You can get the sub from the ID token (which is a JWT) after you have signed in. After you have signed in using the AWSMobileClient, you can do something like the following to get the sub

 AWSMobileClient.getInstance().getTokens().getIdToken().getClaim("sub")

sub can be taken if we have accesstoken

CognitoJWTParser.getClaim(accessToken.getJWTToken(), "sub")

Related