docs-devsite/auth.googleauthprovider.md
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 an OAuthCredential for ProviderId<!-- -->.GOOGLE.
<b>Signature:</b>
export declare class GoogleAuthProvider extends BaseOAuthProvider
<b>Extends:</b> BaseOAuthProvider
| Constructor | Modifiers | Description |
|---|---|---|
| (constructor)() | Constructs a new instance of the <code>GoogleAuthProvider</code> class |
| Property | Modifiers | Type | Description |
|---|---|---|---|
| GOOGLE_SIGN_IN_METHOD | <code>static</code> | 'google.com' | Always set to SignInMethod<!-- -->.GOOGLE. |
| PROVIDER_ID | <code>static</code> | 'google.com' | Always set to ProviderId<!-- -->.GOOGLE. |
| Method | Modifiers | Description |
|---|---|---|
| credential(idToken, accessToken) | <code>static</code> | Creates a credential for Google. At least one of ID token and access token is required. |
| credentialFromError(error) | <code>static</code> | Used to extract the underlying OAuthCredential from a AuthError which was thrown during a sign-in, link, or reauthenticate operation. |
| credentialFromResult(userCredential) | <code>static</code> | Used to extract the underlying OAuthCredential from a UserCredential<!-- -->. |
Constructs a new instance of the GoogleAuthProvider class
<b>Signature:</b>
constructor();
Always set to SignInMethod<!-- -->.GOOGLE.
<b>Signature:</b>
static readonly GOOGLE_SIGN_IN_METHOD: 'google.com';
Always set to ProviderId<!-- -->.GOOGLE.
<b>Signature:</b>
static readonly PROVIDER_ID: 'google.com';
Creates a credential for Google. At least one of ID token and access token is required.
<b>Signature:</b>
static credential(idToken?: string | null, accessToken?: string | null): OAuthCredential;
| Parameter | Type | Description |
|---|---|---|
| idToken | string | null | Google ID token. |
| accessToken | string | null | Google access token. |
<b>Returns:</b>
// \`googleUser\` from the onsuccess Google Sign In callback.
const credential = GoogleAuthProvider.credential(googleUser.getAuthResponse().id_token);
const result = await signInWithCredential(credential);
Used to extract the underlying OAuthCredential from a AuthError which was thrown during a sign-in, link, or reauthenticate operation.
<b>Signature:</b>
static credentialFromError(error: FirebaseError): OAuthCredential | null;
| Parameter | Type | Description |
|---|---|---|
| error | FirebaseError |
<b>Returns:</b>
OAuthCredential | null
Used to extract the underlying OAuthCredential from a UserCredential<!-- -->.
<b>Signature:</b>
static credentialFromResult(userCredential: UserCredential): OAuthCredential | null;
| Parameter | Type | Description |
|---|---|---|
| userCredential | UserCredential | The user credential. |
<b>Returns:</b>
OAuthCredential | null
// Sign in using a redirect.
const provider = new GoogleAuthProvider();
// Start a sign in process for an unauthenticated user.
provider.addScope('profile');
provider.addScope('email');
await signInWithRedirect(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 result
const result = await getRedirectResult(auth);
if (result) {
// This is the signed-in user
const user = result.user;
// This gives you a Google Access Token.
const credential = GoogleAuthProvider.credentialFromResult(result);
const token = credential.accessToken;
}
// Sign in using a popup.
const provider = new GoogleAuthProvider();
provider.addScope('profile');
provider.addScope('email');
const result = await signInWithPopup(auth, provider);
// The signed-in user info.
const user = result.user;
// This gives you a Google Access Token.
const credential = GoogleAuthProvider.credentialFromResult(result);
const token = credential.accessToken;