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

Add option to choose between id token and access token #44

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ckng0221
Copy link

@ckng0221 ckng0221 commented Feb 24, 2023

Fixes #22

User can define to use id token or access token in settings.py.
Without defining, it by default take id token.

COGNITO_TOKEN_TYPE = "access"  # '{'id', 'access'} Default: 'id'

The client_id from access token will be validated whether it matches the one defined in the `settings.COGNITO_AUDIENCE`.
When using access token, the backend will call the userinfo endpoint from Amazon Cognito, to obtain the user info based on the access key, and pass into the payload inside the Django user_model's get_or_create_for_cognito method.
Split the method into get_user and create_for_cognito.
Spliting the method into two allows more efficient calling of the method, especially  when using access token.
The get_user method will first check whether the user exists. If exists, it will directly skip the get requests from UserInfo endpoint, and also skip the attempt for user creation, and directly return the user object.

The UserInfo endpoint will be only called during the initial registeration of the client that does not exist in User database.
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

Successfully merging this pull request may close these issues.

Unable to accept Cognito Access Tokens
1 participant