Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cognito-idp: missing readable attributes in JWT payload #1755

Closed
ferruvich opened this issue Aug 7, 2018 · 0 comments
Closed

Cognito-idp: missing readable attributes in JWT payload #1755

ferruvich opened this issue Aug 7, 2018 · 0 comments

Comments

@ferruvich
Copy link
Contributor

While testing the JWT payload verification part in my app, i've noticed that moto ignores the pool client readable attributes in JWT payload.
Here's a working example:

User Pool And App Client creation

cognito_client = boto3.client('cognito-idp')

create_response = cognito_client.create_user_pool(
    PoolName='user_pool'
)
client_id = cognito_client.create_user_pool_client(
    UserPoolId=create_response['UserPool']['Id'],
    ClientName='mock_pool_client',
    ReadAttributes=['custom:readable_attribute']
)['UserPoolClient']['ClientId']

User Creation

user = cognito_client.admin_create_user(
    UserPoolId=create_response['UserPool']['Id'],
    Username='mock@user.com',
    UserAttributes=[{
            'Name': 'custom:readable_attribute',
            'Value': 'readable_value'
    }],
    TemporaryPassword='temporary_password'
)['User']

User Confirmation and Token Retrieving

init_auth_response = cognito_client.admin_initiate_auth(
    UserPoolId=user_pool_id,
    ClientId=client_id,
    AuthFlow='ADMIN_NO_SRP_AUTH',
    AuthParameters={
        'USERNAME': user['Username'],
        'PASSWORD': 'temporary_password'
    },
)

auth_response = cognito_client.respond_to_auth_challenge(
    ClientId=client_id,
    Session=init_auth_response['Session'],
    ChallengeName=init_auth_response['ChallengeName'],
    ChallengeResponses={
        'USERNAME': user['Username'],
        'NEW_PASSWORD': 'definitive_password'
    }
)

In this way, we have the user's access token in auth_response['AuthenticationResult']['AccessToken'].

The token payload should be like this:

{
    "iss": "https://cognito-idp.eu-central-1.amazonaws.com/5f74a2d1-1965-4010-b5cd-a889e71abfab",
    "sub": "3e61257c-a209-4cbe-b408-da69c00f4352",
    "aud": "ecbe867f-9fac-42ee-8eea-e05e95157896",
    "token_use": "id",
    "auth_time": 1533646833,
    "exp": 1533650433,
    "custom:readable_attribute": "readable_value"
}

Instead, the payload appears to be like this:

{
    "iss": "https://cognito-idp.eu-central-1.amazonaws.com/5f74a2d1-1965-4010-b5cd-a889e71abfab",
    "sub": "3e61257c-a209-4cbe-b408-da69c00f4352",
    "aud": "ecbe867f-9fac-42ee-8eea-e05e95157896",
    "token_use": "id",
    "auth_time": 1533646833,
    "exp": 1533650433,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant