// 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;
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-08-01 UTC."],[],[],null,["# GithubAuthProvider class\n\nProvider for generating an [OAuthCredential](./auth.oauthcredential.md#oauthcredential_class) for [ProviderId](./auth.md#providerid).GITHUB.\n\nGitHub requires an OAuth 2.0 redirect, so you can either handle the redirect directly, or use the [signInWithPopup()](./auth.md#signinwithpopup_770f816) handler:\n\n**Signature:** \n\n export declare class GithubAuthProvider extends BaseOAuthProvider \n\n**Extends:** BaseOAuthProvider\n\nConstructors\n------------\n\n| Constructor | Modifiers | Description |\n|-------------------------------------------------------------------------------|-----------|-------------------------------------------------------------|\n| [(constructor)()](./auth.githubauthprovider.md#githubauthproviderconstructor) | | Constructs a new instance of the `GithubAuthProvider` class |\n\nProperties\n----------\n\n| Property | Modifiers | Type | Description |\n|-----------------------------------------------------------------------------------------------|-----------|--------------|--------------------------------------------------------------|\n| [GITHUB_SIGN_IN_METHOD](./auth.githubauthprovider.md#githubauthprovidergithub_sign_in_method) | `static` | 'github.com' | Always set to [SignInMethod](./auth.md#signinmethod).GITHUB. |\n| [PROVIDER_ID](./auth.githubauthprovider.md#githubauthproviderprovider_id) | `static` | 'github.com' | Always set to [ProviderId](./auth.md#providerid).GITHUB. |\n\nMethods\n-------\n\n| Method | Modifiers | Description |\n|-------------------------------------------------------------------------------------------------------------|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [credential(accessToken)](./auth.githubauthprovider.md#githubauthprovidercredential) | `static` | Creates a credential for GitHub. |\n| [credentialFromError(error)](./auth.githubauthprovider.md#githubauthprovidercredentialfromerror) | `static` | Used to extract the underlying [OAuthCredential](./auth.oauthcredential.md#oauthcredential_class) from a [AuthError](./auth.autherror.md#autherror_interface) which was thrown during a sign-in, link, or reauthenticate operation. |\n| [credentialFromResult(userCredential)](./auth.githubauthprovider.md#githubauthprovidercredentialfromresult) | `static` | Used to extract the underlying [OAuthCredential](./auth.oauthcredential.md#oauthcredential_class) from a [UserCredential](./auth.usercredential.md#usercredential_interface). |\n\nGithubAuthProvider.(constructor)\n--------------------------------\n\nConstructs a new instance of the `GithubAuthProvider` class\n\n**Signature:** \n\n constructor();\n\nGithubAuthProvider.GITHUB_SIGN_IN_METHOD\n----------------------------------------\n\nAlways set to [SignInMethod](./auth.md#signinmethod).GITHUB.\n\n**Signature:** \n\n static readonly GITHUB_SIGN_IN_METHOD: 'github.com';\n\nGithubAuthProvider.PROVIDER_ID\n------------------------------\n\nAlways set to [ProviderId](./auth.md#providerid).GITHUB.\n\n**Signature:** \n\n static readonly PROVIDER_ID: 'github.com';\n\nGithubAuthProvider.credential()\n-------------------------------\n\nCreates a credential for GitHub.\n\n**Signature:** \n\n static credential(accessToken: string): OAuthCredential;\n\n#### Parameters\n\n| Parameter | Type | Description |\n|-------------|--------|----------------------|\n| accessToken | string | GitHub access token. |\n\n**Returns:**\n\n[OAuthCredential](./auth.oauthcredential.md#oauthcredential_class)\n\nGithubAuthProvider.credentialFromError()\n----------------------------------------\n\nUsed to extract the underlying [OAuthCredential](./auth.oauthcredential.md#oauthcredential_class) from a [AuthError](./auth.autherror.md#autherror_interface) which was thrown during a sign-in, link, or reauthenticate operation.\n\n**Signature:** \n\n static credentialFromError(error: FirebaseError): OAuthCredential | null;\n\n#### Parameters\n\n| Parameter | Type | Description |\n|-----------|--------------------------------------------------------------|-------------|\n| error | [FirebaseError](./util.firebaseerror.md#firebaseerror_class) | |\n\n**Returns:**\n\n[OAuthCredential](./auth.oauthcredential.md#oauthcredential_class) \\| null\n\nGithubAuthProvider.credentialFromResult()\n-----------------------------------------\n\nUsed to extract the underlying [OAuthCredential](./auth.oauthcredential.md#oauthcredential_class) from a [UserCredential](./auth.usercredential.md#usercredential_interface).\n\n**Signature:** \n\n static credentialFromResult(userCredential: UserCredential): OAuthCredential | null;\n\n#### Parameters\n\n| Parameter | Type | Description |\n|----------------|---------------------------------------------------------------------|----------------------|\n| userCredential | [UserCredential](./auth.usercredential.md#usercredential_interface) | The user credential. |\n\n**Returns:**\n\n[OAuthCredential](./auth.oauthcredential.md#oauthcredential_class) \\| null\n\n### Example 1\n\n // Sign in using a redirect.\n const provider = new GithubAuthProvider();\n // Start a sign in process for an unauthenticated user.\n provider.addScope('repo');\n await signInWithRedirect(auth, provider);\n // This will trigger a full page redirect away from your app\n\n // After returning from the redirect when your app initializes you can obtain the result\n const result = await getRedirectResult(auth);\n if (result) {\n // This is the signed-in user\n const user = result.user;\n // This gives you a GitHub Access Token.\n const credential = GithubAuthProvider.credentialFromResult(result);\n const token = credential.accessToken;\n }\n\n### Example 2\n\n // Sign in using a popup.\n const provider = new GithubAuthProvider();\n provider.addScope('repo');\n const result = await signInWithPopup(auth, provider);\n\n // The signed-in user info.\n const user = result.user;\n // This gives you a GitHub Access Token.\n const credential = GithubAuthProvider.credentialFromResult(result);\n const token = credential.accessToken;"]]