Puoi anche utilizzare un modello email personalizzato, se la tua app ne ha uno.
Conformità ai requisiti di Apple relativi ai dati anonimizzati
Apple offre agli utenti la possibilità di anonimizzare i propri dati, incluso il loro indirizzo email. Apple assegna agli utenti che selezionano questa opzione un indirizzo email offuscato con il dominio privaterelay.appleid.com.
La tua app deve rispettare eventuali norme o termini per gli sviluppatori di Apple relativi agli ID Apple anonimizzati. Ciò include l'ottenimento del consenso dell'utente prima di associare eventuali informazioni che consentono l'identificazione personale (PII) a un ID Apple anonimizzato. Le azioni che coinvolgono PII includono, a titolo esemplificativo:
Collegamento di un indirizzo email a un Apple ID anonimizzato o viceversa.
Collegamento di un numero di telefono a un Apple ID anonimizzato o viceversa
Collegamento di una credenziale social non anonima, come Facebook o Google, a un ID Apple anonimizzato o viceversa.
Per ulteriori informazioni, consulta il Contratto di licenza del programma per sviluppatori Apple per il tuo account sviluppatore Apple.
Configurare Apple come fornitore
Per configurare Apple come provider di identità:
Vai alla pagina Provider di identità nella Google Cloud console.
Inserisci il tuo ID servizi, l'ID team Apple, l'ID chiave e la
chiave privata.
Registra i domini della tua app facendo clic su Aggiungi dominio in Domini autorizzati. Per scopi di sviluppo, localhost è già attivato per impostazione predefinita.
Nella sezione Configura l'applicazione, fai clic su Android. Copia lo snippet nel codice dell'app per inizializzare l'SDK client di Identity Platform.
(Facoltativo) Aggiungi gli ambiti OAuth. Gli ambiti specificano i dati che stai richiedendo ad Apple. I dati più sensibili potrebbero richiedere scopi specifici. Per impostazione predefinita, quando è attiva l'opzione Un account per indirizzo email, Identity Platform richiede gli ambiti email e name.
(Facoltativo) Localizza il flusso di autenticazione. Puoi specificare una lingua o utilizzare la lingua predefinita del dispositivo:
Java
// Localize the Apple authentication screen in French.provider.addCustomParameter("locale","fr");
Kotlin
// Localize the Apple authentication screen in French.provider.addCustomParameter("locale","fr");
Consentire l'accesso all'utente con Identity Platform.
Controlla se è già presente una risposta chiamando
startActivityForSignInWithProvider():
Java
mAuth=FirebaseAuth.getInstance();Task<AuthResult>pending=mAuth.getPendingAuthResult();if(pending!=null){pending.addOnSuccessListener(newOnSuccessListener<AuthResult>(){@OverridepublicvoidonSuccess(AuthResultauthResult){Log.d(TAG,"checkPending:onSuccess:"+authResult);// Get the user profile with authResult.getUser() and// authResult.getAdditionalUserInfo(), and the ID// token from Apple with authResult.getCredential().}}).addOnFailureListener(newOnFailureListener(){@OverridepublicvoidonFailure(@NonNullExceptione){Log.w(TAG,"checkPending:onFailure",e);}});}else{Log.d(TAG,"pending: null");}
Kotlin
valpending=auth.pendingAuthResultif(pending!=null){pending.addOnSuccessListener{authResult->
Log.d(TAG,"checkPending:onSuccess:$authResult")// Get the user profile with authResult.getUser() and// authResult.getAdditionalUserInfo(), and the ID// token from Apple with authResult.getCredential().}.addOnFailureListener{e->
Log.w(TAG,"checkPending:onFailure",e)}}else{Log.d(TAG,"pending: null")}
Quando accedi, la tua attività viene messa in background, il che significa che il sistema può recuperarla durante il flusso di autenticazione. Il controllo se un risultato è già presente impedisce all'utente di dover accedere due volte.
Se non ci sono risultati in attesa, chiama
startActivityForSignInWithProvider():
A differenza di molti altri provider di identità, Apple non fornisce un URL di una foto.
Se un utente sceglie di non condividere il proprio indirizzo email reale con la tua app, Apple fornisce un indirizzo email univoco da condividere. Questa email ha il seguente formato:
xyz@privaterelay.appleid.com. Se hai configurato il servizio di inoltro email privato, Apple inoltra le email inviate all'indirizzo anonimo all'indirizzo email reale dell'utente.
Apple condivide le informazioni degli utenti, ad esempio i nomi visualizzati, con le app solo la prima volta che un utente accede. Nella maggior parte dei casi, Identity Platform memorizza questi
dati, che puoi recuperare utilizzando firebase.auth().currentUser.displayName
durante le sessioni future. Tuttavia, se hai consentito agli utenti di accedere alla tua app
utilizzando Apple prima di eseguire l'integrazione con Identity Platform, le informazioni utente
non sono disponibili.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-11 UTC."],[[["\u003cp\u003eThis guide outlines how to integrate "Sign in with Apple" functionality into your Android application using Identity Platform.\u003c/p\u003e\n"],["\u003cp\u003eYou must configure your app on the Apple Developer site, including registering a Return URL, temporarily hosting a verification file, and obtaining your Services ID, Apple team ID, key ID, and private key.\u003c/p\u003e\n"],["\u003cp\u003eTo configure Apple as an identity provider, you'll need to add Apple as a provider in the Google Cloud console and input the necessary credentials, such as your Services ID, Apple team ID, key ID, and private key.\u003c/p\u003e\n"],["\u003cp\u003eWhen implementing sign-in, you can customize the authentication flow by adding specific OAuth scopes to request user data, and also can localize the authentication screen.\u003c/p\u003e\n"],["\u003cp\u003eIf a user chooses to anonymize their data, Apple will use a unique email address in the format \u003ccode\u003exyz@privaterelay.appleid.com\u003c/code\u003e, which you must comply with by not associating PII with the anonymized Apple ID without user consent.\u003c/p\u003e\n"]]],[],null,["# Signing in users with Apple on Android\n======================================\n\nThis document shows you how to use Identity Platform to add *Sign in with Apple*\nto your Android app.\n\nBefore you begin\n----------------\n\n- Create an Android app that uses Identity Platform.\n\n- Join the [Apple Developer Program](https://developer.apple.com/programs).\n\nConfiguring your app with Apple\n-------------------------------\n\nOn the Apple Developer site:\n\n1. Follow the steps in [Configure Sign in with Apple for the web](https://developer.apple.com/help/account/configure-app-capabilities/configure-sign-in-with-apple-for-the-web).\n This includes:\n\n 1. Registering a *Return URL*, which looks like:\n\n ```\n https://project-id.firebaseapp.com/__/auth/handler\n ```\n 2. Temporarily hosting a file at the following URL to verify your domain:\n\n ```\n https://project-id.firebaseapp.com/.well-known/apple-developer-domain-association.txt\n ```\n\n Additionally, take note of your *Services ID* and *Apple team ID* --- you'll\n need them in the next section.\n2. [Use an Apple private key to create a sign in](https://developer.apple.com/help/account/configure-app-capabilities/create-a-sign-in-with-apple-private-key).\n You'll need the *key* and its *ID* in the next section.\n\n3. If you use Identity Platform to send emails to your users,\n [configure your project with Apple's private email relay service](https://developer.apple.com/help/account/configure-app-capabilities/configure-private-email-relay-service)\n using the following email:\n\n ```\n noreply@project-id.firebaseapp.com\n ```\n\n You can also use a custom email template, if your app has one.\n\nComplying with Apple's anonymized data requirements\n---------------------------------------------------\n\nApple gives users the option of anonymizing their data, including\ntheir email address. Apple assigns users who select this option an obfuscated\nemail address with the domain `privaterelay.appleid.com`.\n\nYour app must comply with any applicable developer policies or terms from Apple\nregarding anonymized Apple IDs. This includes obtaining user consent before\nassociating any personally identifying information (PII) with an anonymized\nApple ID. Actions that involve PII include, but are not limited to:\n\n- Linking an email address to an anonymized Apple ID, or vice versa.\n- Linking a phone number to an anonymized Apple ID, or vice versa\n- Linking a non-anonymous social credential, such as Facebook or Google, to to anonymized Apple ID, or vice versa.\n\nFor more information, refer to the *Apple Developer Program License Agreement*\nfor your Apple developer account.\n\nConfiguring Apple as a provider\n-------------------------------\n\nTo configure Apple as an identity provider:\n\n1. Go to the **Identity Providers** page in the Google Cloud console.\n\n [Go to the Identity Providers page](https://console.cloud.google.com/customer-identity/providers)\n2. Click **Add a Provider**.\n\n3. Select **Apple** from the list.\n\n4. Under **Platform** , select **Android**.\n\n5. Enter your **Services ID** , **Apple team ID** , **Key ID** , and\n **Private key**.\n\n6. Register your app's domains by clicking **Add domain** under\n **Authorized domains** . For development purposes, `localhost` is already\n enabled by default.\n\n | **Important:** In projects created after April 28, 2025, Identity Platform no longer includes `localhost` as an authorized domain by default. Google strongly discourages the use of `localhost` in production projects. If you choose to authorize `localhost`, you can manually add it in the **Settings** page, in **Authorized Domains** , by clicking **Add Domain**.\n7. Under **Configure your application** , click **Android**. Copy the\n snippet into your app's code to initialize the Identity Platform\n client SDK.\n\n8. Click **Save**.\n\nSigning in users with the client SDK\n------------------------------------\n\n1. Create an instance of the `OAuthProvider` provider object, using the\n ID `apple.com`:\n\n ### Java\n\n OAuthProvider.Builder provider = OAuthProvider.newBuilder(\"apple.com\");\n\n ### Kotlin\n\n val provider = OAuthProvider.newBuilder(\"apple.com\")\n\n2. **Optional:** Add OAuth scopes. Scopes specify what data you are\n requesting from Apple. More sensitive data may require specific\n scopes. By default, when **One account per email address** is enabled,\n Identity Platform requests the `email` and `name` scopes.\n\n ### Java\n\n List\u003cString\u003e scopes =\n new ArrayList\u003cString\u003e() {\n {\n add(\"email\");\n add(\"name\");\n }\n };\n provider.setScopes(scopes);\n\n ### Kotlin\n\n provider.setScopes(arrayOf(\"email\", \"name\"))\n\n3. **Optional:** Localize the authentication flow. You can specify a language,\n or use the device's default language:\n\n ### Java\n\n // Localize the Apple authentication screen in French.\n provider.addCustomParameter(\"locale\", \"fr\");\n\n ### Kotlin\n\n // Localize the Apple authentication screen in French.\n provider.addCustomParameter(\"locale\", \"fr\");\n\n4. Sign in the user with Identity Platform.\n\n | **Note:** When a user signs in, Identity Platform takes control of your UI and opens a [Custom Chrome Tab](https://developer.chrome.com/multidevice/android/customtabs). Because of this, you shouldn't reference your Activity in the `OnSuccessListener` and `OnFailureListener` listeners; they will immediately detach when the authentication operation starts.\n 1. Check if a response is already present by calling\n `startActivityForSignInWithProvider()`:\n\n ### Java\n\n mAuth = FirebaseAuth.getInstance();\n Task\u003cAuthResult\u003e pending = mAuth.getPendingAuthResult();\n if (pending != null) {\n pending.addOnSuccessListener(new OnSuccessListener\u003cAuthResult\u003e() {\n @Override\n public void onSuccess(AuthResult authResult) {\n Log.d(TAG, \"checkPending:onSuccess:\" + authResult);\n // Get the user profile with authResult.getUser() and\n // authResult.getAdditionalUserInfo(), and the ID\n // token from Apple with authResult.getCredential().\n }\n }).addOnFailureListener(new OnFailureListener() {\n @Override\n public void onFailure(@NonNull Exception e) {\n Log.w(TAG, \"checkPending:onFailure\", e);\n }\n });\n } else {\n Log.d(TAG, \"pending: null\");\n }\n\n ### Kotlin\n\n val pending = auth.pendingAuthResult\n if (pending != null) {\n pending.addOnSuccessListener { authResult -\u003e\n Log.d(TAG, \"checkPending:onSuccess:$authResult\")\n // Get the user profile with authResult.getUser() and\n // authResult.getAdditionalUserInfo(), and the ID\n // token from Apple with authResult.getCredential().\n }.addOnFailureListener { e -\u003e\n Log.w(TAG, \"checkPending:onFailure\", e)\n }\n } else {\n Log.d(TAG, \"pending: null\")\n }\n\n Signing in puts your Activity in the background, which means the system\n can reclaim it during the authentication flow. Checking if a result is\n already present prevents the user from having to sign in twice.\n 2. If there's no pending result, call\n `startActivityForSignInWithProvider()`:\n\n ### Java\n\n mAuth.startActivityForSignInWithProvider(this, provider.build())\n .addOnSuccessListener(\n new OnSuccessListener\u003cAuthResult\u003e() {\n @Override\n public void onSuccess(AuthResult authResult) {\n // Sign-in successful!\n Log.d(TAG, \"activitySignIn:onSuccess:\" + authResult.getUser());\n FirebaseUser user = authResult.getUser();\n // ...\n }\n })\n .addOnFailureListener(\n new OnFailureListener() {\n @Override\n public void onFailure(@NonNull Exception e) {\n Log.w(TAG, \"activitySignIn:onFailure\", e);\n }\n });\n\n ### Kotlin\n\n auth.startActivityForSignInWithProvider(this, provider.build())\n .addOnSuccessListener { authResult -\u003e\n // Sign-in successful!\n Log.d(TAG, \"activitySignIn:onSuccess:${authResult.user}\")\n val user = authResult.user\n // ...\n }\n .addOnFailureListener { e -\u003e\n Log.w(TAG, \"activitySignIn:onFailure\", e)\n }\n\nUnlike many other identity providers, Apple does not provide a photo URL.\n\nIf a user chooses not to share their real email with your app, Apple provisions\na unique email address for that user to share instead. This email takes the form\n`xyz@privaterelay.appleid.com`. If you configured the private email relay\nservice, Apple forwards emails sent to the anonymized address to the user's real\nemail address.\n\nApple only shares user information, such as display names, with apps the\nfirst time a user signs in. In most cases, Identity Platform stores this\ndata, which lets you fetch it using `firebase.auth().currentUser.displayName`\nduring future sessions. However, if you allowed users to sign into your app\nusing Apple before integrating with Identity Platform, user information\nis not available.\n\nWhat's next\n-----------\n\n- Learn more about [Identity Platform users](/identity-platform/docs/concepts-manage-users).\n- Sign in users with [other identity providers](/identity-platform/docs/how-to#signing-in-users)."]]