Using custom ID instead of Cognito ID (sub)

0

Is there a tutorial somewhere showing how to set up a custom auth flow that uses a custom ID (custom:id, configure as an optional attribute) instead of the Cognito ID?

已提問 1 年前檢視次數 854 次
3 個答案
0

Hello,

From the description of the issue, I can see that you wish to implement the custom authentication flow by using a custom attribute of your user instead of using its sub ID.

I would like to mention that the authentication flow starts with a call to the InitiateAuth API operation[1]. Now, we have to pass the user's username as an auth parameter to the API[2]. Here, I would like to mention that if we have configured our userpool to use email/phone_number as sign-up/sign-in option then we can pass the sub ID as well to the auth parameter of the API as in this case, the value for the username and the sub attribute of the authenticated user would be the same unique identifier UUID[3]. Currently, it is not possible to start the sign-in for a user by passing any other attribute or custom attribute of the user as an auth parameter.

If you wish to use the custom attribute of your user for some validation, then you have to create a custom challenge in your Lambda function involving that attribute and present it to the user as a challenge, once the authentication has initiated. Please refer the documentation[4][5] for sample code snippets for creating custom challenges.

[1]. https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_InitiateAuth.html

[2]. https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-define-auth-challenge.html

[3]. https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-using-the-id-token.html

[4]. https://aws.amazon.com/blogs/mobile/extending-amazon-cognito-with-email-otp-for-2fa-using-amazon-ses/

[5]. https://github.com/aws-samples/amazon-cognito-passwordless-email-auth

AWS
支援工程師
已回答 1 年前
0

Thank you. Actually I may have this backward. It might sufficient for my needs that the Cognito POST API with the AccessToken as payload that returns a {"UserAttributes": {...}, "Username": "..."} dictionary include the custom ID in the attributes. Currently it includes only the sub, email and email_verified attributes.

已回答 1 年前
0

Never mind, I found out: you just need to make the custom attribute readable for the selected app.

已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南