Skip to main content
Despia V3 can present the native Apple sign-in sheet on iOS when the app is signed with the Sign in with Apple capability. Android uses the browser through Despia’s OAuth bridge. Web apps can use the Apple JS SDK.
The Android examples use despia-native. Load the Apple JS SDK before your app script when you use the Apple JS examples.

Installation

Add the Apple JS SDK to your HTML before your app script:

Platform overview


How it works

Despia’s iOS runtime presents the Apple sign-in sheet through AuthenticationServices. The Apple JS compatibility bridge can handle popup requests on supported builds and origins. Your backend verifies the Apple response and creates your app session. The Android legacy flow uses Chrome Custom Tabs and an oauth/ deeplink to resume the WebView.

iOS

Android


Platform detection

Use the canonical user agent check. All three constants are derived from the same toLowerCase() call. Gate every native call behind the relevant constant so the flow degrades cleanly in a browser and on the wrong platform.

iOS Apple sign-in

The Apple JS examples below use popup mode. When the Despia compatibility bridge handles the request, Apple returns the native credential through the JavaScript callback. Despia preserves the Apple JS redirect flow on HTTPS when you use redirect mode. Enable Sign in with Apple on the app’s Apple App ID and rebuild with a provisioning profile that includes the capability. Verify the token on your backend. Use the bundle ID as the expected audience for a native token and the Services ID registered for the web flow when validating a web token. Your backend must also validate Apple’s signature, issuer, expiration and the nonce for the request. The native bridge returns an Apple credential. Your app’s authentication backend must use it to establish the signed-in session.

Android, oauth:// bridge

Your frontend asks your backend for an Apple OAuth URL, then opens it via despia('oauth://?url=...').
Find your deeplink scheme at Despia > Publish > Deeplink. Replace myapp throughout with your actual scheme.

Frontend trigger

Backend OAuth URL endpoint

Generates the Apple OAuth URL with native-callback.html as the redirect. Pass the deeplink scheme through as a query param so the bridge page can read it.

The native-callback.html bridge

This page runs inside Chrome Custom Tabs. Apple redirects here after auth, the page reads the tokens, then fires a deeplink to close the tab and pass tokens back to the WebView. Users never see the .html because Chrome Custom Tabs hides the URL bar. Use a plain HTML file in public/, not a React component. React Router can strip the #id_token hash fragment on route change, causing tokens to disappear before your callback logic runs. Apple supports two response modes. Pick one:
The oauth/ prefix in the deeplink is required. myapp://oauth/auth closes Chrome Custom Tabs and navigates the WebView to /auth. myapp://auth without it does nothing, the user stays stuck in the tab.

Handling tokens at /auth

After Despia closes the tab and navigates to /auth?id_token=xxx, your auth page reads the token and creates a session.
If /auth is already mounted when the deeplink arrives, your framework updates the URL without remounting. Token-reading logic that only runs on mount has already fired with empty params and will not run again. The tokens sit in the URL and nothing happens. The fix is framework-specific and covered in the tabs below.
Include searchParams in the useEffect dependency array. Without it the effect fires once on mount and ignores all subsequent URL changes.

Web, Apple JS SDK popup


Complete cross-platform handler


Apple Developer Console setup

1

Create an App ID

Go to Certificates, Identifiers & Profiles > Identifiers, create an App ID, and enable Sign In with Apple.
2

Create a Services ID

Create a Services ID (e.g. com.yourcompany.yourapp.webauth). This is your clientId.
3

Configure the Services ID

Enable Sign In with Apple, click Configure, and add your domain and return URL. The redirectURI in your code must match the origin of the page running the SDK exactly. https://yourapp.com/ not https://yourapp.com/auth. The trailing slash must match too.
4

Create a private key

Go to Keys, create a key with Sign In with Apple enabled, download the .p8 file, note your Key ID and Team ID.
5

Configure your backend

Generate a signed JWT from your .p8 key to use as client_secret. Use jsonwebtoken (Node.js) or equivalent. Valid for up to 6 months.
The client secret JWT expires after 6 months. Set a calendar reminder. Apple Sign In will silently stop working when it expires.

Debugging

Use this section when the Android OAuth flow is not working as expected. Identify which stage is broken first, then use the debug overlay to confirm what arrived at your /auth page. The flow has four stages. A failure in one looks completely different from a failure in another:
The debug overlay below tells you whether Stage 4 received anything. Work backwards from there.

