GitHub auth provider.

GitHub requires an OAuth 2.0 redirect, so you can either handle the redirect directly, or use the signInWithPopup handler:

example
// Using a redirect.
firebase.auth().getRedirectResult().then(function(result) {
  if (result.credential) {
    // This gives you a GitHub Access Token.
    var token = result.credential.accessToken;
  }
  var user = result.user;
}).catch(function(error) {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;
  // The email of the user's account used.
  var email = error.email;
  // The firebase.auth.AuthCredential type that was used.
  var credential = error.credential;
  if (errorCode === 'auth/account-exists-with-different-credential') {
    alert('You have signed up with a different provider for that email.');
    // Handle linking here if your app allows it.
  } else {
    console.error(error);
  }
});

// Start a sign in process for an unauthenticated user.
var provider = new firebase.auth.GithubAuthProvider();
provider.addScope('repo');
firebase.auth().signInWithRedirect(provider);
example
// With popup.
var provider = new firebase.auth.GithubAuthProvider();
 provider.addScope('repo');
 firebase.auth().signInWithPopup(provider).then(function(result) {
   // This gives you a GitHub Access Token.
   var token = result.credential.accessToken;
   // The signed-in user info.
   var user = result.user;
 }).catch(function(error) {
   // Handle Errors here.
   var errorCode = error.code;
   var errorMessage = error.message;
   // The email of the user's account used.
   var email = error.email;
   // The firebase.auth.AuthCredential type that was used.
   var credential = error.credential;
   if (errorCode === 'auth/account-exists-with-different-credential') {
     alert('You have signed up with a different provider for that email.');
     // Handle linking here if your app allows it.
   } else {
     console.error(error);
   }
 });
see

firebase.auth.Auth.onAuthStateChanged to receive sign in state changes.

Implements

Index

Properties

providerId

providerId: string

Static GITHUB_SIGN_IN_METHOD

GITHUB_SIGN_IN_METHOD: string

This corresponds to the sign-in method identifier as returned in firebase.auth.Auth.fetchSignInMethodsForEmail.

Static PROVIDER_ID

PROVIDER_ID: string

Methods

addScope

setCustomParameters

  • setCustomParameters ( customOAuthParameters Object ) : AuthProvider
  • Sets the OAuth custom parameters to pass in a GitHub OAuth request for popup and redirect sign-in operations. Valid parameters include 'allow_signup'. For a detailed list, check the GitHub 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.

    Parameters

    • customOAuthParameters: Object

      The custom OAuth parameters to pass in the OAuth request.

    Returns AuthProvider

    The provider instance itself.

Static credential

  • credential ( token string ) : OAuthCredential
  • example
    var cred = firebase.auth.GithubAuthProvider.credential(
        // `event` from the Github auth.authResponseChange callback.
        event.authResponse.accessToken
    );

    Parameters

    • token: string

      Github access token.

    Returns OAuthCredential

    The auth provider credential.