AWS Amplify - how to get “Cognito Identity Id” from Cognito

1

There appears to be two different ids that identify users in an AWS Amplify project that uses AWS Cognito:

  • “Cognito Identity Id” and…
  • “Cognito Sub”

Is there any way to get a “Cognito Identity Id” purely from Cognito itself, using the CognitoIdentityServiceProvider? For example, if a new user is created programmatically and there’s an associated table indexed on their “cognito identity id” and I want to set values in that table before the user logs in. It seems like it is only exposed in requests by that actual user.


For more context on what I understand these terms to be:

  1. Cognito Identity Id

    • Is this the id from the identity pool?
    • This is a uuid with the region prefixed, e.g.,: "us-east-1:12345678-beef-cafe-face-1234567890ab"
    • Accessed via:
      • In frontend code with the Auth module: Auth.currentUserInfo().then(user => user.id)
      • In backend API requests for an authenticated user: req.apiGateway.event.requestContext.identity.cognitoIdentityId
      • Not available in the results of: new AWS.CognitoIdentityServiceProvider().listUsers(params)
    • Notes:
      • This id is treated as a "userId" in various Amplify examples/docs
      • I’ve seen examples of people saving this manually in Cognito with a custom parameter of "custom:identity_id", which can only be set during an authenticated request by that user
  2. Cognito Sub

    • This appears to be something like a unique id for the user pool?
    • This is a uuid
    • Accessed via:
      • In frontend code with the Auth module: Auth.currentUserInfo().then(user => user.attributes.sub)
      • In backend API requests for an authenticated user: req.apiGateway.event.requestContext.identity.cognitoAuthenticationProvider.match(/CognitoSignIn:([^:]+)$/)[1]
      • In the results of CognitoIdentityServiceProvider queries
PeterFP
질문됨 일 년 전256회 조회
1개 답변
0

Hi,

you are right:

Jeff

AWS
답변함 9달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