How to add Auth0 as SAML Identity Provider in AWS Cognito

karthik
3 min readApr 28, 2023

--

Introduction

AWS Cognito is one of the most widely used Identity Provider. There are scenarios where a customer who uses AWS Cognito wants to setup SAML federation between Cognito and Auth0. For ex: As an organization, I can build a product which is integrated with AWS Cognito using OIDC. If a customer of my product wants their employees or contractors to login using their own Identity Provider like Auth0, Okta, AzureAD etc., I can setup a federation between AWS Cognito and Auth0, Okta, AzureAD etc. to allow those employees or contractors to access my product.

In this blog, we are going to see how to setup the federation between AWS Cognito and Auth0 using SAML protocol.

  1. User opens a browser and types the client app URL
  2. Browser displays the client app website. Depending on how the client app is designed, it might automatically initiate an Authentication flow with AWS Cognito or display the home page where users should click the login button to initiate the Authentication. This diagram shows the first option where the client app automatically initiates the OIDC flow with AWS Cognito by redirecting the user to /authorize URL.
  3. AWS Cognito receives the request from client app and either displays the login page with a button to initiate the SAML federation or automatically initiate the SAML federation with Auth0 by sending a SAML AuthnRequest to SAML Sign-On URL.
  4. Auth0 will display the login page to the user.
  5. User will enter the credetials.
  6. Auth0 will validate the credentials and proceed to next step if it is valid.
  7. Auth0 will return a SAML Response back to AWS Cognito.
  8. AWS Cognito will verify the SAML Assertion, create a user profile in the local user pool for this Auth0 user if it doesn’t exist.
  9. AWS Cognito will redirect back to Client app with an authorization code.
  10. Client app will make a backend API call to Cognito’s token endpoint to get the ID and Access tokens
  11. AWS Cognito will return and ID and Access tokens
  12. Client app will validate the ID token, check if it is a valid user and return the web page to the browser

How to configure AWS Cognito — Auth0 SAML integration

Please follow this video for the step-by-step instructions

Key points to note

  • When a user logs in for the first time, AWS Cognito will create a profile for that user in the local user pool. The tokens that are generated by Cognito will be based on the attribute values of Cognito user profile
  • Please make sure all the attributes are mapped properly in the Cognito SAML attribute mapping configuration. All the SAML attribute names from Auth0 should match with the claim name in above screenshot. Follow this guide.
  • Please make sure Auth0 SAML application to return all the required attributes of the user
  • Please note that the user created from Auth0 console won’t have all the attributes like first name, last name etc. You need to manually call the Auth0 user management APIs to set these attributes as mentioned in the video. Otherwise, it will be null and those SAML attributes won’t have any value.

Thanks for reading this article. Please subscribe to the below YouTube channel and follow me in medium to learn about security and IAM.

--

--