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

已提问 1 年前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

已回答 1 年前
  • 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

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则