Since the user is already authenticated in App-B (which uses Auth0 behind the scenes), we expected the SSO flow to proceed without showing the Auth0 login screen again when redirecting to App-A via Cognito.
What We Suspect:
We understand that:
App-B uses a custom login screen(app-b.com/login), not Auth0’s Universal Login.
The core of the issue is that your custom login flow for App-B authenticates the user but doesn’t create a Single Sign-On (SSO) session at the Auth0 level. When Cognito redirects to Auth0, Auth0 has no record of an active session and therefore must ask the user to authenticate again.
The recommended solution is to adjust your custom login flow to use Auth0’s Cross-Origin Authentication. This allows you to keep your custom login UI hosted on your domain while still establishing the necessary SSO session cookie on the Auth0 domain upon successful login.
To achieve seamless SSO while keeping your custom UI, you can implement the Cross-Origin Authentication flow. This involves changing your custom login form to post the user’s credentials directly to Auth0.
Here’s a step-by-step guide:
Step 1: Configure Your Auth0 Application
Go to your Auth0 Dashboard > Applications > Applications and select the application used by App-B.
In the “Application URIs” section, add the origin of your custom login page (e.g., https://app-b.com) to the Allowed Web Origins list.
Ensure you have a URL for App-B registered in the Allowed Callback URLs list (e.g., https://app-b.com/callback). This is where Auth0 will send the user back after they log in.
Step 2: Modify Your Custom Login Form
Adjust your login form’s HTML to POST directly to the /usernamepassword/login endpoint on your Auth0 domain. You will need to include several hidden fields to pass the required OIDC parameters.
The browser posts the credentials directly to Auth0.
Auth0 validates them, sets the SSO session cookie on the Auth0 domain, and redirects the user back to your redirect_uri (https://app-b.com/callback) with an authorization code in the URL query string.
Your backend code at this callback endpoint must now exchange this authorization code for tokens (ID, Access, and Refresh) by making a POST request to the /oauth/token endpoint.
After this flow is complete, the user is logged into App-B, and more importantly, the Auth0 SSO cookie is set. Now, when the user navigates to App-A, the redirect to Auth0 will be seamless.
If you have any other questions, feel free to reach out!