Backend verification
The credential is only proof of identity once your backend has verified it. Send the backend the identityToken, the raw nonce you generated, the authorizationCode, and on the first sign-in the email and fullName.
const rawNonce = createNonce() // your code: random, single-use
const credential = await AppleSignIn.signIn({ scopes: ['email'], nonce: rawNonce })
if (credential !== undefined) {
await api.post('/auth/apple', {
identityToken: credential.identityToken,
authorizationCode: credential.authorizationCode,
nonce: rawNonce,
email: credential.email,
fullName: credential.fullName,
})
}
The nonce
Pass the raw nonce to signIn. The module hashes it with SHA-256 (lowercase hex of the UTF-8 bytes) and sends the hash to Apple, and Apple writes that hash into the ID token's nonce claim. The raw value never leaves your app and backend.
| Where | Value |
|---|---|
signIn({ nonce }) | raw nonce |
| Sent to Apple | sha256Hex(rawNonce) |
ID token nonce claim | sha256Hex(rawNonce) |
| Firebase, Supabase | raw nonce, next to the token |
A custom backend hashes the raw nonce it received and compares it to the token's nonce claim.
:::info Generate nonces securely
The nonce must be unpredictable and used once. The example app builds one with Math.random() only for demonstration; production apps should use a cryptographically secure source, ideally a nonce issued by your backend.
:::
The identity token
identityToken is an OpenID Connect ID token (JWT). Verify its signature against Apple's public keys on your backend, then read the user ID from its sub claim; it equals credential.user. Apple documents the checks in Verifying a user.
The authorization code
authorizationCode is short-lived and single use. Your backend exchanges it at Apple's token endpoint for refresh tokens. Do not store it in the app.