// 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,["Provider 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\nProperties\n\nMethods\n\nGithubAuthProvider.(constructor)\n\nConstructs a new instance of the `GithubAuthProvider` class\n\n**Signature:** \n\n constructor();\n\nGithubAuthProvider.GITHUB_SIGN_IN_METHOD\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\nAlways set to [ProviderId](./auth.md#providerid).GITHUB.\n\n**Signature:** \n\n static readonly PROVIDER_ID: 'github.com';\n\nGithubAuthProvider.credential()\n\nCreates a credential for GitHub.\n\n**Signature:** \n\n static credential(accessToken: string): OAuthCredential;\n\nParameters\n\n**Returns:**\n\n[OAuthCredential](./auth.oauthcredential.md#oauthcredential_class)\n\nGithubAuthProvider.credentialFromError()\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\nParameters\n\n**Returns:**\n\n[OAuthCredential](./auth.oauthcredential.md#oauthcredential_class) \\| null\n\nGithubAuthProvider.credentialFromResult()\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\nParameters\n\n**Returns:**\n\n[OAuthCredential](./auth.oauthcredential.md#oauthcredential_class) \\| null\n\nExample 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\nExample 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;"]]