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 %}
Provider for generating generic OAuthCredential.
Signature:
exportdeclareclassOAuthProviderextendsBaseOAuthProvider
Extends: BaseOAuthProvider
Method | Modifiers | Description |
---|---|---|
credential(params) | Creates a OAuthCredential from a generic OAuth provider's access token or ID token. | |
credentialFromError(error) | static | Used to extract the underlying OAuthCredential from a AuthError which was thrown during a sign-in, link, or reauthenticate operation. |
credentialFromJSON(json) | static | Creates an OAuthCredential from a JSON string or a plain object. |
credentialFromResult(userCredential) | static | Used to extract the underlying OAuthCredential from a UserCredential. |
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;
Parameter | Type | Description |
---|---|---|
params | OAuthCredentialOptions | Either the options object containing the ID token, access token and raw nonce or the ID token string. |
Returns:
// `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);
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;
Parameter | Type | Description |
---|---|---|
error | FirebaseError |
Returns:
OAuthCredential | null
Creates an OAuthCredential from a JSON string or a plain object.
Signature:
staticcredentialFromJSON(json: object|string): OAuthCredential;
Parameter | Type | Description |
---|---|---|
json | object | string | A plain object or a JSON string |
Returns:
Used to extract the underlying OAuthCredential from a UserCredential.
Signature:
staticcredentialFromResult(userCredential: UserCredential): OAuthCredential|null;
Parameter | Type | Description |
---|---|---|
userCredential | UserCredential | The user credential. |
Returns:
OAuthCredential | null
// 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;}
// 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;