-
Notifications
You must be signed in to change notification settings - Fork 403
feat(clerk-expo): Introduce SAML support #4880
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 all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
07c2983
Refactor `useOAuth` to `useSso`
LauraBeatris 94791c8
Add changeset
LauraBeatris f339177
Pass identifier when creating sign in
LauraBeatris 2ca1647
Deprecate `useOAuth` in favor of `useSSO`
LauraBeatris 4ff145c
Refactor implementation
LauraBeatris fbbfe8b
Close web browser popup on SSO callback
LauraBeatris e104927
fix: Create first factor for enterprise_sso strategy
LauraBeatris 05c9b82
debug
NicolasLopes7 6088af1
fix: Handle transfer flow
LauraBeatris 55de7d9
chore: Experiment with not providing a redirect URL
LauraBeatris 8ba1692
chore: Experiment with manually opening deep link
LauraBeatris 41e76d6
chore: Refactor `redirectUrl` approach to be used for URL parsing only
LauraBeatris 9a43d07
Fix transfer flow
LauraBeatris d79d297
Update comment regarding redirect URL
LauraBeatris 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| '@clerk/clerk-expo': minor | ||
| --- | ||
|
|
||
| Introduce support for SSO with SAML | ||
|
|
||
| - Introduce `useSSO` hook to support a wider range of SSO flow types | ||
| - Deprecate `useOAuth` in favor of new `useSSO` hook |
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,98 @@ | ||
| import { useSignIn, useSignUp } from '@clerk/clerk-react'; | ||
| import type { EnterpriseSSOStrategy, OAuthStrategy, SetActive, SignInResource, SignUpResource } from '@clerk/types'; | ||
| import * as AuthSession from 'expo-auth-session'; | ||
| import * as WebBrowser from 'expo-web-browser'; | ||
|
|
||
| import { errorThrower } from '../utils/errors'; | ||
|
|
||
| export type StartSSOFlowParams = { | ||
| unsafeMetadata?: SignUpUnsafeMetadata; | ||
| } & ( | ||
| | { | ||
| strategy: OAuthStrategy; | ||
| } | ||
| | { | ||
| strategy: EnterpriseSSOStrategy; | ||
| identifier: string; | ||
| } | ||
| ); | ||
|
|
||
| export type StartSSOFlowReturnType = { | ||
| createdSessionId: string | null; | ||
| authSessionResult?: WebBrowser.WebBrowserAuthSessionResult; | ||
| setActive?: SetActive; | ||
| signIn?: SignInResource; | ||
| signUp?: SignUpResource; | ||
| }; | ||
|
|
||
| export function useSSO() { | ||
| const { signIn, setActive, isLoaded: isSignInLoaded } = useSignIn(); | ||
| const { signUp, isLoaded: isSignUpLoaded } = useSignUp(); | ||
|
|
||
| async function startSSOFlow(startSSOFlowParams: StartSSOFlowParams): Promise<StartSSOFlowReturnType> { | ||
| if (!isSignInLoaded || !isSignUpLoaded) { | ||
| return { | ||
| createdSessionId: null, | ||
| signIn, | ||
| signUp, | ||
| setActive, | ||
| }; | ||
| } | ||
|
|
||
| const { strategy, unsafeMetadata } = startSSOFlowParams ?? {}; | ||
|
|
||
| /** | ||
| * Creates a redirect URL based on the application platform | ||
| * It must be whitelisted, either via Clerk Dashboard, or BAPI, in order | ||
| * to include the `rotating_token_nonce` on SSO callback | ||
| * @ref https://clerk.com/docs/reference/backend-api/tag/Redirect-URLs#operation/CreateRedirectURL | ||
| */ | ||
| const redirectUrl = AuthSession.makeRedirectUri({ | ||
| path: 'sso-callback', | ||
| }); | ||
|
|
||
| await signIn.create({ | ||
| strategy, | ||
| redirectUrl, | ||
| ...(startSSOFlowParams.strategy === 'enterprise_sso' ? { identifier: startSSOFlowParams.identifier } : {}), | ||
| }); | ||
|
|
||
| const { externalVerificationRedirectURL } = signIn.firstFactorVerification; | ||
| if (!externalVerificationRedirectURL) { | ||
| return errorThrower.throw('Missing external verification redirect URL for SSO flow'); | ||
| } | ||
|
|
||
| const authSessionResult = await WebBrowser.openAuthSessionAsync(externalVerificationRedirectURL.toString()); | ||
LauraBeatris marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (authSessionResult.type !== 'success' || !authSessionResult.url) { | ||
| return { | ||
| createdSessionId: null, | ||
| setActive, | ||
| signIn, | ||
| signUp, | ||
| }; | ||
| } | ||
|
|
||
| const params = new URL(authSessionResult.url).searchParams; | ||
| const rotatingTokenNonce = params.get('rotating_token_nonce') ?? ''; | ||
| await signIn.reload({ rotatingTokenNonce }); | ||
|
|
||
| const userNeedsToBeCreated = signIn.firstFactorVerification.status === 'transferable'; | ||
| if (userNeedsToBeCreated) { | ||
| await signUp.create({ | ||
| transfer: true, | ||
| unsafeMetadata, | ||
| }); | ||
| } | ||
|
|
||
| return { | ||
| createdSessionId: signUp.createdSessionId ?? signIn.createdSessionId, | ||
| setActive, | ||
| signIn, | ||
| signUp, | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| startSSOFlow, | ||
| }; | ||
| } | ||
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.