אימות באמצעות Firebase באמצעות מערכת אימות בהתאמה אישית
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
אפשר לשלב אימות ב-Firebase עם מערכת אימות בהתאמה אישית:
לשנות את שרת האימות כדי להפיק אסימונים חתומים בהתאמה אישית כשמשתמש
נכנס בהצלחה. האפליקציה מקבלת את האסימון הזה ומשתמשת בו כדי לבצע אימות מול Firebase.
לפני שמתחילים
- אם עדיין לא עשיתם זאת, עליכם לפעול לפי השלבים שמפורטים במדריך תחילת העבודה.
- מתקינים ומגדירים את ה-SDK של Firebase לאדמינים.
צריך לאתחל את ה-SDK
עם פרטי הכניסה הנכונים לפרויקט Firebase.
אימות באמצעות Firebase
כשמשתמשים נכנסים לאפליקציה, שולחים את פרטי הכניסה שלהם (למשל, שם המשתמש והסיסמה) לשרת האימות. שלך
השרת בודק את פרטי הכניסה, ואם הם חוקיים,
יוצרת אסימון Firebase בהתאמה אישית
ושולח את האסימון בחזרה לאפליקציה שלכם.
אחרי שמקבלים את האסימון המותאם אישית משרת האימות, מעבירים אותו אל signInWithCustomToken()
כדי להתחבר את המשתמש:
try {
final userCredential =
await FirebaseAuth.instance.signInWithCustomToken(token);
print("Sign-in successful.");
} on FirebaseAuthException catch (e) {
switch (e.code) {
case "invalid-custom-token":
print("The supplied token is not a Firebase custom auth token.");
break;
case "custom-token-mismatch":
print("The supplied token is for a different Firebase project.");
break;
default:
print("Unknown error.");
}
}
השלבים הבאים
לאחר שמשתמש יוצר חשבון חדש, החשבון הזה מאוחסן כחלק
פרויקט Firebase, ואפשר להשתמש בו כדי לזהות משתמש בכל האפליקציות
פרויקט, ללא קשר לשיטת הכניסה שבה המשתמש השתמש.
באפליקציות שלכם, אתם יכולים לקבל את פרטי הפרופיל הבסיסיים של המשתמש מהאובייקט User
. למידע נוסף, ראו ניהול משתמשים.
במסגרת כללי האבטחה של Firebase Realtime Database ושל Cloud Storage, אפשר לקבל את מזהה המשתמש הייחודי של המשתמש שנכנס לחשבון מהמשתנה auth
, ולהשתמש בו כדי לקבוע לאילו נתונים למשתמש תהיה גישה.
אפשר לאפשר למשתמשים להיכנס לאפליקציה באמצעות מספר סוגי אימות
ספקים על ידי קישור פרטי הכניסה של ספק האימות) אל
חשבון משתמש קיים.
כדי לצאת ממשתמש, צריך להתקשר אל signOut()
:
await FirebaseAuth.instance.signOut();
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-25 (שעון UTC).
[null,null,["עדכון אחרון: 2025-07-25 (שעון UTC)."],[],[],null,["\u003cbr /\u003e\n\nYou can integrate Firebase Authentication with a custom authentication system by\nmodifying your authentication server to produce custom signed tokens when a user\nsuccessfully signs in. Your app receives this token and uses it to authenticate\nwith Firebase.\n\nBefore you begin\n\n1. If you haven't already, follow the steps in the [Get started](/docs/auth/flutter/start) guide.\n2. [Install and configure the Firebase Admin SDK](/docs/admin/setup). Be sure to [initialize the SDK](/docs/admin/setup#initialize-sdk) with the correct credentials for your Firebase project.\n\nAuthenticate with Firebase\n\n1. When users sign in to your app, send their sign-in credentials (for\n example, their username and password) to your authentication server. Your\n server checks the credentials and, if they are valid,\n [creates a custom Firebase token](/docs/auth/admin/create-custom-tokens)\n and sends the token back to your app.\n\n2. After you receive the custom token from your authentication server, pass it\n to `signInWithCustomToken()` to sign in the user:\n\n try {\n final userCredential =\n await FirebaseAuth.instance.signInWithCustomToken(token);\n print(\"Sign-in successful.\");\n } on FirebaseAuthException catch (e) {\n switch (e.code) {\n case \"invalid-custom-token\":\n print(\"The supplied token is not a Firebase custom auth token.\");\n break;\n case \"custom-token-mismatch\":\n print(\"The supplied token is for a different Firebase project.\");\n break;\n default:\n print(\"Unknown error.\");\n }\n }\n\nNext steps\n\nAfter a user creates a new account, this account is stored as part of your\nFirebase project, and can be used to identify a user across every app in your\nproject, regardless of what sign-in method the user used.\n\nIn your apps, you can get the user's basic profile information from the\n`User` object. See [Manage Users](/docs/auth/flutter/manage-users).\n\nIn your Firebase Realtime Database and Cloud Storage Security Rules, you can\nget the signed-in user's unique user ID from the `auth` variable, and use it to\ncontrol what data a user can access.\n\nYou can allow users to sign in to your app using multiple authentication\nproviders by [linking auth provider credentials](/docs/auth/flutter/account-linking)) to an\nexisting user account.\n\nTo sign out a user, call `signOut()`: \n\n await FirebaseAuth.instance.signOut();"]]