Username instead of email in Cognito JWT access token claims
See original GitHub issueHi,
I would like to ask about email
being present in Cognito JWT access token claims.
According to congito documentation it should include username
and not email
.
I don’t see any option to change that behaviour based on create_jwt
method:
def create_access_token(self, client_id, username):
extra_data = {}
user = self._get_user(username)
if len(user.groups) > 0:
extra_data["cognito:groups"] = [group.group_name for group in user.groups]
access_token, expires_in = self.create_jwt(
client_id, username, "access", extra_data=extra_data
)
self.access_tokens[access_token] = (client_id, username)
return access_token, expires_in
def create_jwt(
self, client_id, username, token_use, expires_in=60 * 60, extra_data=None
):
now = int(time.time())
payload = {
"iss": "https://cognito-idp.{}.amazonaws.com/{}".format(
self.region, self.id
),
"sub": self._get_user(username).id,
"aud": client_id,
"token_use": token_use,
"auth_time": now,
"exp": now + expires_in,
"email": flatten_attrs(self._get_user(username).attributes).get("email"),
}
payload.update(extra_data or {})
headers = {"kid": "dummy"} # KID as present in jwks-public.json
return (
jws.sign(payload, self.json_web_key, headers, algorithm="RS256"),
expires_in,
)
Do you consider that as a bug or kind of deprecation?
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Using tokens with user pools - Amazon Cognito
Authenticate users and grant access to resources with tokens. Tokens have claims, which are pieces of information about the user. The ID token...
Read more >How to get user attributes (username, email, etc.) using ...
AccessToken · 1. This great for getting the ID. But can you use getCurrentUser() to find the email attribute instead of ID? –...
Read more >Using the access token - Amazon Cognito
The user pool access token contains claims about the authenticated user, a list of the user's ... The access token is represented as...
Read more >Authenticate with a backend server - Google Developers
After a user successfully signs in, get the user's ID token: ... the JWT signature, the aud claim, the iss claim, and the...
Read more >Authentication - Advanced workflows - JavaScript - Amplify Docs
Note that this isn't from a Cognito User Pool so the user you get after calling ... After the federated login, you can...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Whenever somebody feels like tackling this, @mglowinski93 - there are no timelines here.
Everything is open-source, so if you want to have a look, PR’s are always welcome! http://docs.getmoto.org/en/latest/docs/contributing/index.html
Sorry for pushy question, but when can we get the fix for that issue?