// `event` from the Facebook auth.authResponseChange callback.constcredential=FacebookAuthProvider.credential(event.authResponse.accessToken);constresult=awaitsignInWithCredential(credential);
FacebookAuthProvider.credentialFromError()
Used to extract the underlying OAuthCredential from a AuthError which was thrown during a sign-in, link, or reauthenticate operation.
// Sign in using a redirect.constprovider=newFacebookAuthProvider();// Start a sign in process for an unauthenticated user.provider.addScope('user_birthday');awaitsignInWithRedirect(auth,provider);// This will trigger a full page redirect away from your app// After returning from the redirect when your app initializes you can obtain the resultconstresult=awaitgetRedirectResult(auth);if(result){// This is the signed-in userconstuser=result.user;// This gives you a Facebook Access Token.constcredential=FacebookAuthProvider.credentialFromResult(result);consttoken=credential.accessToken;}
Example 2
// Sign in using a popup.constprovider=newFacebookAuthProvider();provider.addScope('user_birthday');constresult=awaitsignInWithPopup(auth,provider);// The signed-in user info.constuser=result.user;// This gives you a Facebook Access Token.constcredential=FacebookAuthProvider.credentialFromResult(result);consttoken=credential.accessToken;
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-01-19 UTC."],[],[],null,["# FacebookAuthProvider class\n\nProvider for generating an [OAuthCredential](./auth.oauthcredential.md#oauthcredential_class) for [ProviderId](./auth.md#providerid).FACEBOOK.\n\n**Signature:** \n\n export declare class FacebookAuthProvider extends BaseOAuthProvider \n\n**Extends:** BaseOAuthProvider\n\nConstructors\n------------\n\n| Constructor | Modifiers | Description |\n|-----------------------------------------------------------------------------------|-----------|---------------------------------------------------------------|\n| [(constructor)()](./auth.facebookauthprovider.md#facebookauthproviderconstructor) | | Constructs a new instance of the `FacebookAuthProvider` class |\n\nProperties\n----------\n\n| Property | Modifiers | Type | Description |\n|-------------------------------------------------------------------------------------------------------|-----------|----------------|----------------------------------------------------------------|\n| [FACEBOOK_SIGN_IN_METHOD](./auth.facebookauthprovider.md#facebookauthproviderfacebook_sign_in_method) | `static` | 'facebook.com' | Always set to [SignInMethod](./auth.md#signinmethod).FACEBOOK. |\n| [PROVIDER_ID](./auth.facebookauthprovider.md#facebookauthproviderprovider_id) | `static` | 'facebook.com' | Always set to [ProviderId](./auth.md#providerid).FACEBOOK. |\n\nMethods\n-------\n\n| Method | Modifiers | Description |\n|-----------------------------------------------------------------------------------------------------------------|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [credential(accessToken)](./auth.facebookauthprovider.md#facebookauthprovidercredential) | `static` | Creates a credential for Facebook. |\n| [credentialFromError(error)](./auth.facebookauthprovider.md#facebookauthprovidercredentialfromerror) | `static` | Used to extract the underlying [OAuthCredential](./auth.oauthcredential.md#oauthcredential_class) from a [AuthError](./auth.autherror.md#autherror_interface) which was thrown during a sign-in, link, or reauthenticate operation. |\n| [credentialFromResult(userCredential)](./auth.facebookauthprovider.md#facebookauthprovidercredentialfromresult) | `static` | Used to extract the underlying [OAuthCredential](./auth.oauthcredential.md#oauthcredential_class) from a [UserCredential](./auth.usercredential.md#usercredential_interface). |\n\nFacebookAuthProvider.(constructor)\n----------------------------------\n\nConstructs a new instance of the `FacebookAuthProvider` class\n\n**Signature:** \n\n constructor();\n\nFacebookAuthProvider.FACEBOOK_SIGN_IN_METHOD\n--------------------------------------------\n\nAlways set to [SignInMethod](./auth.md#signinmethod).FACEBOOK.\n\n**Signature:** \n\n static readonly FACEBOOK_SIGN_IN_METHOD: 'facebook.com';\n\nFacebookAuthProvider.PROVIDER_ID\n--------------------------------\n\nAlways set to [ProviderId](./auth.md#providerid).FACEBOOK.\n\n**Signature:** \n\n static readonly PROVIDER_ID: 'facebook.com';\n\nFacebookAuthProvider.credential()\n---------------------------------\n\nCreates a credential for Facebook.\n\n**Signature:** \n\n static credential(accessToken: string): OAuthCredential;\n\n#### Parameters\n\n| Parameter | Type | Description |\n|-------------|--------|------------------------|\n| accessToken | string | Facebook access token. |\n\n**Returns:**\n\n[OAuthCredential](./auth.oauthcredential.md#oauthcredential_class)\n\n### Example\n\n // `event` from the Facebook auth.authResponseChange callback.\n const credential = FacebookAuthProvider.credential(event.authResponse.accessToken);\n const result = await signInWithCredential(credential);\n\nFacebookAuthProvider.credentialFromError()\n------------------------------------------\n\nUsed to extract the underlying [OAuthCredential](./auth.oauthcredential.md#oauthcredential_class) from a [AuthError](./auth.autherror.md#autherror_interface) which was thrown during a sign-in, link, or reauthenticate operation.\n\n**Signature:** \n\n static credentialFromError(error: FirebaseError): OAuthCredential | null;\n\n#### Parameters\n\n| Parameter | Type | Description |\n|-----------|--------------------------------------------------------------|-------------|\n| error | [FirebaseError](./util.firebaseerror.md#firebaseerror_class) | |\n\n**Returns:**\n\n[OAuthCredential](./auth.oauthcredential.md#oauthcredential_class) \\| null\n\nFacebookAuthProvider.credentialFromResult()\n-------------------------------------------\n\nUsed to extract the underlying [OAuthCredential](./auth.oauthcredential.md#oauthcredential_class) from a [UserCredential](./auth.usercredential.md#usercredential_interface).\n\n**Signature:** \n\n static credentialFromResult(userCredential: UserCredential): OAuthCredential | null;\n\n#### Parameters\n\n| Parameter | Type | Description |\n|----------------|---------------------------------------------------------------------|----------------------|\n| userCredential | [UserCredential](./auth.usercredential.md#usercredential_interface) | The user credential. |\n\n**Returns:**\n\n[OAuthCredential](./auth.oauthcredential.md#oauthcredential_class) \\| null\n\n### Example 1\n\n // Sign in using a redirect.\n const provider = new FacebookAuthProvider();\n // Start a sign in process for an unauthenticated user.\n provider.addScope('user_birthday');\n await signInWithRedirect(auth, provider);\n // This will trigger a full page redirect away from your app\n\n // After returning from the redirect when your app initializes you can obtain the result\n const result = await getRedirectResult(auth);\n if (result) {\n // This is the signed-in user\n const user = result.user;\n // This gives you a Facebook Access Token.\n const credential = FacebookAuthProvider.credentialFromResult(result);\n const token = credential.accessToken;\n }\n\n### Example 2\n\n // Sign in using a popup.\n const provider = new FacebookAuthProvider();\n provider.addScope('user_birthday');\n const result = await signInWithPopup(auth, provider);\n\n // The signed-in user info.\n const user = result.user;\n // This gives you a Facebook Access Token.\n const credential = FacebookAuthProvider.credentialFromResult(result);\n const token = credential.accessToken;"]]