קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
אתם יכולים לאפשר למשתמשים לבצע אימות ב-Firebase באמצעות ספקי OAuth כמו Yahoo. לשם כך, משלבים באפליקציה כניסה גנרית מבוססת-אינטרנט באמצעות OAuth באמצעות Firebase SDK כדי לבצע את תהליך הכניסה מקצה לקצה. מכיוון שהתהליך הזה מחייב שימוש ב-Firebase SDK לנייד, הוא נתמך רק בפלטפורמות Android ו-Apple.
מוסיפים את FirebaseUnity SDK (במיוחד FirebaseAuth.unitypackage) לפרויקט ב-Unity.
חשוב לזכור שההוספה של Firebase לפרויקט Unity כוללת משימות,
במסוף Firebase ובפרויקט Unity הפתוח
(לדוגמה, אתם מורידים קובצי תצורה של Firebase מהמסוף, ואז מעבירים
אותם בפרויקט ב-Unity).
אופציונלי: מציינים פרמטרים מותאמים אישית נוספים של OAuth שרוצים להגדיר
שליחה עם בקשת ה-OAuth.
providerData.CustomParameters=newDictionary<string,string>;// Prompt user to re-authenticate to Yahoo.providerData.CustomParameters.Add("prompt","login");// Localize to French.providerData.CustomParameters.Add("language","fr");
הפרמטרים שבהם Yahoo תומכת מפורטים במסמכי התיעוד של Yahoo OAuth.
שימו לב שאי אפשר להעביר פרמטרים שנדרשים ל-Firebase עם
custom_parameters() הפרמטרים האלה הם client_id, redirect_uri, response_type, scope ו-state.
אופציונלי: אפשר לציין היקפי הרשאות OAuth 2.0 נוספים, מעבר ל-profile וכן
email שברצונך לבקש מספק האימות. אם
נדרשת גישה לנתוני משתמשים פרטיים מ-Yahoo APIs,
תצטרכו לבקש הרשאות ל-Yahoo APIs בקטע הרשאות API
Yahoo Developer Console. היקפי ההרשאות המבוקשים של OAuth חייבים להיות התאמות מדויקות
מוגדרים מראש בהרשאות ה-API של האפליקציה. לדוגמה, אם בוחרים בקריאה/כתיבה
הם מתבקשים לגשת לאנשי הקשר של המשתמשים, והם מוגדרים מראש ב-API של האפליקציה
הרשאות, צריך להעביר את sdct-w במקום היקף הרשאות ה-OAuth לקריאה בלבד
sdct-r. אחרת,התהליך ייכשל ותוצג שגיאה
למשתמש קצה.
providerData.Scopes=newList<string>();// Request access to Yahoo Mail API.providerData.Scopes.Add("mail-r");// This must be preconfigured in the app's API permissions.providerData.Scopes.Add("sdct-w");
אחרי שהגדרתם את נתוני הספק, השתמשו בהם כדי ליצור
FedeatedOAuthProvider.
// Construct a FederatedOAuthProvider for use in Auth methods.Firebase.Auth.FederatedOAuthProviderprovider=newFirebase.Auth.FederatedOAuthProvider();provider.SetProviderData(providerData);
אימות באמצעות Firebase באמצעות אובייקט ספק האימות. שימו לב שבניגוד ל-
פעולות אחרות של FirebaseAuth – הן יכולות לשלוט בממשק המשתמש שלכם על ידי הקפצה
תצוגת אינטרנט שבה המשתמש יכול להזין את פרטי הכניסה שלו.
כדי להתחיל את תהליך הכניסה, צריך לבצע קריאה ל-SignInAndRetrieveDataWithCredentialAsync:
<<../_includes/_sign_in_with_provider_unity.md>>>
הדוגמאות שלמעלה מתמקדות בתהליכי כניסה, אבל אפשר גם לקשר ספק של Yahoo למשתמש קיים באמצעות LinkWithProviderAsync. לדוגמה, אפשר לקשר מספר
ספקים לאותו משתמש, כדי לאפשר להם להיכנס עם אחד מהם.
user.LinkWithProviderAsync(provider).ContinueOnMainThread(task=>{if(task.IsCanceled){Debug.LogError("LinkWithProviderAsync was canceled.");return;}if(task.IsFaulted){Debug.LogError("LinkWithProviderAsync encountered an error: "+task.Exception);return;}Firebase.Auth.AuthResultauthResult=task.Result;Firebase.Auth.FirebaseUseruser=authResult.User;Debug.LogFormat("User linked successfully: {0} ({1})",user.DisplayName,user.UserId);});
אפשר להשתמש באותו דפוס עם ReauthenticateWithProviderAsync, כדי לאחזר פרטי כניסה עדכניים לפעולות רגישות שדורשות כניסה לאחרונה.
user.ReauthenticateWithProviderAsync(provider).ContinueOnMainThread(task=>{if(task.IsCanceled){Debug.LogError("ReauthenticateWithProviderAsync was canceled.");return;}if(task.IsFaulted){Debug.LogError("ReauthenticateWithProviderAsync encountered an error: "+task.Exception);return;}Firebase.Auth.AuthResultauthResult=task.Result;Firebase.Auth.FirebaseUseruser=authResult.User;Debug.LogFormat("User reauthenticated successfully: {0} ({1})",user.DisplayName,user.UserId);});
מתקדם: טיפול בתהליך הכניסה באופן ידני
בניגוד לספקים אחרים של OAuth שנתמכים על ידי Firebase, כמו Google, Facebook ו-Twitter, שבהם אפשר להיכנס ישירות באמצעות פרטי כניסה שמבוססים על אסימון גישה של OAuth, אימות ב-Firebase לא תומך באותה יכולת עבור ספקים כמו Yahoo, כי שרת האימות ב-Firebase לא יכול לאמת את הקהל של אסימוני הגישה של Yahoo ב-OAuth.
זוהי דרישת אבטחה קריטית, והיא עלולה לחשוף אפליקציות ואתרים למתקפות של שחזור, שבהן אפשר להשתמש באסימון גישה של Yahoo OAuth שנוצר לפרויקט אחד (תוקף) כדי להיכנס לפרויקט אחר (קורבן).
במקום זאת, Firebase Auth מאפשר לטפל בכל תהליך OAuth ובהחלפת קוד ההרשאה באמצעות מזהה הלקוח והסוד של OAuth שהוגדרו במסוף Firebase. מכיוון שאפשר להשתמש בקוד ההרשאה רק בשילוב עם מזהה לקוח או סוד לקוח ספציפיים, אי אפשר להשתמש בקוד הרשאה שהתקבל לפרויקט אחד בפרויקט אחר.
אם נדרש שימוש בספקים האלה בסביבות לא נתמכות,
ספריית OAuth של צד שלישי
אימות מותאם אישית ב-Firebase
יצטרך להשתמש ב-Gemini. ההגדרה הראשונה נדרשת כדי לבצע אימות מול הספק
וגם כדי להחליף את פרטי הכניסה של הספק באסימון מותאם אישית.
השלבים הבאים
אחרי שמשתמש נכנס לחשבון בפעם הראשונה, נוצר חשבון משתמש חדש שמקושר לפרטי הכניסה – כלומר שם המשתמש והסיסמה, מספר הטלפון או פרטי ספק האימות – שבאמצעותם המשתמש נכנס לחשבון. החדש הזה
מאוחסנים כחלק מפרויקט Firebase, וניתן להשתמש בהם כדי לזהות
משתמש בכל האפליקציות בפרויקט, בלי קשר לאופן שבו המשתמשים נכנסים לחשבון.
Firebase.Auth.FirebaseUseruser=auth.CurrentUser;if(user!=null){stringname=user.DisplayName;stringemail=user.Email;System.Uriphoto_url=user.PhotoUrl;// The user's Id, unique to the Firebase project.// Do NOT use this value to authenticate with your backend server, if you// have one; use User.TokenAsync() instead.stringuid=user.UserId;}
בתוך Firebase Realtime Database ו-Cloud Storageכללי אבטחה –
מקבלים את מזהה המשתמש הייחודי של המשתמש המחובר מהמשתנה auth,
ולהשתמש בהם כדי לקבוע לאילו נתונים המשתמש יוכל לגשת.
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-09-03 (שעון UTC)."],[],[],null,["You can let your users authenticate with Firebase using OAuth providers like\nYahoo by integrating web-based generic OAuth Login into your app using the\nFirebase SDK to carry out the end to end sign-in flow. Since this flow requires\nthe use of the phone-based Firebase SDKs, it is only supported on Android and\nApple platforms.\n\nBefore you begin\n\nBefore you can use\n[Firebase Authentication](/docs/reference/unity/namespace/firebase/auth),\nyou need to:\n\n- Register your Unity project and configure it to use Firebase.\n\n - If your Unity project already uses Firebase, then it's already\n registered and configured for Firebase.\n\n - If you don't have a Unity project, you can download a\n [sample app](//github.com/google/mechahamster).\n\n- Add the [Firebase Unity SDK](/download/unity) (specifically, `FirebaseAuth.unitypackage`) to\n your Unity project.\n\n| **Find detailed instructions for these initial\n| setup tasks in\n| [Add Firebase to your Unity project](/docs/unity/setup#prerequisites).**\n\nNote that adding Firebase to your Unity project involves tasks both in the\n[Firebase console](//console.firebase.google.com/) and in your open Unity project\n(for example, you download Firebase config files from the console, then move\nthem into your Unity project).\n\nAccess the `Firebase.Auth.FirebaseAuth` class The `FirebaseAuth` class is the gateway for all API calls. It is accessible through [FirebaseAuth.DefaultInstance](/docs/reference/unity/class/firebase/auth/firebase-auth#defaultinstance). \n\n```c#\nFirebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;\n```\n\nHandle the sign-in flow with the Firebase SDK\n\nTo handle the sign-in flow with the Firebase SDK, follow these steps:\n\n1. Construct an instance of a `FederatedOAuthProviderData` configured with\n the provider ID appropriate for Yahoo.\n\n Firebase.Auth.FederatedOAuthProviderData providerData =\n new Firebase.Auth.FederatedOAuthProviderData();\n providerData.ProviderId = Firebase.Auth.YahooAuthProvider.ProviderId;\n\n2. **Optional**: Specify additional custom OAuth parameters that you want to\n send with the OAuth request.\n\n providerData.CustomParameters = new Dictionary\u003cstring,string\u003e;\n\n // Prompt user to re-authenticate to Yahoo.\n providerData.CustomParameters.Add(\"prompt\", \"login\");\n\n // Localize to French.\n providerData.CustomParameters.Add(\"language\", \"fr\");\n\n For the parameters Yahoo supports, see the\n [Yahoo OAuth documentation](https://developer.yahoo.com/oauth2/guide/openid_connect/getting_started.html).\n Note that you can't pass Firebase-required parameters with\n `custom_parameters()`. These parameters are **client_id** ,\n **redirect_uri** , **response_type** , **scope** and **state**.\n3. **Optional** : Specify additional OAuth 2.0 scopes beyond `profile` and\n `email` that you want to request from the authentication provider. If your\n application requires access to private user data from Yahoo APIs, you'll\n need to request permissions to Yahoo APIs under **API Permissions** in the\n Yahoo developer console. Requested OAuth scopes must be exact matches to the\n preconfigured ones in the app's API permissions. For example if, read/write\n access is requested to user contacts and preconfigured in the app's API\n permissions, `sdct-w` has to be passed instead of the readonly OAuth scope\n `sdct-r`. Otherwise,the flow will fail and an error would be shown to the\n end user.\n\n providerData.Scopes = new List\u003cstring\u003e();\n\n // Request access to Yahoo Mail API.\n providerData.Scopes.Add(\"mail-r\");\n // This must be preconfigured in the app's API permissions.\n providerData.Scopes.Add(\"sdct-w\");\n\n To learn more, refer to the\n [Yahoo scopes documentation](https://developer.yahoo.com/oauth2/guide/yahoo_scopes/).\n4. Once your provider data has been configured, use it to create a\n FederatedOAuthProvider.\n\n // Construct a FederatedOAuthProvider for use in Auth methods.\n Firebase.Auth.FederatedOAuthProvider provider =\n new Firebase.Auth.FederatedOAuthProvider();\n provider.SetProviderData(providerData);\n\n5. Authenticate with Firebase using the Auth provider object. Note that unlike\n other FirebaseAuth operations, this will take control of your UI by popping\n up a web view in which the user can enter their credentials.\n\n To start the sign in flow, call `SignInAndRetrieveDataWithCredentialAsync`:\n\n\\\u003c\\\u003c../_includes/_sign_in_with_provider_unity.md\\\u003e\\\u003e\\\u003e\n\n1. While the above examples focus on sign-in flows, you also have the\n ability to link a Yahoo provider to an existing user using\n `LinkWithProviderAsync`. For example, you can link multiple\n providers to the same user allowing them to sign in with either.\n\n user.LinkWithProviderAsync(provider).ContinueOnMainThread(task =\u003e {\n if (task.IsCanceled) {\n Debug.LogError(\"LinkWithProviderAsync was canceled.\");\n return;\n }\n if (task.IsFaulted) {\n Debug.LogError(\"LinkWithProviderAsync encountered an error: \"\n + task.Exception);\n return;\n }\n\n Firebase.Auth.AuthResult authResult = task.Result;\n Firebase.Auth.FirebaseUser user = authResult.User;\n Debug.LogFormat(\"User linked successfully: {0} ({1})\",\n user.DisplayName, user.UserId);\n });\n\n2. The same pattern can be used with `ReauthenticateWithProviderAsync` which\n can be used to retrieve fresh credentials for sensitive operations that\n require recent login.\n\n user.ReauthenticateWithProviderAsync(provider).ContinueOnMainThread(task =\u003e {\n if (task.IsCanceled) {\n Debug.LogError(\"ReauthenticateWithProviderAsync was canceled.\");\n return;\n }\n if (task.IsFaulted) {\n Debug.LogError(\n \"ReauthenticateWithProviderAsync encountered an error: \" +\n task.Exception);\n return;\n }\n\n Firebase.Auth.AuthResult authResult = task.Result;\n Firebase.Auth.FirebaseUser user = authResult.User;\n Debug.LogFormat(\"User reauthenticated successfully: {0} ({1})\",\n user.DisplayName, user.UserId);\n });\n\nAdvanced: Handle the sign-in flow manually\n\nUnlike other OAuth providers supported by Firebase such as Google, Facebook,\nand Twitter, where sign-in can directly be achieved with OAuth access token\nbased credentials, Firebase Auth does not support the same capability for\nproviders such as Yahoo due to the inability of the Firebase\nAuth server to verify the audience of Yahoo OAuth access tokens.\nThis is a critical security requirement and could expose applications and\nwebsites to replay attacks where a Yahoo OAuth access token obtained for\none project (attacker) can be used to sign in to another project (victim).\nInstead, Firebase Auth offers the ability to handle the entire OAuth flow and\nthe authorization code exchange using the OAuth client ID and secret\nconfigured in the Firebase Console. As the authorization code can only be used\nin conjunction with a specific client ID/secret, an authorization code\nobtained for one project cannot be used with another.\n\nIf these providers are required to be used in unsupported environments, a\nthird party OAuth library and\n[Firebase custom authentication](../admin/create-custom-tokens)\nwould need to be used. The former is needed to authenticate with the provider\nand the latter to exchange the provider's credential for a custom token.\n\nNext steps\n\nAfter a user signs in for the first time, a new user account is created and\nlinked to the credentials---that is, the user name and password, phone\nnumber, or auth provider information---the user signed in with. This new\naccount is stored as part of your Firebase project, and can be used to identify\na user across every app in your project, regardless of how the user signs in.\n\n- In your apps, you can get the user's basic profile information from the\n [`Firebase.Auth.FirebaseUser`](/docs/reference/unity/class/firebase/auth/firebase-user) object:\n\n ```c#\n Firebase.Auth.FirebaseUser user = auth.CurrentUser;\n if (user != null) {\n string name = user.DisplayName;\n string email = user.Email;\n System.Uri photo_url = user.PhotoUrl;\n // The user's Id, unique to the Firebase project.\n // Do NOT use this value to authenticate with your backend server, if you\n // have one; use User.TokenAsync() instead.\n string uid = user.UserId;\n }\n ```\n- In your Firebase Realtime Database and Cloud Storage\n [Security Rules](/docs/database/security/user-security), you can\n get the signed-in user's unique user ID from the `auth` variable,\n and use it to control 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 to an\nexisting user account.](/docs/auth/unity/account-linking)\n\nTo sign out a user, call [`SignOut()`](/docs/reference/unity/class/firebase/auth/firebase-auth#signout): \n\n```c#\nauth.SignOut();\n```"]]