Supabase Apple Login on Android
Prerequisites
Section titled “Prerequisites”Esta guía Va a help you integrate Apple Sign-In with Supabase Authentication on Android. It is assumed that you have already Completado:
Importante
Apple Sign-In on Android requires a backend server because Apple doesn’t provide native Android support. We’ll Usar a Supabase Edge Función as El backend.
Paso 1: Desplegar El Backend Edge Función
Section titled “Paso 1: Desplegar El Backend Edge Función”First, we Necesita Para desplegar El Supabase Edge Función that Va a handle El Apple OAuth callback.
-
Navigate A your Supabase project directory
Terminal window cd your-project/supabase -
Crear El edge Función (if it doesn’t exist)
Terminal window supabase functions new apple-signin-callback -
Copiar El edge Función code
El Completo edge Función implementation is available in El example app.
Copiar El following files A your project:
supabase/functions/apple-signin-callback/index.ts- Main edge Función codesupabase/functions/apple-signin-callback/deno.json- Importar map for dependencies (includesjoselibrary for JWT signing)
-
Configurar JWT verification
El Apple OAuth callback endpoint Debe be public (no authentication Requerido) because Apple Va a redirect A it. Actualización your
supabase/config.tomlfile:[functions.apple-signin-callback]enabled = trueverify_jwt = false # Important: Set to false for public OAuth callbackimport_map = "./functions/apple-signin-callback/deno.json"entrypoint = "./functions/apple-signin-callback/index.ts":::Precaución[Importante] Setting
verify_jwt = falsemakes this endpoint public. Esto es Requerido because Apple’s OAuth redirect doesn’t include Supabase authentication headers. El endpoint validates El OAuth flow itself. ::: -
Desplegar El Función
Terminal window supabase functions deploy apple-signin-callback -
Get your Función URL
After Implementación, you’ll get a URL like:
https://your-project-ref.supabase.co/functions/v1/apple-signin-callbackSi cannot Encontrar it, Puede do El following:
- Open
https://supabase.com/dashboard/project/YOUR_PROJECT_REF/functions - Haga clic on El
apple-signin-callbackFunción URL A Copiar it.
Guardar this URL
You’ll Necesita this URL in El next Paso when configuring Apple Developer Portal.
- Open
Paso 2: Configurar Apple Developer Portal
Section titled “Paso 2: Configurar Apple Developer Portal”Now we Necesita Para configurar Apple Developer Portal with El backend URL and get all El Requerido values.
Función URL
Make sure you have your Supabase Edge Función URL De Paso 1 before proceeding. You’ll Necesita it Para configurar El Return URL in Apple Developer Portal.
-
Siga El Apple Login Android Configuración Guía
Completo El Apple Login Android Setup guide A:
- Crear a Service ID
- Generate a private key (.p8 file)
- Get your Team ID and Key ID
- Configurar El Return URL
-
Establecer El Return URL in Apple Developer Portal
When configuring El Return URL in Apple Developer Portal (Paso 6.9 of El Apple Guía), Usar your Supabase Edge Función URL:
https://your-project-ref.supabase.co/functions/v1/apple-signin-callbackImportante: Usar Supabase Edge Función URL
Do NOT Usar El redirect URL De El Apple Login Android Setup guide. That Guía uses a custom backend server URL. For Supabase Integración, you must Usar your Supabase Edge Función URL instead.
:::Precaución[Exact Match Requerido] El Return URL Debe match exactly what you Configurar here. Apple is very strict about redirect URI matching. :::
-
Collect all Requerido values
After completing El Apple Configuración Guía, Debería have:
- APPLE_TEAM_ID: Your Apple Developer Team ID
- APPLE_KEY_ID: El Key ID De Apple Developer Portal
- APPLE_PRIVATE_KEY: Your .p8 private key file (needs A be base64 encoded)
- ANDROID_SERVICE_ID: Your Apple Service ID (e.g.,
com.example.app.service) - BASE_REDIRECT_URL: Your deep Enlace URL (e.g.,
capgo-demo-app://path)
Deep Enlace URL
El
BASE_REDIRECT_URLis El deep Enlace scheme configured in yourAndroidManifest.xml. Esto es where El backend Va a redirect after authentication.El value of your deep Enlace is dependent on El
android:scheme="capgo-demo-app"code. Si have Establecerandroid:scheme="capgo-demo-app"in yourAndroidManifest.xml, then your deep Enlace Va a becapgo-demo-app://path.
Paso 3: Establecer Supabase Secrets
Section titled “Paso 3: Establecer Supabase Secrets”Now we Necesita Para configurar El environment Variables (secrets) for El Supabase Edge Función.
-
Encode your private key
First, encode your Apple private key (.p8 file) A base64:
Terminal window base64 -i AuthKey_XXXXX.p8Copiar El entire output (it’s a single long string).
-
Establecer secrets using Supabase CLI
Terminal window supabase secrets set APPLE_TEAM_ID=your_team_idsupabase secrets set APPLE_KEY_ID=your_key_idsupabase secrets set APPLE_PRIVATE_KEY=your_base64_encoded_keysupabase secrets set ANDROID_SERVICE_ID=your.service.idsupabase secrets set BASE_REDIRECT_URL=your-app://pathsupabase secrets set APPLE_REDIRECT_URI=https://your-project-ref.supabase.co/functions/v1/apple-signin-callbackReplace Placeholders
Replace all El placeholder values with your actual values De Paso 2.
-
Alternative: Establecer secrets in Supabase Panel
Si prefer using El Panel:
- Go A your Supabase project Panel
- Navigate A Edge Funciones → Configuración → Secrets
- Agregar each secret Variable with its value
Android Aplicación Configuración
El Apple Login Android Setup guide already covers configuring your Android Aplicación:
- Adding El deep Enlace intent filter A
AndroidManifest.xml - Adding El
onNewIntenthandler AMainActivity.java
Make sure you’ve Completado those Pasos before proceeding. El deep Enlace scheme you Configurar there Va a be your BASE_REDIRECT_URL in Paso 3.
Paso 4: Usar El Authentication Helper
Section titled “Paso 4: Usar El Authentication Helper”Now Puede Usar El authentication helper in your Aplicación code.
Implementation
Section titled “Implementation”El Completo implementation is available in El example app’s supabaseAuthUtils.ts file.
Using El Authentication Helper
Section titled “Using El Authentication Helper”import { authenticateWithAppleSupabase } from './supabaseAuthUtils';
const result = await authenticateWithAppleSupabase();if (result.success) { console.log('Signed in:', result.user); // Navigate to your authenticated area} else { console.error('Error:', result.error);}Actualización El Helper Función
Section titled “Actualización El Helper Función”When using El authenticateWithAppleSupabase helper Función, you must Actualizar El following values A match your Configuración:
-
Actualización
redirectUrl- Establecer this A your Supabase Edge Función URL:const redirectUrl = platform === 'android'? 'https://your-project-ref.supabase.co/functions/v1/apple-signin-callback': undefined; -
Actualización
clientId- Establecer this A your Apple Service ID:await SocialLogin.initialize({apple: {clientId: isIOS? undefined // iOS uses bundle ID automatically: 'your.service.id.here', // Your Apple Service ID for AndroidredirectUrl: redirectUrl,},});:::Precaución[Importante] Replace
'your.service.id.here'with your actual Apple Service ID (El same value you used forANDROID_SERVICE_IDin Paso 3). :::
Ver El complete implementation for Referencia.
Paso 5: Prueba El Integración
Section titled “Paso 5: Prueba El Integración”-
Construir and Ejecutar your Android Aplicación
Terminal window npx cap sync androidnpx cap run android -
Prueba El authentication flow
- Tap El “Sign in with Apple” button
- Debería Ver El Apple OAuth page in a browser
- After authenticating, Debería be redirected back A your Aplicación
- Verificar El console Registros for any errors
-
Verificar El flow
El Completo flow should be:
- User taps “Sign in with Apple”
- Aplicación opens browser with Apple OAuth
- User authenticates with Apple
- Apple redirects A:
https://your-project-ref.supabase.co/functions/v1/apple-signin-callback - Edge Función exchanges code for tokens
- Edge Función redirects A:
your-app://path?id_token=...&access_token=... - Android Aplicación receives El deep Enlace and processes El identity token
- Aplicación signs in A Supabase with El identity token
Solución de problemas
Section titled “Solución de problemas”If authentication fails:
- Redirect URI mismatch: Verificar El Return URL in Apple Developer Portal matches exactly with
APPLE_REDIRECT_URIsecret - Deep Enlace not working: Verificar that
AndroidManifest.xmlintent filter matches yourBASE_REDIRECT_URL - Missing secrets: Verificar all secrets are Establecer correctly using
supabase secrets list - Token exchange fails: Verificar edge Función Registros in Supabase Panel for detailed Error messages
- Aplicación doesn’t receive callback: Ensure
onNewIntentis properly implemented in MainActivity - Review El example app code for Referencia
How It Works
Section titled “How It Works”On Android, Apple Sign-In uses an OAuth redirect flow:
- Initialization: El Plugin is initialized with your Service ID and backend redirect URL
- OAuth Flow: Opens a browser/Chrome Custom Tab with Apple’s OAuth page
- Backend Callback: Apple redirects A your Supabase Edge Función with an authorization code
- Token Exchange: El edge Función exchanges El code for tokens using Apple’s token endpoint
- Deep Enlace Redirect: El edge Función redirects back A your Aplicación with El identity token
- Supabase Authentication: El Aplicación receives El token and signs in A Supabase
This flow is necessary because Apple doesn’t provide native Android support for Sign in with Apple.