GoogleAuthProvider class Stay organized with collections Save and categorize content based on your preferences.
Provider for generating anOAuthCredential forProviderId.GOOGLE.
Signature:
exportdeclareclassGoogleAuthProviderextendsBaseOAuthProviderExtends: BaseOAuthProvider
Constructors
| Constructor | Modifiers | Description |
|---|---|---|
| (constructor)() | Constructs a new instance of theGoogleAuthProvider class |
Properties
| Property | Modifiers | Type | Description |
|---|---|---|---|
| GOOGLE_SIGN_IN_METHOD | static | 'google.com' | Always set toSignInMethod.GOOGLE. |
| PROVIDER_ID | static | 'google.com' | Always set toProviderId.GOOGLE. |
Methods
| Method | Modifiers | Description |
|---|---|---|
| credential(idToken, accessToken) | static | Creates a credential for Google. At least one of ID token and access token is required. |
| credentialFromError(error) | static | Used to extract the underlyingOAuthCredential from aAuthError which was thrown during a sign-in, link, or reauthenticate operation. |
| credentialFromResult(userCredential) | static | Used to extract the underlyingOAuthCredential from aUserCredential. |
GoogleAuthProvider.(constructor)
Constructs a new instance of theGoogleAuthProvider class
Signature:
constructor();GoogleAuthProvider.GOOGLE_SIGN_IN_METHOD
Always set toSignInMethod.GOOGLE.
Signature:
staticreadonlyGOOGLE_SIGN_IN_METHOD:'google.com';GoogleAuthProvider.PROVIDER_ID
Always set toProviderId.GOOGLE.
Signature:
staticreadonlyPROVIDER_ID:'google.com';GoogleAuthProvider.credential()
Creates a credential for Google. At least one of ID token and access token is required.
Signature:
staticcredential(idToken?:string|null,accessToken?:string|null):OAuthCredential;Parameters
| Parameter | Type | Description |
|---|---|---|
| idToken | string | null | Google ID token. |
| accessToken | string | null | Google access token. |
Returns:
Example
// \`googleUser\` from the onsuccess Google Sign In callback.constcredential=GoogleAuthProvider.credential(googleUser.getAuthResponse().id_token);constresult=awaitsignInWithCredential(credential);GoogleAuthProvider.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
| Parameter | Type | Description |
|---|---|---|
| error | FirebaseError |
Returns:
OAuthCredential | null
GoogleAuthProvider.credentialFromResult()
Used to extract the underlyingOAuthCredential from aUserCredential.
Signature:
staticcredentialFromResult(userCredential:UserCredential):OAuthCredential|null;Parameters
| Parameter | Type | Description |
|---|---|---|
| userCredential | UserCredential | The user credential. |
Returns:
OAuthCredential | null
Example 1
// Sign in using a redirect.constprovider=newGoogleAuthProvider();// 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 Google Access Token.constcredential=GoogleAuthProvider.credentialFromResult(result);consttoken=credential.accessToken;}Example 2
// Sign in using a popup.constprovider=newGoogleAuthProvider();provider.addScope('profile');provider.addScope('email');constresult=awaitsignInWithPopup(auth,provider);// The signed-in user info.constuser=result.user;// This gives you a Google Access Token.constcredential=GoogleAuthProvider.credentialFromResult(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-02-01 UTC.