Overview
GitStarRecall supports two authentication methods for accessing the GitHub API:- OAuth Flow: PKCE-based OAuth 2.0 authorization flow
- Personal Access Token (PAT): Direct token authentication
Authentication Methods
OAuth Configuration
The OAuth configuration is automatically generated based on environment variables.GitHub OAuth application client ID. Set via
VITE_GITHUB_CLIENT_ID environment variable.OAuth callback URL. Defaults to
${window.location.origin}/auth/callback or can be set via VITE_GITHUB_REDIRECT_URI.Required GitHub scopes. Always includes
["read:user", "repo"].OAuth Flow
Starting OAuth Login
Initiate the OAuth authorization flow with GitHub.- Generates a random state parameter (32 bytes)
- Generates a PKCE code verifier (48 bytes)
- Creates SHA-256 code challenge from the verifier
- Stores state and verifier in
sessionStorage - Returns the GitHub authorization URL
GitHub OAuth application client ID
Callback URL after authorization
Space-separated scopes:
"read:user repo"Random state for CSRF protection
Base64-URL encoded SHA-256 hash of the code verifier
Always
"S256" for SHA-256 hashingSet to
"false" - requires existing GitHub accountHandling OAuth Callback
Process the OAuth callback from GitHub and exchange the code for an access token.Authorization code from GitHub callback URL
State parameter from callback URL (must match stored state)
GitHub personal access token for API requests
- Missing OAuth session (state or verifier not found)
- State mismatch (CSRF protection)
- Missing exchange URL configuration
- Failed token exchange (non-200 response)
- Missing access token in response
Session Storage Keys
The OAuth flow uses thesesessionStorage keys:
gitstarrecall.oauth.state- Random state for CSRF protectiongitstarrecall.oauth.verifier- PKCE code verifier
Personal Access Token (PAT)
Login with PAT
Authenticate directly with a GitHub Personal Access Token.- Trimming whitespace
- Removing
Bearerprefix (case-insensitive) - Removing
tokenprefix (case-insensitive) - Removing surrounding quotes
read:user- Read user profile informationrepo- Access repository data and stars
Auth Context
useAuth Hook
Access authentication state and methods from any component.Current GitHub access token, or
null if not authenticatedAuthentication method used to obtain the token
OAuth configuration with
clientId, redirectUri, and scopestrue if user has a valid access tokenStart the OAuth authorization flow (redirects to GitHub)
Process OAuth callback and exchange code for token
Authenticate with a Personal Access Token
Clear authentication state and local settings
Type Definitions
AuthMethod
OAuthCallbackInput
OAuthConfig
Security Features
PKCE (Proof Key for Code Exchange)
The OAuth flow implements PKCE to prevent authorization code interception:- Generate random
code_verifier(48 bytes, base64-url encoded) - Create
code_challenge= BASE64URL(SHA256(code_verifier)) - Send
code_challengewith authorization request - Send
code_verifierwith token exchange request - GitHub validates that SHA256(verifier) matches the challenge
CSRF Protection
Random state parameter prevents cross-site request forgery:- Generate random state (32 bytes)
- Store in
sessionStoragebefore redirect - GitHub includes state in callback URL
- Verify callback state matches stored value
Token Normalization
All tokens are normalized to prevent common input errors:- Strips whitespace
- Removes authentication scheme prefixes
- Removes quotes
- Validates non-empty result
Error Messages
| Error | Cause |
|---|---|
Missing VITE_GITHUB_CLIENT_ID | OAuth client ID not configured |
Missing VITE_GITHUB_OAUTH_EXCHANGE_URL | Exchange endpoint not configured |
OAuth session was not found | State/verifier missing from sessionStorage |
OAuth state mismatch | Callback state doesn’t match stored state |
OAuth token exchange failed (status) | HTTP error from exchange endpoint |
OAuth exchange did not return access_token | Invalid response format |
GitHub returned an OAuth error: {error} | GitHub rejected authorization |
Missing OAuth code/state in callback URL | Invalid callback parameters |
GitHub token is required | Empty or invalid PAT provided |
Environment Variables
GitHub OAuth application client ID
OAuth callback URL. Defaults to
${origin}/auth/callbackBackend endpoint for exchanging authorization code for access token