Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Accesso degli utenti con un sistema di autenticazione personalizzato
Questo documento mostra come utilizzare Identity Platform per far accedere gli utenti con un sistema di autenticazione personalizzato. Nell'autenticazione personalizzata, utilizzi un server di autenticazione per produrre token firmati personalizzati quando un utente accede correttamente. L'app riceve questo token e lo utilizza per autenticarsi con Identity Platform.
import{getAuth,signInWithCustomToken}from"firebase/auth";constauth=getAuth();signInWithCustomToken(auth,token).then((userCredential)=>{// Signed inconstuser=userCredential.user;// ...}).catch((error)=>{consterrorCode=error.code;consterrorMessage=error.message;// ...});
firebase.auth().signInWithCustomToken(token).then((userCredential)=>{// Signed invaruser=userCredential.user;// ...}).catch((error)=>{varerrorCode=error.code;varerrorMessage=error.message;// ...});
[[["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-04 UTC."],[[["\u003cp\u003eThis guide details how to use Identity Platform for user sign-in with a custom authentication system, leveraging custom signed tokens generated by your authentication server.\u003c/p\u003e\n"],["\u003cp\u003eBefore implementing custom authentication, you should consider migrating users if Identity Platform natively supports your app's sign-in method.\u003c/p\u003e\n"],["\u003cp\u003eThe sign-in process involves collecting user credentials, sending them to your server for validation, receiving a custom JWT, and then using \u003ccode\u003esignInWithCustomToken()\u003c/code\u003e to authenticate the user with Identity Platform.\u003c/p\u003e\n"],["\u003cp\u003eTo begin, you will need to install the client SDK and ensure that your server can accept user credentials and mint custom tokens.\u003c/p\u003e\n"],["\u003cp\u003eOnce the user is signed in, you can then configure custom claims and integrate Identity Platform using the REST API.\u003c/p\u003e\n"]]],[],null,["# Signing in users with a custom authentication system\n====================================================\n\nThis document shows you how to use Identity Platform to sign in users with a custom authentication system. In custom authentication, you use an authentication server to produce custom signed tokens when a user successfully signs in. Your app receives this token and uses it to authenticate with Identity Platform.\n| **Note:** If your app uses a sign-in method that Identity Platform supports (such as email and password), consider [migrating users](/identity-platform/docs/migrating-users) instead of implementing custom authentication.\n\nBefore you begin\n----------------\n\n- [Install the client SDK](/identity-platform/docs/quickstart-email-password).\n\n- Configure your server to accept user credentials and\n [mint custom tokens](/identity-platform/docs/admin/create-custom-tokens).\n\nSigning in users\n----------------\n\n1. Collect sign-in credentials from the user.\n\n2. Send the credentials to your server. Your server validates the request, and\n returns a custom JWT.\n\n3. Pass the JWT to\n [`signInWithCustomToken()`](/identity-platform/docs/reference/rest/v1/accounts/signInWithCustomToken)\n to authenticate the user with Identity Platform:\n\n ### Web version 9\n\n ```javascript\n import { getAuth, signInWithCustomToken } from \"firebase/auth\";\n\n const auth = getAuth();\n signInWithCustomToken(auth, token)\n .then((userCredential) =\u003e {\n // Signed in\n const user = userCredential.user;\n // ...\n })\n .catch((error) =\u003e {\n const errorCode = error.code;\n const errorMessage = error.message;\n // ...\n });https://github.com/firebase/snippets-web/blob/467eaa165dcbd9b3ab15711e76fa52237ba37f8b/snippets/auth-next/custom/auth_sign_in_custom.js#L8-L21\n ```\n\n ### Web version 8\n\n ```javascript\n firebase.auth().signInWithCustomToken(token)\n .then((userCredential) =\u003e {\n // Signed in\n var user = userCredential.user;\n // ...\n })\n .catch((error) =\u003e {\n var errorCode = error.code;\n var errorMessage = error.message;\n // ...\n });https://github.com/firebase/snippets-web/blob/467eaa165dcbd9b3ab15711e76fa52237ba37f8b/auth/custom.js#L10-L20\n ```\n\nWhat's next\n===========\n\n- [Configure custom claims](/identity-platform/docs/how-to-configure-custom-claims) on users.\n- [Use the REST API](/identity-platform/docs/use-rest-api) to integrate Identity Platform with other parts of your custom authentication system."]]