Monday, 8 February 2021

AWS Cognito SSO Integration with Python

AWS Cognito SSO Integration with Python

AWS SSO Cognito OAuth2.0 implementation as per below URL:

https://aws.amazon.com/blogs/mobile/understanding-amazon-cognito-user-pool-oauth-2-0-grants/

First we need to create code, get Client ID and Client Secret. Run below URL:

https://AUTH_DOMAIN/login?client_id=XXXXXXXXXX&response_type=code&scope=email+openid&redirect_uri=http://localhost/test/sso_check

Above URL will return to redirect url with code in query string.

Note: Code is valid for one time transaction only.

Get Access Token using the Code as per below description:



Make below request:





this will return below response:

{
    "id_token": "eyJraWQiOiJJNGs2UXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "access_token": "eyJraWQiOiJENllqdXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "refresh_token": "eyJjdHkiOiJKV1QiLCJlbmXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "expires_in": 3600,
    "token_type": "Bearer"
}


From above response we need to use id_token to get user information:

  • id_token – A valid user pool ID token. Note that an ID token is only provided if the openid scope was requested.
Below is the Python code Github URL to get user information by validating JWT token returned in id_token key.






Below is the response from above Python code:



Create .ICS file using PHP code

Recently worked on creating a .ics file in PHP after a very long time, code so thought to share with everybody. Please find below the comple...