question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Username instead of email in Cognito JWT access token claims

See original GitHub issue

Hi, 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:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
bblommerscommented, Jul 3, 2022

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

0reactions
mglowinski93commented, Jul 2, 2022

Sorry for pushy question, but when can we get the fix for that issue?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found