FacebookAuthProvider class

Provider for generating an OAuthCredential for ProviderId.FACEBOOK.

Signature:

exportdeclareclassFacebookAuthProviderextendsBaseOAuthProvider

Extends: BaseOAuthProvider

Constructors

ConstructorModifiersDescription
(constructor)()Constructs a new instance of the FacebookAuthProvider class

Properties

PropertyModifiersTypeDescription
FACEBOOK_SIGN_IN_METHODstatic'facebook.com'Always set to SignInMethod.FACEBOOK.
PROVIDER_IDstatic'facebook.com'Always set to ProviderId.FACEBOOK.

Methods

MethodModifiersDescription
credential(accessToken)staticCreates a credential for Facebook.
credentialFromError(error)staticUsed to extract the underlying OAuthCredential from a AuthError which was thrown during a sign-in, link, or reauthenticate operation.
credentialFromResult(userCredential)staticUsed to extract the underlying OAuthCredential from a UserCredential.

FacebookAuthProvider.(constructor)

Constructs a new instance of the FacebookAuthProvider class

Signature:

constructor();

FacebookAuthProvider.FACEBOOK_SIGN_IN_METHOD

Always set to SignInMethod.FACEBOOK.

Signature:

staticreadonlyFACEBOOK_SIGN_IN_METHOD:'facebook.com';

FacebookAuthProvider.PROVIDER_ID

Always set to ProviderId.FACEBOOK.

Signature:

staticreadonlyPROVIDER_ID:'facebook.com';

FacebookAuthProvider.credential()

Creates a credential for Facebook.

Signature:

staticcredential(accessToken:string):OAuthCredential;

Parameters

ParameterTypeDescription
accessTokenstringFacebook access token.

Returns:

OAuthCredential

Example

// `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.

Signature:

staticcredentialFromError(error:FirebaseError):OAuthCredential|null;

Parameters

ParameterTypeDescription
errorFirebaseError

Returns:

OAuthCredential | null

FacebookAuthProvider.credentialFromResult()

Used to extract the underlying OAuthCredential from a UserCredential.

Signature:

staticcredentialFromResult(userCredential:UserCredential):OAuthCredential|null;

Parameters

ParameterTypeDescription
userCredentialUserCredentialThe user credential.

Returns:

OAuthCredential | null

Example 1

// 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;