Sign in with Apple
Sign users in with Apple through Abrova Auth. The app runs Apple's native sign-in with a hashed nonce; Abrova verifies Apple's ID token for your bundle IDs and Services IDs. Includes the account deletion key that revokes the Apple sign-in.
Your app runs Apple's own sign-in and receives an ID token from Apple. The SDK sends that token to Abrova Auth, which checks that Apple signed it for one of your app identifiers and signs the user in. On iOS the SDK can run the whole Apple sheet for you.
An iOS app that offers Sign in with Google (or another third-party login) must also offer Sign in with Apple, and an app that lets users create an account must let them delete it in the app. Abrova Auth supports both.
Sign in with Apple needs a connection to Apple, which can be unreliable from Iran. Offer anonymous, e-mail and password, magic link or Telegram code as well: they do not depend on Apple or Google.
Set it up in the Console#
Open Abrova Auth › Sign-in methods, turn on Apple, and enter your identifiers:
| Field | What to enter |
|---|---|
| Bundle IDs (iOS apps) | The bundle id of each iOS or macOS app that uses the native Apple sheet, for example com.example.app. |
| Services IDs (web and Android) | The Services ID you created in the Apple Developer portal for Sign in with Apple on the web or on Android. |
Abrova Auth accepts an Apple ID token only when it was issued to one of these identifiers. A token Apple issued for any other app is refused.
Account deletion key (recommended)
Apple asks apps to revoke a user's Sign in with Apple when the user deletes their account. To let Abrova Auth do that, create a Sign in with Apple key in the Apple Developer portal (Certificates, Identifiers & Profiles › Keys) and enter, in the same Apple section:
| Field | Where to find it |
|---|---|
| Team ID | 10 characters, Apple Developer › Membership. |
| Key ID | 10 characters, shown with the key. |
| Private key (.p8) | The whole file. It is stored encrypted and never shown again. |
Then pass Apple's authorizationCode when the user signs in (the SDKs show where). Abrova Auth redeems the code when the user first signs up with Apple (or links Apple), so add the key before you launch: users who signed up before the key was saved cannot have their Apple sign-in revoked. Without the key or the code, account deletion still deletes the user; only the Apple-side revocation is skipped.
The nonce#
A nonce ties Apple's ID token to this one sign-in, so a captured token cannot be used again:
- Create a random raw nonce with the SDK's helper (16 to 256 characters).
- Give Apple the lowercase hex SHA-256 of it.
- Give Abrova Auth the raw value.
Abrova Auth checks that they match and accepts each nonce once. Apple's ID token must also be less than 10 minutes old.
| SDK | Raw nonce | Value for Apple |
|---|---|---|
| Flutter | AbrovaAuthNonce.generate() | AbrovaAuthNonce.sha256Hex(raw) |
| iOS | AbrovaNonce.generate() | AbrovaNonce.sha256(raw) |
| Android | AbrovaNonce.generate() | AbrovaNonce.sha256(raw) |
| Web, React Native | (await auth.createNonce()).rawNonce | (await auth.createNonce()).hashedNonce |
Sign in#
iOS: the SDK runs Apple's sheet
Add the Sign in with Apple capability to your app target, then:
try await AbrovaAuth.shared.signInWithAppleNative()
The SDK creates the nonce, shows Apple's sheet, and passes the ID token, the authorization code and the name Apple shares on the first sign-in. It throws .canceled when the user closes the sheet.
Flutter
With the sign_in_with_apple package:
final raw = AbrovaAuthNonce.generate();
final apple = await SignInWithApple.getAppleIDCredential(
scopes: [AppleIDAuthorizationScopes.email, AppleIDAuthorizationScopes.fullName],
nonce: AbrovaAuthNonce.sha256Hex(raw),
);
await AbrovaAuth.instance.signInWithApple(
idToken: apple.identityToken!,
rawNonce: raw,
authorizationCode: apple.authorizationCode, // lets account deletion revoke Apple
name: [apple.givenName, apple.familyName].whereType<String>().join(' '),
);Android
Run Apple's web sign-in with your Services ID and AbrovaNonce.sha256(rawNonce) as the nonce, then pass the id_token and code Apple returns:
AbrovaAuth.shared.signInWithApple(idToken, rawNonce, authorizationCode = code)
Web and React Native
Use Sign in with Apple JS (web) or your React Native Apple sign-in library with hashedNonce as the nonce:
const { rawNonce, hashedNonce } = await auth.createNonce();
// ... run Apple's sign-in with nonce: hashedNonce, then:
await auth.signInWithApple({ idToken, rawNonce, authorizationCode, name });Name and e-mail#
Apple shares the user's name only on the first sign-in, and the e-mail may be a private relay address. Abrova Auth stores them (encrypted) only when Store profile data is on under Abrova Auth › Settings. If your app needs the name, save it in your own data on the first sign-in.
Link Apple to a signed-in user#
To upgrade an anonymous user, use the link call with the same arguments: linkApple(...), or on iOS signInWithAppleNative(link: true). The user keeps their id. If this Apple ID already belongs to another user, the call fails with PROVIDER_ALREADY_LINKED.
Errors#
| Code | Meaning |
|---|---|
| NOT_CONFIGURED | Apple is on, but no bundle ID or Services ID is entered. |
| INVALID_ID_TOKEN | Apple did not sign it, it was issued to another app id, it is older than 10 minutes, or its nonce is not the SHA-256 of the raw nonce you sent. |
| INVALID_INPUT | The raw nonce is missing or not 16 to 256 characters. |
| NONCE_REUSED | This nonce was already used. Create a new one for every sign-in. |
| PROVIDER_ALREADY_LINKED | Linking only: the Apple ID belongs to another user. |
| METHOD_DISABLED | Apple sign-in is off for the project. |