-
Notifications
You must be signed in to change notification settings - Fork 233
feat: add support for Native to Web SSO #1386
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
base: master
Are you sure you want to change the base?
Changes from all commits
9962e19
c09b00a
8f9069a
40aec34
0e8c06d
6849ee8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
| import type { Credentials } from '../../types'; | ||||||||||||||||||||||||||||||||||||||||||||||
| import type { Credentials, SessionTransferCredentials } from '../../types'; | ||||||||||||||||||||||||||||||||||||||||||||||
| import { ApiCredentials } from '../models'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -50,6 +50,47 @@ export interface ICredentialsManager { | |||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||
| clearCredentials(): Promise<void>; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||
| * Obtains session transfer credentials for performing Native to Web SSO. | ||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||
| * @remarks | ||||||||||||||||||||||||||||||||||||||||||||||
| * This method exchanges the stored refresh token for a session transfer token | ||||||||||||||||||||||||||||||||||||||||||||||
| * that can be used to authenticate in web contexts without requiring the user | ||||||||||||||||||||||||||||||||||||||||||||||
| * to log in again. The session transfer token can be passed as a cookie or | ||||||||||||||||||||||||||||||||||||||||||||||
| * query parameter to the `/authorize` endpoint to establish a web session. | ||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||
subhankarmaiti marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||
| * Session transfer tokens are short-lived and expire after a few minutes. | ||||||||||||||||||||||||||||||||||||||||||||||
| * Once expired, they can no longer be used for web SSO. | ||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||
| * If Refresh Token Rotation is enabled, this method will also update the stored | ||||||||||||||||||||||||||||||||||||||||||||||
| * credentials with new tokens (ID token and refresh token) returned from the | ||||||||||||||||||||||||||||||||||||||||||||||
| * token exchange. | ||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||
| * @param parameters Optional additional parameters to pass to the token exchange. | ||||||||||||||||||||||||||||||||||||||||||||||
| * @param headers Optional additional headers to include in the token exchange request. | ||||||||||||||||||||||||||||||||||||||||||||||
| * @returns A promise that resolves with the session transfer credentials. | ||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||
| * @example | ||||||||||||||||||||||||||||||||||||||||||||||
| * ```typescript | ||||||||||||||||||||||||||||||||||||||||||||||
| * // Get session transfer credentials | ||||||||||||||||||||||||||||||||||||||||||||||
| * const ssoCredentials = await auth0.credentialsManager.getSSOCredentials(); | ||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||
| * // Option 1: Use as a cookie | ||||||||||||||||||||||||||||||||||||||||||||||
| * const cookie = `auth0_session_transfer_token=${ssoCredentials.sessionTransferToken}; path=/; domain=.yourdomain.com; secure; httponly`; | ||||||||||||||||||||||||||||||||||||||||||||||
| * document.cookie = cookie; | ||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||
| * // Option 2: Use as a query parameter | ||||||||||||||||||||||||||||||||||||||||||||||
| * const authorizeUrl = `https://${domain}/authorize?session_transfer_token=${ssoCredentials.sessionTransferToken}&...`; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+75
to
+83
|
||||||||||||||||||||||||||||||||||||||||||||||
| * // Get session transfer credentials | |
| * const ssoCredentials = await auth0.credentialsManager.getSSOCredentials(); | |
| * | |
| * // Option 1: Use as a cookie | |
| * const cookie = `auth0_session_transfer_token=${ssoCredentials.sessionTransferToken}; path=/; domain=.yourdomain.com; secure; httponly`; | |
| * document.cookie = cookie; | |
| * | |
| * // Option 2: Use as a query parameter | |
| * const authorizeUrl = `https://${domain}/authorize?session_transfer_token=${ssoCredentials.sessionTransferToken}&...`; | |
| * // Native context: Obtain the session transfer token | |
| * const ssoCredentials = await auth0.credentialsManager.getSSOCredentials(); | |
| * | |
| * // Pass the sessionTransferToken to your WebView or browser context. | |
| * // For example, inject it as a query parameter or via postMessage: | |
| * const authorizeUrl = `https://${domain}/authorize?session_transfer_token=${ssoCredentials.sessionTransferToken}&...`; | |
| * // Open the URL in a WebView or browser, or inject the token as needed. | |
| * | |
| * // --- In the web context (e.g., inside the WebView) --- | |
| * // Option 1: Set as a cookie (injected JS in WebView) | |
| * document.cookie = `auth0_session_transfer_token=${sessionTransferToken}; path=/; domain=.yourdomain.com; secure; httponly`; | |
| * | |
| * // Option 2: Use as a query parameter (already included in authorizeUrl) |
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation URL https://auth0.com/docs/authenticate/login/configure-silent-authentication references silent authentication, which is a different feature from Native to Web SSO using session transfer tokens. Consider linking to more specific documentation about session transfer tokens or Native to Web SSO if available, as silent authentication typically refers to refreshing tokens without user interaction in the same context, not transferring sessions between native and web contexts.
| * @see https://auth0.com/docs/authenticate/login/configure-silent-authentication | |
| * @see https://auth0.com/docs/authenticate/login/session-transfer-tokens |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -20,6 +20,7 @@ import type { | |||||
| ResetPasswordParameters, | ||||||
| MfaChallengeResponse, | ||||||
| DPoPHeadersParams, | ||||||
| SessionTransferCredentials, | ||||||
| } from '../types'; | ||||||
| import type { ApiCredentials } from '../core/models'; | ||||||
| import type { | ||||||
|
|
@@ -276,6 +277,51 @@ export interface Auth0ContextInterface extends AuthState { | |||||
| getDPoPHeaders: ( | ||||||
| params: DPoPHeadersParams | ||||||
| ) => Promise<Record<string, string>>; | ||||||
|
|
||||||
| /** | ||||||
| * Obtains session transfer credentials for performing Native to Web SSO. | ||||||
| * | ||||||
| * @remarks | ||||||
| * This method exchanges the stored refresh token for a session transfer token | ||||||
| * that can be used to authenticate in web contexts without requiring the user | ||||||
| * to log in again. The session transfer token can be passed as a cookie or | ||||||
| * query parameter to the `/authorize` endpoint to establish a web session. | ||||||
| * | ||||||
| * Session transfer tokens are short-lived and expire after a few minutes. | ||||||
| * Once expired, they can no longer be used for web SSO. | ||||||
| * | ||||||
| * If Refresh Token Rotation is enabled, this method will also update the stored | ||||||
| * credentials with new tokens (ID token and refresh token) returned from the | ||||||
| * token exchange. | ||||||
| * | ||||||
| * **Platform specific:** This method is only available on native platforms (iOS/Android). | ||||||
| * On web, it will throw an error. | ||||||
| * | ||||||
| * @param parameters Optional additional parameters to pass to the token exchange. | ||||||
| * @param headers Optional additional headers to include in the token exchange request. | ||||||
| * @returns A promise that resolves with the session transfer credentials. | ||||||
| * | ||||||
| * @example | ||||||
| * ```typescript | ||||||
| * // Get session transfer credentials | ||||||
| * const ssoCredentials = await getSSOCredentials(); | ||||||
| * | ||||||
| * // Option 1: Use as a cookie (recommended) | ||||||
| * const cookie = `auth0_session_transfer_token=${ssoCredentials.sessionTransferToken}; path=/; domain=.yourdomain.com; secure; httponly`; | ||||||
| * document.cookie = cookie; | ||||||
| * window.location.href = `https://yourdomain.com/authorize?client_id=${clientId}&...`; | ||||||
| * | ||||||
| * // Option 2: Use as a query parameter | ||||||
| * const authorizeUrl = `https://yourdomain.com/authorize?session_transfer_token=${ssoCredentials.sessionTransferToken}&client_id=${clientId}&...`; | ||||||
| * window.location.href = authorizeUrl; | ||||||
| * ``` | ||||||
|
Comment on lines
+304
to
+317
|
||||||
| * | ||||||
| * @see https://auth0.com/docs/authenticate/login/configure-silent-authentication | ||||||
|
||||||
| * @see https://auth0.com/docs/authenticate/login/configure-silent-authentication | |
| * @see https://auth0.com/docs/authenticate/login/session-transfer-tokens |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
headersparameter is accepted but not used in the Android implementation. It's converted fromReadableMapbut never passed tosecureCredentialsManager.getSsoCredentials(). If headers are not supported by the Android SDK, this should be documented, or if they should be supported, they need to be passed through to the native SDK call.