Prerequisites
Before implementing GitHub Sign-In, you need to:- Have a GitHub account
- Register a new OAuth application on GitHub
- Obtain OAuth credentials (Client ID and Client Secret)
- Configure authorization callback URLs
GitHub OAuth App Setup
-
Create an OAuth App
- Go to GitHub Developer Settings
- Click “OAuth Apps” in the left sidebar
- Click “New OAuth App”
-
Configure Application Details
- Application name: Enter your application’s name
- Homepage URL:
- For local development:
http://localhost:3000 - For production:
https://yourdomain.com
- For local development:
- Application description: (Optional) Describe your application
- Authorization callback URL: This is critical for OAuth to work
- For local development:
http://localhost:3000/api/_internal/auth/github/callback - For production:
https://yourdomain.com/api/_internal/auth/github/callback
- For local development:
-
Register Application
- Click “Register application”
-
Generate Client Secret
- After registration, you’ll see your Client ID
- Click “Generate a new client secret”
- Copy and save the Client Secret immediately (it won’t be shown again)
-
Save Credentials
- Store your Client ID and Client Secret securely
- Use environment variables or Modelence Cloud config
- Never commit these credentials to version control
Server-Side Configuration
GitHub Sign-In is built into Modelence and requires no additional packages.Option 1: Modelence Cloud (Recommended)
The preferred way to configure GitHub authentication is through Modelence Cloud:- Go to https://cloud.modelence.com/
- Navigate to your project
- Go to Authentication → Providers → GitHub
- Enable GitHub authentication
- Enter your Client ID and Client Secret from GitHub
- Save the configuration
Option 2: Environment Variables
Alternatively, you can use environment variables. Create a.env file in your project root:
MODELENCE_AUTH_GITHUB_CLIENT_SCOPES: Comma-separated list of OAuth scopes to request from GitHub. Defaults touser:emailif not specified.
.env to your .gitignore file to keep credentials secure.
The GitHub authentication is automatically enabled when these configurations are set. No additional server code is needed.
Client-Side Implementation
To initiate GitHub Sign-In, redirect the user to the GitHub authentication endpoint:UI Integration
Add a GitHub Sign-In button to your UI:How GitHub Sign-In Works
- Initiation - User clicks “Sign in with GitHub” button
- Redirect - User is redirected to GitHub’s OAuth authorization page
- Authorization - User grants permission to your app
- Callback - GitHub redirects back to your app with an authorization code
- Token Exchange - Your server exchanges the code for an access token and user information
- User Creation/Login - If user doesn’t exist, a new account is created; otherwise, user is logged in
- Session Creation - A session is established and the user is authenticated
User Data Handling
When a user signs in with GitHub, Modelence automatically:- Creates a user account if one doesn’t exist
- Links the GitHub account to the user profile
- Retrieves profile information (username, email, avatar, name)
- Marks the email as verified if GitHub has verified it
Requesting Additional Scopes
By default, Modelence requests basic profile information (user:email scope). If you need additional data from GitHub, you can configure additional scopes using the MODELENCE_AUTH_GITHUB_CLIENT_SCOPES environment variable or through Modelence Cloud.
Configuring Scopes
Via Environment Variables:- Go to cloud.modelence.com
- Navigate to Authentication → Providers → GitHub
- Add the desired scopes in the scopes configuration field
Common GitHub Scopes
user:email- Access to user’s email addresses (default, required for authentication)read:user- Read access to user profile datauser- Full access to user profile data (includes read and write)repo- Access to public and private repositoriespublic_repo- Access to public repositories onlygist- Access to gistsread:org- Read-only access to organization membership
Combining with Email/Password Authentication
Users can have both GitHub and email/password authentication on the same account:Troubleshooting
Authorization callback URL mismatch- Ensure the callback URL in your GitHub OAuth App settings exactly matches your application URL
- Check for trailing slashes and http vs https
- Common format:
https://yourdomain.com/api/_internal/auth/github/callback - You can only register one callback URL per OAuth App
- Check your GitHub app settings to ensure it hasn’t been suspended
- Verify your account is in good standing
- Verify your Client ID and Client Secret are correct
- Check that environment variables are properly loaded
- Ensure you copied the Client Secret correctly (it’s only shown once)
- Make sure credentials are from the correct GitHub OAuth App
- Some GitHub users have private email addresses
- Users must have at least one public email or primary email set
- You may need to handle cases where email is not provided
- Consider prompting users to provide an email if not available from GitHub
- GitHub enforces rate limits on OAuth endpoints
- If developing locally, avoid making too many authentication requests in quick succession
- Production apps typically don’t hit these limits under normal usage