GitHub OAuth Provider¶
Authenticate users with their GitHub accounts.
Prerequisites¶
Register a GitHub OAuth App at https://github.com/settings/applications/new:
- Homepage URL:
https://your-domain.com - Authorization callback URL:
https://your-domain.com/auth/oauth/github/callback
Copy the Client ID and generate a Client Secret.
Setup¶
import os
from fastauth.providers.github import GitHubProvider
config = FastAuthConfig(
providers=[
GitHubProvider(
client_id=os.environ["GITHUB_CLIENT_ID"],
client_secret=os.environ["GITHUB_CLIENT_SECRET"],
),
],
oauth_adapter=adapter.oauth,
oauth_state_store=MemorySessionBackend(),
oauth_redirect_url="https://your-domain.com/auth/callback", # optional frontend redirect
...
)
Email policy¶
GitHub accounts may have a private email address. FastAuth fetches the user's primary, verified email from the GitHub API. If no public email is available it falls back to the verified primary email from the /user/emails endpoint.
Note
Users without a verified email on GitHub cannot sign in until they add and verify one.
Flow¶
The flow is the same as Google OAuth — call /authorize, redirect the user, handle the callback. The provider ID is github: