Setting up Google and Apple sign-in
The app sends the ID token from the Google or Apple SDK to POST /api/v1/auth/social. The API checks the token's signature, issuer, audience and expiry (and the nonce for Apple), then signs the user in. You only need to put the right IDs and keys in Admin → Settings → Integrations.
- Open Google Cloud Console → APIs & Services → Credentials. Create a project if you don't have one.
- Set up the OAuth consent screen: app name, support email, logo, and links to your privacy policy and terms.
- Create OAuth client IDs:
- Android: package name (e.g.
com.yourcompany.app) and the SHA-1 of your signing key. You need one for the debug key and one for the release (Play App Signing) key. - iOS: your bundle ID.
- Web application: the Android app uses this ID as
serverClientIdto get an ID token.
- Android: package name (e.g.
- In Admin → Settings → Integrations → Google client IDs, add all three client IDs. A token is accepted when its audience matches any of them.
- Build the app with these client IDs, and add the reversed iOS client ID to
Info.plist: see Setting up the Flutter app below.
Apple
Apple requires Sign in with Apple in any iOS app that also offers Google sign-in.
- In Apple Developer → Certificates, Identifiers & Profiles → Identifiers, open your app ID and enable Sign in with Apple.
- Keys → create a key with Sign in with Apple enabled, linked to your app ID. Download the
.p8file. You can download it only once. - Note your Team ID (top right of the developer portal) and the Key ID.
- In Admin → Settings → Integrations → Apple, fill in:
- Bundle ID: your iOS bundle ID (the token audience).
- Service ID: optional; only for Sign in with Apple on Android or the web.
- Team ID and Key ID.
- Private key: paste the whole
.p8contents, including theBEGIN/ENDlines. It is stored encrypted.
With the key configured, the API exchanges Apple's one-time authorization code for a refresh token and revokes it when the user deletes their account, which Apple requires. Without the key, sign-in still works, but revocation is skipped (and logged).
Things to know about Apple
- Apple sends the user's name only on the first sign-in. The app passes it as
name, and the API stores it then. - Users can choose Hide My Email. Their address looks like
abc123@privaterelay.appleid.com, and mail sent to it is forwarded to them. To email these users, register your sending domain under Sign in with Apple for Email Communication in the developer portal. - The app generates a random nonce, sends its SHA-256 to Apple, and sends the raw nonce to the API, which checks that they match.
Setting up the Flutter app
The buttons appear only when the admin settings above are filled in (GET /config → features.google_login, features.apple_login, features.apple_login_android).
- Android: no code changes. Add the SHA-1 and SHA-256 of every signing key (debug, upload, and the Play App Signing key from Play Console → App integrity) to the Android OAuth client. Get the debug ones with
cd mobile/android && ./gradlew signingReport. - Both platforms: build with the web client ID so Google issues an ID token for your API:
flutter run --flavor dev -t lib/main_dev.dart \ --dart-define=GOOGLE_SERVER_CLIENT_ID=1234-abc.apps.googleusercontent.com \ --dart-define=GOOGLE_IOS_CLIENT_ID=1234-ios.apps.googleusercontent.com - iOS: in
ios/Runner/Info.plist, add the reversed iOS client ID (com.googleusercontent.apps.1234-ios) underCFBundleURLTypes→CFBundleURLSchemes.
Apple
- iOS: in Xcode, open
Runner→ Signing & Capabilities → + Capability → Sign in with Apple. Nothing else is needed. - Android (optional; Apple's web flow):
- In Apple Developer, create a Services ID (e.g.
com.yourcompany.app.signin), enable Sign in with Apple, and add your API domain with the return URLhttps://your-api-domain/auth/apple/android. - Put the Services ID in Admin → Settings → Integrations → Apple → Services ID, and your Android package name in Admin → Settings → Deep links.
- The API's
/auth/apple/androidpage hands the result back to the app (signinwithapple://callback). The receiving activity is already inAndroidManifest.xml.
- In Apple Developer, create a Services ID (e.g.
Testing
Social sign-in can't be fully tested on an emulator without a Google account and the SHA-1 of the debug key registered. Use a real phone and a dev build pointed at your API with --dart-define=API_BASE_URL=http://<your computer's LAN IP>:8000/api/v1.
How accounts are matched
- The same Google/Apple identity as before → that account.
- A new identity whose email matches an account that verified the same email → linked to that account.
- The email belongs to an account that never verified it → refused with
AUTH_EMAIL_TAKEN. The user should log in with their password, or verify that account first. - Otherwise → a new account, with the email marked as verified.
When an account is deleted, its Google/Apple links are removed. Signing in again creates a fresh account.
Error codes
| Code | Meaning |
|---|---|
AUTH_SOCIAL_INVALID_TOKEN (422) |
Bad signature, expired, wrong audience or issuer, or nonce mismatch |
AUTH_SOCIAL_NOT_CONFIGURED (503) |
No client IDs / bundle ID set in admin |
AUTH_EMAIL_TAKEN (409) |
Email belongs to an unverified account (see above) |