-
Notifications
You must be signed in to change notification settings - Fork 236
feat: add ssoExchange to Authentication API for Native-to-Web SSO #1494
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bbc9f13
feat: implement SSO exchange functionality and related types for nati…
subhankarmaiti 6de2872
feat: add ssoExchange method to Auth0Context and Auth0Provider for se…
subhankarmaiti e84cabe
feat: add SSO Exchange section to documentation with usage examples f…
subhankarmaiti 2d87604
fix: remove unused Alert import in SSOExchangeScreen example
subhankarmaiti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import type { | ||
| SessionTransferCredentials, | ||
| SSOCredentialsResponse, | ||
| } from '../../types'; | ||
|
|
||
| /** | ||
| * A class representation of SSO credentials returned by the session transfer token exchange. | ||
| * Maps the raw API response (snake_case) to the SDK's SessionTransferCredentials type (camelCase). | ||
| */ | ||
| export class SSOCredentials implements SessionTransferCredentials { | ||
| public sessionTransferToken: string; | ||
| public tokenType: string; | ||
| public expiresIn: number; | ||
| public idToken?: string; | ||
| public refreshToken?: string; | ||
|
|
||
| constructor(params: SessionTransferCredentials) { | ||
| this.sessionTransferToken = params.sessionTransferToken; | ||
| this.tokenType = params.tokenType; | ||
| this.expiresIn = params.expiresIn; | ||
| this.idToken = params.idToken; | ||
| this.refreshToken = params.refreshToken; | ||
| } | ||
|
|
||
| /** | ||
| * Creates an SSOCredentials instance from a raw /oauth/token response. | ||
| * The API returns `access_token` as the session transfer token and | ||
| * `issued_token_type` as the token type. | ||
| */ | ||
| static fromResponse(response: SSOCredentialsResponse): SSOCredentials { | ||
| return new SSOCredentials({ | ||
| sessionTransferToken: response.access_token, | ||
| tokenType: response.issued_token_type, | ||
| expiresIn: response.expires_in, | ||
| idToken: response.id_token, | ||
| refreshToken: response.refresh_token, | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import { SSOCredentials } from '../SSOCredentials'; | ||
| import type { SSOCredentialsResponse } from '../../../types'; | ||
|
|
||
| describe('SSOCredentials', () => { | ||
| describe('constructor', () => { | ||
| it('should correctly assign all properties from the input object', () => { | ||
| const data = { | ||
| sessionTransferToken: 'stt_token_123', | ||
| tokenType: 'urn:auth0:params:oauth:token-type:session_transfer_token', | ||
| expiresIn: 120, | ||
| idToken: 'id_token_456', | ||
| refreshToken: 'refresh_token_789', | ||
| }; | ||
|
|
||
| const creds = new SSOCredentials(data); | ||
|
|
||
| expect(creds.sessionTransferToken).toBe(data.sessionTransferToken); | ||
| expect(creds.tokenType).toBe(data.tokenType); | ||
| expect(creds.expiresIn).toBe(data.expiresIn); | ||
| expect(creds.idToken).toBe(data.idToken); | ||
| expect(creds.refreshToken).toBe(data.refreshToken); | ||
| }); | ||
|
|
||
| it('should handle missing optional properties', () => { | ||
| const data = { | ||
| sessionTransferToken: 'stt_token_123', | ||
| tokenType: 'urn:auth0:params:oauth:token-type:session_transfer_token', | ||
| expiresIn: 120, | ||
| }; | ||
|
|
||
| const creds = new SSOCredentials(data); | ||
|
|
||
| expect(creds.idToken).toBeUndefined(); | ||
| expect(creds.refreshToken).toBeUndefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('fromResponse', () => { | ||
| it('should correctly map snake_case API response to camelCase properties', () => { | ||
| const response: SSOCredentialsResponse = { | ||
| access_token: 'stt_token_123', | ||
| issued_token_type: | ||
| 'urn:auth0:params:oauth:token-type:session_transfer_token', | ||
| token_type: 'N_A', | ||
| expires_in: 120, | ||
| id_token: 'id_token_456', | ||
| refresh_token: 'refresh_token_789', | ||
| }; | ||
|
|
||
| const creds = SSOCredentials.fromResponse(response); | ||
|
|
||
| expect(creds).toBeInstanceOf(SSOCredentials); | ||
| expect(creds.sessionTransferToken).toBe(response.access_token); | ||
| expect(creds.tokenType).toBe(response.issued_token_type); | ||
| expect(creds.expiresIn).toBe(response.expires_in); | ||
| expect(creds.idToken).toBe(response.id_token); | ||
| expect(creds.refreshToken).toBe(response.refresh_token); | ||
| }); | ||
|
|
||
| it('should handle a response with no optional fields', () => { | ||
| const response: SSOCredentialsResponse = { | ||
| access_token: 'stt_token_123', | ||
| issued_token_type: | ||
| 'urn:auth0:params:oauth:token-type:session_transfer_token', | ||
| token_type: 'N_A', | ||
| expires_in: 60, | ||
| }; | ||
|
|
||
| const creds = SSOCredentials.fromResponse(response); | ||
|
|
||
| expect(creds.idToken).toBeUndefined(); | ||
| expect(creds.refreshToken).toBeUndefined(); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.