Constructor

OAuthProvider

new OAuthProvider(providerId)

Generic OAuth provider.

Parameter

providerId

string

The associated provider ID, such as github.com.

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 the OAuth Access Token for that provider.
    var token = result.credential.accessToken;
  }
  var user = result.user;
});

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

Property

providerId

string

Implements
firebase.auth.AuthProvider#providerId

Methods

addScope

addScope(scope) returns firebase.auth.OAuthProvider

Parameter

scope

string

Provider OAuth scope to add.

Returns

non-null firebase.auth.OAuthProvider The provider instance.

credential

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

Creates a Firebase credential from a generic OAuth provider's access token or ID token.

Parameter

idToken

Optional

string

The OAuth ID token if OIDC compliant.

Value may be null.

accessToken

Optional

string

The OAuth access token.

Value may be null.

Returns

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

Example

// `googleUser` from the onsuccess Google Sign In callback.
// Initialize a generate OAuth provider with a `google.com` providerId.
var provider = new firebase.auth.OAuthProvider('google.com');
var credential = provider.credential(
    googleUser.getAuthResponse().id_token);
firebase.auth().signInWithCredential(credential)

setCustomParameters

setCustomParameters(customOAuthParameters) returns firebase.auth.OAuthProvider

Sets the OAuth custom parameters to pass in an OAuth request for popup and redirect sign-in operations. For a detailed list, check the 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.OAuthProvider The provider instance.