Cognito issued JWT does not contain user roles

0

According to this SO - User roles in Amazon Cognito the user roles should be available in the JWT returned by Cognito. However when inspecting the JWT I don't see any roles nor the cognito:groups claim that is supposedly there.

From what I understood these scopes were needed for this to work:

Enter image description here

Is there a specific option that needs to be enabled as well? Am I supposed to use a Pre authentication Lambda trigger for this?

Notes:

  • We have configured Congito to use IAM Identity Center SAML application as the external identity provider.
已提问 9 个月前610 查看次数
1 回答
1
已接受的回答

Hi,

While you configured the Client Application to be able to use the scopes aws.cognito.signin.user.admin, Email, OpenID, Profile, you need to request them so that the token issued includes the necessary scopes.

Please ensure that when your Client is doing an Authorization call to Cognito on the /oauth2/authorize endpoint it includes all the necessary scopes in the request as defined in the query string parameter scope - see documentation https://docs.aws.amazon.com/cognito/latest/developerguide/authorization-endpoint.html

Cognito when it receives an authorization request on /oauth2/authorize first checks that the scopes requested are part of the scopes authorized for this client id. Then it issues an authorization code that can be exchanged for JWTs. Those JWTs will only include the scopes requested during the authorize call. If you miss a scope, Cognito will not fill that out based on the list of scopes authorized. An if you miss the scope that can allow to read the group membership / role memebership, those won't be included in the JWTs.

Jeff

AWS
已回答 9 个月前
  • Yep... I was missing the openid scope. Thanks! :)

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

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

回答问题的准则