Debug overlay

Add this to your /auth page during development. Remove it before submitting to the App Store or Google Play. Apple reviewers authenticate through your app during review and will see it. Show only whether credential fields arrived and a fixed error category. Do not display or log authorization URLs, callback URLs, tokens, session tokens or authorization codes. Use synthetic values when checking diagnostics, and review app, SDK and crash-report logging separately.
Swap in this standalone component as your /auth route during testing. Route it back to your real Auth component before shipping.

Reading the output

Common failure points

Chrome Custom Tabs does not open. Check that the URL passed to despia() is valid HTTPS and uses the expected provider hostname. Do not print its query string or fragment. Depending on your backend it may start with https://appleid.apple.com/auth/authorize (custom backend), or your Supabase, Firebase, or other hosted auth provider’s own OAuth endpoint. The important thing is that it is a full HTTPS URL and not empty or malformed. native-callback.html not reached. The redirect_uri in your OAuth URL must exactly match the return URL registered in the Apple Developer Console including https://, the full domain, the path, and the .html extension. Apple does exact string matching. Hash fragment empty in native-callback.html. Some hosting platforms strip hash fragments from redirects. Check only whether window.location.hash is nonempty at the top of the script. Do not print the fragment or full URL. If using a React component for the callback, switch to public/native-callback.html. React Router may be stripping the hash. Deeplink does not close Chrome Custom Tabs. The oauth/ segment must be present, myapp://oauth/auth. Without it Despia does not intercept the deeplink and the tab stays open. Find your scheme in Despia > Publish > Deeplink. Tokens arrive but sign-in never completes. Either the backend request failed silently (add error logging), or the auth logic is not running because the page was already mounted. See Handling tokens at /auth above.

Pre-submission checklist

  • Services ID created with Sign In with Apple enabled
  • Domain registered (no https://, no trailing slash)
  • Return URL registered and exactly matches redirectURI in your code including trailing slash
  • Private key (.p8) downloaded and credentials stored in your backend
  • Client secret JWT generated and not expired (max 6 months, set a calendar reminder)
  • Apple JS SDK script tag placed before your app script
  • usePopup: true set in AppleID.auth.init()
  • redirectURI matches the origin of the page running the SDK
  • id_token read from response.authorization.id_token in the JS callback
  • Signed build includes the Sign in with Apple capability when you use the native sheet
  • Backend validates the audience for the selected flow and establishes the app session
  • Backend generates OAuth URL with redirect_uri pointing to /native-callback.html
  • response_mode=fragment or form_post set correctly
  • deeplink_scheme passed through to native-callback.html
  • public/native-callback.html reads #id_token from hash (fragment) or session_token from query params (form_post)
  • Deeplink is {scheme}://oauth/{path}, oauth/ prefix present
  • Deeplink scheme matches Despia > Publish > Deeplink
  • /auth token handler re-runs on URL change, not only on initial mount
  • Debug overlay removed from /auth page
  • Sign in tested on a physical device
  • Sign in tested on both iOS and Android
  • Error state tested, cancel the Apple dialog and confirm the app handles it gracefully


FAQ

The Despia native Apple bridge returns the Apple credential to the calling page. A backend exchange creates the signed-in app session. The Android legacy example returns through its own browser callback.
It signals Despia to close Chrome Custom Tabs and navigate the WebView to the path that follows. myapp://oauth/auth closes the tab and opens /auth. Without oauth/ the deeplink is ignored and the user stays in the tab.
React Router can strip the #id_token hash fragment when it handles a route change, causing the token to disappear before your code reads it. A plain HTML file in public/ bypasses React Router entirely. The .html extension is never visible since Chrome Custom Tabs hides the URL bar.
The script tag must be placed before your app script. The SDK requires HTTPS, it will not load on http://localhost. Check for Content Security Policy errors in the browser console.
The /auth page was already open when the deeplink arrived. Your framework updated the URL without reloading, and your token handler already ran with empty params.Fix per framework:
  • React, add searchParams to your useEffect dependency array
  • Vue, use watch: { '$route.query': { immediate: true, handler } } instead of mounted()
  • Vanilla JS / HTML, call your handler on load and add window.addEventListener('popstate', handler)

Resources

NPM Package

despia-native

OAuth Reference

Generic OAuth protocol docs

Apple Docs

Sign In with Apple