Provider for generating an OAuthCredential for ProviderId.GOOGLE.
Signature:
export declare class GoogleAuthProvider extends BaseOAuthProvider
Extends: BaseOAuthProvider
Constructors
Constructor | Modifiers | Description |
---|---|---|
(constructor)() | Constructs a new instance of the GoogleAuthProvider class |
Properties
Property | Modifiers | Type | Description |
---|---|---|---|
GOOGLE_SIGN_IN_METHOD | static |
'google.com' | Always set to SignInMethod.GOOGLE. |
PROVIDER_ID | static |
'google.com' | Always set to ProviderId.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 underlying OAuthCredential from a AuthError which was thrown during a sign-in, link, or reauthenticate operation. |
credentialFromResult(userCredential) | static |
Used to extract the underlying OAuthCredential from a UserCredential. |
GoogleAuthProvider.(constructor)
Constructs a new instance of the GoogleAuthProvider
class
Signature:
constructor();
GoogleAuthProvider.GOOGLE_SIGN_IN_METHOD
Always set to SignInMethod.GOOGLE.
Signature:
static readonly GOOGLE_SIGN_IN_METHOD: 'google.com';
GoogleAuthProvider.PROVIDER_ID
Always set to ProviderId.GOOGLE.
Signature:
static readonly PROVIDER_ID: 'google.com';
GoogleAuthProvider.credential()
Creates a credential for Google. At least one of ID token and access token is required.
Signature:
static credential(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.
const credential = GoogleAuthProvider.credential(googleUser.getAuthResponse().id_token);
const result = await signInWithCredential(credential);
GoogleAuthProvider.credentialFromError()
Used to extract the underlying OAuthCredential from a AuthError which was thrown during a sign-in, link, or reauthenticate operation.
Signature:
static credentialFromError(error: FirebaseError): OAuthCredential | null;
Parameters
Parameter | Type | Description |
---|---|---|
error | FirebaseError |
Returns:
OAuthCredential | null
GoogleAuthProvider.credentialFromResult()
Used to extract the underlying OAuthCredential from a UserCredential.
Signature:
static credentialFromResult(userCredential: UserCredential): OAuthCredential | null;
Parameters
Parameter | Type | Description |
---|---|---|
userCredential | UserCredential | The user credential. |
Returns:
OAuthCredential | null
Example 1
// 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;
}
Example 2
// 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;