Overview
Nectr uses GitHub OAuth 2.0 for user authentication, followed by JWT tokens stored in HTTP-only cookies for session management.Authentication Flow
- User initiates GitHub OAuth flow via
/auth/github - GitHub redirects to
/auth/github/callbackwith authorization code - Nectr exchanges code for GitHub access token
- Server creates JWT and sets it as an HTTP-only cookie
- Subsequent requests automatically include the cookie for authentication
Required Scopes
Nectr requests the following GitHub OAuth scopes:repo: Full access to repositories (required for webhook management and code review)read:user: Read user profile datauser:email: Access user email address
Cookie-Based Authentication
After successful login, the API sets an HTTP-only cookie namedaccess_token:
Cookie Properties
- Name:
access_token - HttpOnly: Yes (prevents JavaScript access)
- Secure: Yes (production only, HTTPS required)
- SameSite:
None(production) /Lax(development) - Max-Age: 1440 minutes (24 hours, configurable via
ACCESS_TOKEN_EXPIRE_MINUTES)
CORS Configuration
The API allows credentials from these origins:Token Encryption
GitHub access tokens are encrypted at rest using Fernet symmetric encryption (derived fromSECRET_KEY). If SECRET_KEY changes, all stored tokens become invalid and users must re-authenticate.
Protected Endpoints
Most API endpoints require authentication. Protected endpoints use theget_current_user dependency, which:
- Extracts JWT from the
access_tokencookie - Validates the token signature and expiration
- Loads the user from the database
- Returns 401 if authentication fails
Example: Authenticated Request
Session Expiration
When a token expires or becomes invalid, the API returns:/auth/github to re-authenticate.
Security Considerations
- No CSRF tokens: Using
SameSite=None+Securecookies provides CSRF protection - Token rotation: Tokens are refreshed on each GitHub re-authentication
- Webhook signatures: All GitHub webhooks are verified using HMAC-SHA256
- State parameter: OAuth flow uses cryptographically random state to prevent CSRF