-
Notifications
You must be signed in to change notification settings - Fork 10
Authentication: OAuth support and refresh #731
Description
Is your feature request related to a problem?
Current authentication methods are limited to username/password and API keys, without support for OAuth-based login or token refresh. Users must manually re-authenticate when JWTs expire, leading to a poor user experience.
Describe the solution you'd like
-
Implement
POST /api/v1/auth/googleto verify Google ID tokens and issue a JWT access token + refresh token as HTTP-only cookies.- Auto-embed org/project in JWT for single org/project users.
- Include
requires_project_selection: truefor multiple org/project users with anavailable_projectslist. - Issue a user-only JWT for users without org/projects.
-
Add
POST /api/v1/auth/select-projectto allow multi-project users to select aproject_idfor a new JWT pair. -
Introduce
POST /api/v1/auth/refreshto validate and issue new access + refresh tokens using therefresh_tokencookie. -
Implement
POST /api/v1/auth/logoutto clear access_token and refresh_token cookies. -
Update
get_auth_contextto support three auth methods by priority:X-API-KEYheaderAuthorization: Bearer <token>header- access_token cookie (new)
Ensure JWT tokens populate AuthContext with org_id and project_id, matching API key auth behavior, and reject refresh tokens on regular API calls.
Add User in corresponding to org/project
- Need to create the API Endpoint where superadmin can add the more user in the corresponding to Org/Project.
- Create the one table where we have the mapping of user corresponding to their org and project for tracking.
- Mark the user active after google login and when super admin add the new user in corresponding to any project then mark the user active false.
Original issue
Describe the current behavior
Authentication is currently supported via two methods:
- Username/password login (
POST /api/v1/login/access-token): returns a JWT access token - API Key (
X-API-KEYheader): used for programmatic access, embeds user + organization + project context
The frontend relies on API keys for accessing project-scoped endpoints. There is no OAuth-based login, no cookie-based session management, and no token refresh mechanism, when a JWT expires, the user must re-authenticate manually.
Describe the enhancement you'd like
-
POST /api/v1/auth/google- Accepts a Google ID token from the frontend, verifies it via google.oauth2.id_token, looks up the user by email, and issues a JWT access token + refresh token as HTTP-only cookies.- If the user has exactly 1 org/project (via API key records), it is auto-embedded in the JWT — making it work identically to API key auth.
- If the user has multiple org/projects, the response includes
requires_project_selection: truewithavailable_projectslist. - If the user has no org/projects, a user-only JWT is issued.
-
POST /api/v1/auth/select-project- For multi-project users, accepts aproject_idand issues a new JWT pair with the selected org/project embedded. -
POST /api/v1/auth/refresh- Reads therefresh_tokencookie, validates it, and issues a new access + refresh token pair. This allows silent re-authentication without requiring the user to log in again. -
POST /api/v1/auth/logout— Clears both access_token and refresh_token cookies. -
Updated auth dependency (
get_auth_context) — Now supports three auth methods in priority order:X-API-KEYheader (existing)Authorization: Bearer <token>header (existing)- access_token cookie (new)
JWT tokens with org_id and project_id claims now populate AuthContext with organization and project, matching the behavior of API key auth. Refresh tokens are rejected on normal API calls.