OAuthProvider class

Provider for generating genericOAuthCredential.

Signature:

exportdeclareclassOAuthProviderextendsBaseOAuthProvider

Extends: BaseOAuthProvider

Methods

MethodModifiersDescription
credential(params)Creates aOAuthCredential from a generic OAuth provider's access token or ID token.
credentialFromError(error)staticUsed to extract the underlyingOAuthCredential from aAuthError which was thrown during a sign-in, link, or reauthenticate operation.
credentialFromJSON(json)staticCreates anOAuthCredential from a JSON string or a plain object.
credentialFromResult(userCredential)staticUsed to extract the underlyingOAuthCredential from aUserCredential.

OAuthProvider.credential()

Creates aOAuthCredential from a generic OAuth provider's access token or ID token.

The raw nonce is required when an ID token with a nonce field is provided. The SHA-256 hash of the raw nonce must match the nonce field in the ID token.

Signature:

credential(params:OAuthCredentialOptions):OAuthCredential;

Parameters

ParameterTypeDescription
paramsOAuthCredentialOptionsEither the options object containing the ID token, access token and raw nonce or the ID token string.

Returns:

OAuthCredential

Example

// `googleUser` from the onsuccess Google Sign In callback.// Initialize a generate OAuth provider with a `google.com` providerId.constprovider=newOAuthProvider('google.com');constcredential=provider.credential({idToken:googleUser.getAuthResponse().id_token,});constresult=awaitsignInWithCredential(credential);

OAuthProvider.credentialFromError()

Used to extract the underlyingOAuthCredential from aAuthError which was thrown during a sign-in, link, or reauthenticate operation.

Signature:

staticcredentialFromError(error:FirebaseError):OAuthCredential|null;

Parameters

ParameterTypeDescription
errorFirebaseError

Returns:

OAuthCredential | null

OAuthProvider.credentialFromJSON()

Creates anOAuthCredential from a JSON string or a plain object.

Signature:

staticcredentialFromJSON(json:object|string):OAuthCredential;

Parameters

ParameterTypeDescription
jsonobject | stringA plain object or a JSON string

Returns:

OAuthCredential

OAuthProvider.credentialFromResult()

Used to extract the underlyingOAuthCredential from aUserCredential.

Signature:

staticcredentialFromResult(userCredential:UserCredential):OAuthCredential|null;

Parameters

ParameterTypeDescription
userCredentialUserCredentialThe user credential.

Returns:

OAuthCredential | null

Example 1

// Sign in using a redirect.constprovider=newOAuthProvider('google.com');// Start a sign in process for an unauthenticated user.provider.addScope('profile');provider.addScope('email');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 OAuth Access Token for the provider.constcredential=provider.credentialFromResult(auth,result);consttoken=credential.accessToken;}

Example 2

// Sign in using a popup.constprovider=newOAuthProvider('google.com');provider.addScope('profile');provider.addScope('email');constresult=awaitsignInWithPopup(auth,provider);// The signed-in user info.constuser=result.user;// This gives you a OAuth Access Token for the provider.constcredential=provider.credentialFromResult(auth,result);consttoken=credential.accessToken;

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-01-19 UTC.