Constructor

GoogleAuthProvider

new GoogleAuthProvider()

Google auth provider.

Implements
firebase.auth.AuthProvider
See also
firebase.auth.Auth#onAuthStateChanged to receive sign in state changes.

Examples

// Using a redirect.
firebase.auth().getRedirectResult().then(function(result) {
  if (result.credential) {
    // This gives you a Google Access Token.
    var token = result.credential.accessToken;
  }
  var user = result.user;
});

// Start a sign in process for an unauthenticated user.
var provider = new firebase.auth.GoogleAuthProvider();
provider.addScope('profile');
provider.addScope('email');
firebase.auth().signInWithRedirect(provider);
// Using a popup.
var provider = new firebase.auth.GoogleAuthProvider();
provider.addScope('profile');
provider.addScope('email');
firebase.auth().signInWithPopup(provider).then(function(result) {
 // This gives you a Google Access Token.
 var token = result.credential.accessToken;
 // The signed-in user info.
 var user = result.user;
});

Properties

PROVIDER_ID

static

string

providerId

string

Implements
firebase.auth.AuthProvider#providerId

Methods

credential

static

credential(idToken, accessToken) returns firebase.auth.AuthCredential

Creates a credential for Google. At least one of ID token and access token is required.

Parameter

idToken

Optional

string

Google ID token.

Value may be null.

accessToken

Optional

string

Google access token.

Value may be null.

Returns

non-null firebase.auth.AuthCredential The auth provider credential.

Example

// `googleUser` from the onsuccess Google Sign In callback.
var credential = firebase.auth.GoogleAuthProvider.credential(
              googleUser.getAuthResponse().id_token);
firebase.auth().signInWithCredential(credential)

addScope

addScope(scope) returns firebase.auth.AuthProvider

Parameter

scope

string

Google OAuth scope.

Returns

non-null firebase.auth.AuthProvider The provider instance itself.

setCustomParameters

setCustomParameters(customOAuthParameters) returns firebase.auth.AuthProvider

Sets the OAuth custom parameters to pass in a Google OAuth request for popup and redirect sign-in operations. Valid parameters include 'hd', 'hl', 'include_granted_scopes', 'login_hint' and 'prompt'. For a detailed list, check the Google documentation. Reserved required OAuth 2.0 parameters such as 'client_id', 'redirect_uri', 'scope', 'response_type' and 'state' are not allowed and will be ignored.

Parameter

customOAuthParameters

Object

The custom OAuth parameters to pass in the OAuth request.

Value must not be null.

Returns

non-null firebase.auth.AuthProvider The provider instance itself.