cognitojwt | Decode and verify Amazon Cognito JWT tokens | AWS library
kandi X-RAY | cognitojwt Summary
kandi X-RAY | cognitojwt Summary
Decode and verify Amazon Cognito JWT tokens
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Decodes a token asynchronously
- Builds the public key from the given token
- Ensure that the token_use token_use is valid
- Get a list of keys
- Check if token is expired
- Get unverified headers
- Get unverified claims from a JWT
- Verify token signature
- Construct the public key from the given token
- Returns a list of keys from the server
cognitojwt Key Features
cognitojwt Examples and Code Snippets
Community Discussions
Trending Discussions on cognitojwt
QUESTION
My mobile App currently performs SSO using following steps
- User will select one of the IDP from the list on the Mobile APP and click Login
- Mobile App will instenciate in-app browser control and navigate to SSO URL
- If not already authenticated IDP challenges user for authentication
- User will be presented with the login form to enter his/her credentials.
- Once user is authenticated successfully by IDP, the SAML Assertion will be passed to
Web Server
Web Server
trusts IDP, accepts SML token and generates Session token- Mobile Browser component accepts the session token and share it with native mobile app
- Mobile App calls
web server
APIs with this session token
Now due to security reasons Session token is not advisable to be stored on Mobile Device, whereas OIDC or JWT tokens can be stored
As my Web Application does not support generating OIDC tokens so I thought of adding one more layer of AWS Cognito in between my mobile device and IDP. Now the authentication flow will be like (SAML User Pool IdP Authentication flow)
- The mobile app starts the sign-in process by directing the user to the UI hosted by AWS.
- User is redirected to the identity provider.
- The IdP authenticates the user if necessary. If the IdP recognizes that the user has an active session, the IdP skips the authentication to provide a single sign-in (SSO) experience.
- The IdP POSTs the SAML assertion to the Amazon Cognito service.
- After verifying the SAML assertion and collecting the user attributes (claims) from the assertion, Amazon Cognito returns OIDC tokens to the mobile app for the now signed-in user.
Now my question is once I have OIDC token, how mobile App will call my web server
for any API calls? Is it through Cognito? Direct call to my web server will not work as it does not understand the OIDC token returned by Cognito? How I can achieve this communication from Mobile App to my Web server?
UPDATE: I was able to validate the JWT token from my web server issued by Cognito. If anyone else is looking to do the same then they can refer this cognitojwt library (not written by me just found it on internet)
...ANSWER
Answered 2020-Apr-07 at 10:44OIDC tokens returned by Cognito are ID Token and Access Token, both are JWT. You can pass these to your custom backend directly (most commonly in Authorization
header).
On the backend you should decode and verify the token using your user pool's public key (JWK). JWK is available at https://cognito-idp.{region}.amazonaws.com/{userPoolId}/.well-known/jwks.json
. If token is valid and not expired, you can trust it and use it for custom backend authorization logic.
The whole process of verifying tokens is described here https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-using-tokens-verifying-a-jwt.html and there are a number of open source libraries which will help you do that.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install cognitojwt
Async mode - pip install cognitojwt[async]
Sync mode - pip install cognitojwt[sync]
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page