GithubAuthProvider class

Provider for generating an OAuthCredential for ProviderId.GITHUB.

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

Signature:

export declare class GithubAuthProvider extends BaseOAuthProvider 

Extends: BaseOAuthProvider

Constructors

Constructor Modifiers Description
(constructor)() Constructs a new instance of the GithubAuthProvider class

Properties

Property Modifiers Type Description
GITHUB_SIGN_IN_METHOD static 'github.com' Always set to SignInMethod.GITHUB.
PROVIDER_ID static 'github.com' Always set to ProviderId.GITHUB.

Methods

Method Modifiers Description
credential(accessToken) static Creates a credential for Github.
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.

GithubAuthProvider.(constructor)

Constructs a new instance of the GithubAuthProvider class

Signature:

constructor();

GithubAuthProvider.GITHUB_SIGN_IN_METHOD

Always set to SignInMethod.GITHUB.

Signature:

static readonly GITHUB_SIGN_IN_METHOD: 'github.com';

GithubAuthProvider.PROVIDER_ID

Always set to ProviderId.GITHUB.

Signature:

static readonly PROVIDER_ID: 'github.com';

GithubAuthProvider.credential()

Creates a credential for Github.

Signature:

static credential(accessToken: string): OAuthCredential;

Parameters

Parameter Type Description
accessToken string Github access token.

Returns:

OAuthCredential

GithubAuthProvider.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

GithubAuthProvider.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 GithubAuthProvider();
// Start a sign in process for an unauthenticated user.
provider.addScope('repo');
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 Github Access Token.
  const credential = GithubAuthProvider.credentialFromResult(result);
  const token = credential.accessToken;
}

Example 2

// Sign in using a popup.
const provider = new GithubAuthProvider();
provider.addScope('repo');
const result = await signInWithPopup(auth, provider);

// The signed-in user info.
const user = result.user;
// This gives you a Github Access Token.
const credential = GithubAuthProvider.credentialFromResult(result);
const token = credential.accessToken;