3

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

Natsen
  • 181
  • 1
  • 6

2 Answers2

1

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")
Bommas
  • 228
  • 2
  • 5
  • Thanks Bommas, but I wanted the SUB before the first sign in. After the first successful sign-up call to cognito and before initiating the account activation process, that is when I wanted to get the SUB. Of course after signing in it will be in the JWT token. – Natsen Dec 23 '18 at 04:33
  • @Natsen, I work on the AWS Mobile SDK team will take this as a feature request to the team. If you don't mind, can you create a new github issue here ( https://github.com/aws-amplify/aws-sdk-android/issues) for tracking. – Bommas Dec 24 '18 at 22:25
  • Bommas as I have mentioned in the question this was raised before. Please check this link https://github.com/amazon-archives/amazon-cognito-identity-js/issues/335. But wasn't resolved. – Natsen Dec 30 '18 at 00:40
  • @Natsen, To better track this issue specifically for android please open an issue here https://github.com/aws-amplify/aws-sdk-android/issues – donkon Dec 31 '18 at 17:35
  • @Natsen This is being tracked in https://github.com/aws-amplify/aws-sdk-android/issues/635 issue. Thank you! – Karthikeyan Jan 07 '19 at 19:29
1

sub can be taken if we have accesstoken

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

Siva mbigai M
  • 601
  • 5
  • 3