Birden Fazla Kimlik Doğrulama Sağlayıcısı Bir Hesaba Bağlama
Koleksiyonlar ile düzeninizi koruyun
İçeriği tercihlerinize göre kaydedin ve kategorilere ayırın.
Kullanıcıların çoklu kimlik doğrulama kullanarak uygulamanızda oturum açmasına izin verebilirsiniz
kimlik doğrulama sağlayıcı kimlik bilgilerini mevcut bir kullanıcı hesabına bağlayarak
Kullanıcılar,
kimlik doğrulama sağlayıcısından ödeme alınır. Örneğin, Yeşil Ofis'in web sitesinde
bir Google hesabını bağlayabilir ve
duymuş olabilirsiniz. Alternatif olarak, anonim bir kullanıcı bir Facebook hesabını bağlayıp daha sonra
uygulamanızı kullanmaya devam etmek için Facebook'ta oturum açın.
Başlamadan önce
İki veya daha fazla kimlik doğrulama sağlayıcısı için destek ekleyin (
anonim kimlik doğrulama) ekleyebilirsiniz.
Yetkilendirme sağlayıcı kimlik bilgilerini bir kullanıcı hesabına bağla
Kimlik doğrulama sağlayıcı kimlik bilgilerini mevcut bir kullanıcı hesabına bağlamak için:
Herhangi bir kimlik doğrulama sağlayıcısı veya yöntemi kullanarak kullanıcının oturumunu açın.
Yeni kimlik doğrulama sağlayıcı için oturum açma akışını en fazla tamamlayın ancak
Örneğin, signInWith
yöntemlerinden biri çağrılır. Örneğin,
Kullanıcının Google kimliği jetonu, Facebook erişim jetonu veya e-postası ve şifresi.
Yeni kimlik doğrulama sağlayıcı için bir Credential
nesnesi alın:
// Google Sign-in
final credential = GoogleAuthProvider.credential(idToken: idToken);
// Email and password sign-in
final credential =
EmailAuthProvider.credential(email: emailAddress, password: password);
// Etc.
Credential
nesnesini, oturum açan kullanıcının linkWithCredential()
cihazına iletin
yöntem:
try {
final userCredential = await FirebaseAuth.instance.currentUser
?.linkWithCredential(credential);
} on FirebaseAuthException catch (e) {
switch (e.code) {
case "provider-already-linked":
print("The provider has already been linked to the user.");
break;
case "invalid-credential":
print("The provider's credential is not valid.");
break;
case "credential-already-in-use":
print("The account corresponding to the credential already exists, "
"or is already linked to a Firebase User.");
break;
// See the API reference for the full list of error codes.
default:
print("Unknown error.");
}
```
linkWithCredential()
çağrısı başarılı olursa kullanıcı artık
ve aynı Firebase verilerine erişmelerini isteyebilir.
Yetkilendirme sağlayıcı ile kullanıcı hesabı arasındaki bağlantıyı kaldırma
Bir kimlik doğrulama sağlayıcı ile hesap arasındaki bağlantıyı kaldırabilirsiniz. Böylece, kullanıcı
daha uzun süre oturum açmanızı sağlar.
Bir kimlik doğrulama sağlayıcının kullanıcı hesabıyla olan bağlantısını kaldırmak için sağlayıcı kimliğini
unlink()
yöntemini çağırın. Şuna bağlı kimlik doğrulama sağlayıcılarının sağlayıcı kimliklerini alabilirsiniz:
User
nesnesinin providerData
mülkündeki bir kullanıcı.
try {
await FirebaseAuth.instance.currentUser?.unlink(providerId);
} on FirebaseAuthException catch (e) {
switch (e.code) {
case "no-such-provider":
print("The user isn't linked to the provider or the provider "
"doesn't exist.");
break;
default:
print("Unknown error.");
}
}
Aksi belirtilmediği sürece bu sayfanın içeriği Creative Commons Atıf 4.0 Lisansı altında ve kod örnekleri Apache 2.0 Lisansı altında lisanslanmıştır. Ayrıntılı bilgi için Google Developers Site Politikaları'na göz atın. Java, Oracle ve/veya satış ortaklarının tescilli ticari markasıdır.
Son güncelleme tarihi: 2025-07-25 UTC.
[null,null,["Son güncelleme tarihi: 2025-07-25 UTC."],[],[],null,["\u003cbr /\u003e\n\nYou can allow users to sign in to your app using multiple authentication\nproviders by linking auth provider credentials to an existing user account.\nUsers are identifiable by the same Firebase user ID regardless of the\nauthentication provider they used to sign in. For example, a user who signed in\nwith a password can link a Google account and sign in with either method in the\nfuture. Or, an anonymous user can link a Facebook account and then, later, sign\nin with Facebook to continue using your app.\n\nBefore you begin\n\nAdd support for two or more authentication providers (possibly including\nanonymous authentication) to your app.\n\nLink auth provider credentials to a user account\n\nTo link auth provider credentials to an existing user account:\n\n1. Sign in the user using any authentication provider or method.\n\n2. Complete the sign-in flow for the new authentication provider up to, but not\n including, calling one of the `signInWith`- methods. For example, get\n the user's Google ID token, Facebook access token, or email and password.\n\n3. Get a `Credential` object for the new authentication provider:\n\n // Google Sign-in\n final credential = GoogleAuthProvider.credential(idToken: idToken);\n\n // Email and password sign-in\n final credential =\n EmailAuthProvider.credential(email: emailAddress, password: password);\n\n // Etc.\n\n4. Pass the `Credential` object to the sign-in user's `linkWithCredential()`\n method:\n\n try {\n final userCredential = await FirebaseAuth.instance.currentUser\n ?.linkWithCredential(credential);\n } on FirebaseAuthException catch (e) {\n switch (e.code) {\n case \"provider-already-linked\":\n print(\"The provider has already been linked to the user.\");\n break;\n case \"invalid-credential\":\n print(\"The provider's credential is not valid.\");\n break;\n case \"credential-already-in-use\":\n print(\"The account corresponding to the credential already exists, \"\n \"or is already linked to a Firebase User.\");\n break;\n // See the API reference for the full list of error codes.\n default:\n print(\"Unknown error.\");\n }\n ```\n\nIf the call to `linkWithCredential()` succeeds, the user can now sign in using\nany linked authentication provider and access the same Firebase data.\n\nUnlink an auth provider from a user account\n\nYou can unlink an auth provider from an account, so that the user can no\nlonger sign in with that provider.\n\nTo unlink an auth provider from a user account, pass the provider ID to the\n`unlink()` method. You can get the provider IDs of the auth providers linked to\na user from the `User` object's `providerData` property. \n\n try {\n await FirebaseAuth.instance.currentUser?.unlink(providerId);\n } on FirebaseAuthException catch (e) {\n switch (e.code) {\n case \"no-such-provider\":\n print(\"The user isn't linked to the provider or the provider \"\n \"doesn't exist.\");\n break;\n default:\n print(\"Unknown error.\");\n }\n }"]]