-
-
Notifications
You must be signed in to change notification settings - Fork 374
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add docs for native sign in using Apple SDK
- Loading branch information
1 parent
4e8739c
commit 8740056
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
code-examples/sdk/typescript/src/selfservice/registration/apple-social-sign-in-native.ts
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import * as AppleAuthentication from "expo-apple-authentication" | ||
import * as Crypto from "expo-crypto" | ||
import * as Random from "expo-random" | ||
|
||
async function signInWithApple() { | ||
const nonce = Random.getRandomBytes(16).toString() | ||
|
||
const digest = await Crypto.digestStringAsync( | ||
Crypto.CryptoDigestAlgorithm.SHA256, | ||
nonce, | ||
) | ||
const credential = await AppleAuthentication.signInAsync({ | ||
requestedScopes: [ | ||
AppleAuthentication.AppleAuthenticationScope.EMAIL, | ||
AppleAuthentication.AppleAuthenticationScope.FULL_NAME, | ||
], | ||
nonce: digest, | ||
}) | ||
|
||
return orySdk.updateRegistrationFlow({ | ||
flow: flow.id, | ||
updateRegistrationFlowBody: { | ||
provider: "apple", | ||
id_token: credential.identityToken, | ||
raw_id_token_nonce: nonce, | ||
traits: { | ||
name: { | ||
first: credential.fullName?.givenName || "given name", // When developing, these values might be empty | ||
last: credential.fullName?.familyName || "last name", // When developing, these values might be empty | ||
}, | ||
}, | ||
}, | ||
}) | ||
} |
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