Skip to content

Latest commit

 

History

History
168 lines (114 loc) · 5.66 KB

auth.oauthprovider.md

File metadata and controls

168 lines (114 loc) · 5.66 KB

Project: /docs/reference/js/_project.yaml Book: /docs/reference/_book.yaml page_type: reference

{% comment %} DO NOT EDIT THIS FILE! This is generated by the JS SDK team, and any local changes will be overwritten. Changes should be made in the source code at https://github.com/firebase/firebase-js-sdk {% endcomment %}

OAuthProvider class

Provider for generating generic OAuthCredential.

Signature:

exportdeclareclassOAuthProviderextendsBaseOAuthProvider

Extends: BaseOAuthProvider

Methods

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

OAuthProvider.credential()

Creates a OAuthCredential 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 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

OAuthProvider.credentialFromJSON()

Creates an OAuthCredential 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 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=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;
close