-
Notifications
You must be signed in to change notification settings - Fork 551
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4c8941
commit 0a5b335
Showing
9 changed files
with
186 additions
and
129 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
The following example demonstrates how to create a custom SSO flow with [SAML](docs/authentication/enterprise-connections/overview#saml). | ||
Expo supports SAML Enterprise SSO, but does not support EASIE or OIDC. | ||
|
||
The following example demonstrates how to create a custom SSO flow with [SAML](docs/authentication/enterprise-connections/overview#saml). In the following example, when the user selects the "Sign in with SAML" button, they will be redirected to the provider's authentication page. Once they authenticate, they will be redirected back to your app. If there are missing requirements, like they need to complete MFA, then the `createdSessionId` will remain `null`, and you'll need to add logic to handle the missing requirements. If there are no missing requirements, then the user will be signed in. | ||
|
||
```tsx {{ filename: 'app/(auth)/sign-in.tsx', collapsible: true }} | ||
import React, { useCallback, useEffect } from 'react' | ||
import React, { useCallback, useEffect, useState } from 'react' | ||
import * as WebBrowser from 'expo-web-browser' | ||
import * as Linking from 'expo-linking' | ||
import { useSSO } from '@clerk/clerk-expo' | ||
import { View, Button } from 'react-native' | ||
import { View, Button, TextInput } from 'react-native' | ||
|
||
export const useWarmUpBrowser = () => { | ||
useEffect(() => { | ||
|
@@ -25,22 +26,25 @@ WebBrowser.maybeCompleteAuthSession() | |
export default function Page() { | ||
useWarmUpBrowser() | ||
|
||
const [email, setEmail] = useState('') | ||
|
||
const { startSSOFlow } = useSSO() | ||
|
||
const onPress = useCallback(async () => { | ||
try { | ||
const { createdSessionId, setActive, signIn, signUp } = await startSSOFlow({ | ||
strategy: 'enterprise_sso', | ||
// This identifier would likely be derived from a text input | ||
identifier: '[email protected]', | ||
identifier: email, | ||
}) | ||
|
||
// If sign in was successful, set the active session | ||
if (createdSessionId) { | ||
setActive!({ session: createdSessionId }) | ||
} else { | ||
// Use `signIn` or `signUp` returned from `startSSOFlow` | ||
// for next steps, such as MFA | ||
// If there is no `createdSessionId`, | ||
// there are missing requirements, such as MFA | ||
// Use the `signIn` or `signUp` returned from `startSSOFlow` | ||
// to handle next steps | ||
} | ||
} catch (err) { | ||
// See https://clerk.com/docs/custom-flows/error-handling | ||
|
@@ -51,7 +55,13 @@ export default function Page() { | |
|
||
return ( | ||
<View> | ||
<Button title="Sign in with SSO" onPress={onPress} /> | ||
<TextInput | ||
value={email} | ||
onChangeText={setEmail} | ||
placeholder="Enter email" | ||
placeholderTextColor="#666666" | ||
/> | ||
<Button title="Sign in with SAML" onPress={onPress} /> | ||
</View> | ||
) | ||
} | ||
|
This file contains 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 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 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 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.