GithubAuthProvider class

Provider for generating anOAuthCredential forProviderId.GITHUB.

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

Signature:

exportdeclareclassGithubAuthProviderextendsBaseOAuthProvider

Extends: BaseOAuthProvider

Constructors

ConstructorModifiersDescription
(constructor)()Constructs a new instance of theGithubAuthProvider class

Properties

PropertyModifiersTypeDescription
GITHUB_SIGN_IN_METHODstatic'github.com'Always set toSignInMethod.GITHUB.
PROVIDER_IDstatic'github.com'Always set toProviderId.GITHUB.

Methods

MethodModifiersDescription
credential(accessToken)staticCreates a credential for GitHub.
credentialFromError(error)staticUsed to extract the underlyingOAuthCredential from aAuthError which was thrown during a sign-in, link, or reauthenticate operation.
credentialFromResult(userCredential)staticUsed to extract the underlyingOAuthCredential from aUserCredential.

GithubAuthProvider.(constructor)

Constructs a new instance of theGithubAuthProvider class

Signature:

constructor();

GithubAuthProvider.GITHUB_SIGN_IN_METHOD

Always set toSignInMethod.GITHUB.

Signature:

staticreadonlyGITHUB_SIGN_IN_METHOD:'github.com';

GithubAuthProvider.PROVIDER_ID

Always set toProviderId.GITHUB.

Signature:

staticreadonlyPROVIDER_ID:'github.com';

GithubAuthProvider.credential()

Creates a credential for GitHub.

Signature:

staticcredential(accessToken:string):OAuthCredential;

Parameters

ParameterTypeDescription
accessTokenstringGitHub access token.

Returns:

OAuthCredential

GithubAuthProvider.credentialFromError()

Used to extract the underlyingOAuthCredential from aAuthError which was thrown during a sign-in, link, or reauthenticate operation.

Signature:

staticcredentialFromError(error:FirebaseError):OAuthCredential|null;

Parameters

ParameterTypeDescription
errorFirebaseError

Returns:

OAuthCredential | null

GithubAuthProvider.credentialFromResult()

Used to extract the underlyingOAuthCredential from aUserCredential.

Signature:

staticcredentialFromResult(userCredential:UserCredential):OAuthCredential|null;

Parameters

ParameterTypeDescription
userCredentialUserCredentialThe user credential.

Returns:

OAuthCredential | null

Example 1

// Sign in using a redirect.constprovider=newGithubAuthProvider();// Start a sign in process for an unauthenticated user.provider.addScope('repo');awaitsignInWithRedirect(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 resultconstresult=awaitgetRedirectResult(auth);if(result){// This is the signed-in userconstuser=result.user;// This gives you a GitHub Access Token.constcredential=GithubAuthProvider.credentialFromResult(result);consttoken=credential.accessToken;}

Example 2

// Sign in using a popup.constprovider=newGithubAuthProvider();provider.addScope('repo');constresult=awaitsignInWithPopup(auth,provider);// The signed-in user info.constuser=result.user;// This gives you a GitHub Access Token.constcredential=GithubAuthProvider.credentialFromResult(result);consttoken=credential.accessToken;

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-08-01 UTC.