GET /api/auth/github
Initiates the GitHub OAuth 2.0 authentication flow by redirecting users to GitHub’s authorization page.Query Parameters
None required. The endpoint automatically constructs the authorization URL.OAuth Scopes
The following GitHub scopes are requested:repo- Full control of private repositoriesuser:email- Access to user email addressesadmin:repo_hook- Full control of repository hooks
Response
Redirects to GitHub’s authorization page:Example Request
Notes
- Users will be redirected to GitHub to authorize the application
- After authorization, GitHub redirects back to
/api/auth/github/callback - The
client_idis configured via theGITHUB_CLIENT_IDenvironment variable
GET /api/auth/github/callback
Handles the OAuth callback from GitHub, exchanges the authorization code for an access token, and creates or updates the user account.Query Parameters
Authorization code provided by GitHub after user authorization
Process Flow
- Receives authorization code from GitHub
- Exchanges code for GitHub access token
- Fetches user profile from GitHub API
- Retrieves primary email address
- Creates new user or updates existing user
- Generates JWT tokens
- Sets authentication cookies
- Redirects to frontend application
Response
Redirects to the frontend URL specified inFRONTEND_URL environment variable.
Cookies Set
Expiry: 8-9 daysDevelopment:
- httpOnly: true
- secure: false
- sameSite: Lax
- expires: 9 days
- httpOnly: true
- secure: true
- sameSite: Strict
- domain: .deployhub.cloud
- expires: 8 days
Expiry: 6-10 hoursDevelopment:
- httpOnly: true
- secure: false
- sameSite: Lax
- expires: 10 hours
- httpOnly: true
- secure: true
- sameSite: Strict
- domain: .deployhub.cloud
- expires: 6 hours
User Data Stored
For new users:fullname- GitHub name or login usernameemail- Primary email from GitHubgithubId- GitHub user IDgithubUsername- GitHub usernamegithubAccessToken- GitHub OAuth access tokenprovider- Set to “github”password- Set to null (OAuth users don’t have passwords)
- Updates
githubAccessToken,githubId,githubUsername, andprovider
Status Codes
302- Successful authentication, redirects to frontend400- Missing code or GitHub authentication failed500- GitHub OAuth failed
Error Responses
Example Usage
Users don’t typically call this endpoint directly. The flow is:- User clicks “Login with GitHub” button
- Frontend redirects to
/api/auth/github - User authorizes on GitHub
- GitHub redirects to
/api/auth/github/callback?code=... - Backend processes OAuth and redirects to frontend
Environment Variables Required
GITHUB_CLIENT_ID- GitHub OAuth application client IDGITHUB_CLIENT_SECRET- GitHub OAuth application client secretFRONTEND_URL- Frontend application URL for redirect after authenticationACCESS_TOKEN_SECRET- Secret for signing JWT access tokensREFRESH_TOKEN_SECRET- Secret for signing JWT refresh tokensACCESS_TOKEN_EXPIRY- Access token expiration timeREFRESH_TOKEN_EXPIRY- Refresh token expiration time
Notes
- GitHub users can access their repositories through the stored
githubAccessToken - The token is updated on each login to ensure it remains valid
- If a user already exists with the email, their account is updated to link with GitHub
- No subscription is created during GitHub OAuth (unlike email registration)