Cognito preferred_username and access tokens

0

I've got a Cognito User Pool set up that has the preferred_username set up to work correctly as an alias for username. This means that I can have users - local and federated - able to change their "preferred_username" value and it all works correctly, including ensuring that the values are always unique. It also means that I can use admin-get-user by username and it matches across both fields, and all is good. So far - fantastic.

However, it seems that when I have a user authenticate, neither the Access Token nor the ID Token contains the "preferred_username" field. They do contain the "username" but this is the original one and not the new value if it's been changed.

My desire is to have an API home document that, if the API call is authenticated, contains a link to the Users resource for the user. And ideally that link would be by preferred_username if set - the same way that admin-get-user works.

Am I right that the only way to do this is to get the "username" from the access token, and then make a subsequent API call to get the user details in order to determine the "preferred_username" value? Or is there some way to have the Access Token or ID Token contain the "preferred_username" value?

Cheers

질문됨 일 년 전579회 조회
1개 답변
0

Hey,

Not sure what language or setup you are using here but can you check to see if the claims returned in the authenticated user has the info you need?

Thanks

답변함 일 년 전
  • Hi there,

    I've already checked and they don't. They have the username field, but if there is a preferred_username set then this isn't present.

    What I'm not sure about is if there's some way to configure things so that it is present, or if it's just not an option.

    Cheers

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

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

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