Overview
The GitHub provider enables authentication using GitHub accounts. It implements the OAuth 2.0 protocol and automatically retrieves verified email addresses from private accounts.Installation
Setup
1. Create OAuth App
- Go to GitHub Settings
- Click OAuth Apps > New OAuth App
- Fill in the application details:
- Application name: Your app name
- Homepage URL:
https://yourdomain.com - Authorization callback URL:
- Development:
http://localhost:3000/api/auth/callback/github - Production:
https://yourdomain.com/api/auth/callback/github
- Development:
- Click Register application
- Save your Client ID and generate a Client Secret
2. Configure Environment Variables
Configuration
GitHubProviderConfig
OAuth client ID from GitHub OAuth App settings
OAuth client secret from GitHub OAuth App settings
The callback URL where users will be redirected after authentication
OAuth scopes to request. Defaults to
["read:user", "user:email"]Usage
Custom Scopes
Request additional permissions from GitHub:Available Scopes
read:user- Read user profile datauser:email- Access user email addresses (required for email retrieval)repo- Full control of private repositoriespublic_repo- Access public repositoriesread:org- Read organization membershipgist- Create and edit gists
Implementation Details
The GitHub provider is implemented in/home/daytona/workspace/source/packages/providers/github/src/index.ts:1:
Email Retrieval
The provider automatically handles email retrieval for accounts with private email settings (see/home/daytona/workspace/source/packages/providers/github/src/index.ts:101):
The provider requires the
user:email scope to access email addresses for accounts with private email settings.User Profile
The provider returns the following user profile data:GitHub user ID (converted to string)
User’s primary verified email address
User’s full name, or login username if name is not set
URL to user’s avatar image
Always
true - GitHub only returns verified email addressesFeatures
- Full OAuth 2.0 implementation
- Automatic email retrieval for private accounts
- Verified email addresses only
- Falls back to username if name is not set
- Support for all GitHub OAuth scopes
Troubleshooting
Redirect URI Mismatch
Ensure the redirect URI in your code exactly matches the authorization callback URL configured in your GitHub OAuth App, including the protocol (http/https) and trailing slashes.Missing Email Error
If you receive a “Could not retrieve email from GitHub account” error:- Verify the
user:emailscope is included in your configuration - Ensure the user has at least one verified email address on their GitHub account
- Check that the user hasn’t blocked email access in their GitHub privacy settings
Invalid Client Error
Double-check that yourGITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET environment variables are correctly set and match your OAuth App credentials.