GCP Login Flow
The GCP login endpoint initiates an OAuth 2.0 authorization flow with Google accounts. Upon successful authentication, the user is redirected to the dashboard with an active session containing GCP account details and access tokens.Authentication Endpoint
Response
Redirects to Google OAuth authorization page with the following parameters:Query Parameters (Auto-generated)
Google OAuth client ID from environment configuration
Callback URL configured in environment:
GOOGLE_REDIRECT_URIAlways “code” for authorization code flow
Requested permissions:
openid- OpenID Connect authenticationemail- User’s email addressprofile- User’s basic profile infohttps://www.googleapis.com/auth/cloud-platform- Full GCP access
Set to “offline” to receive refresh token
Set to “consent select_account” to force account selection and consent screen
Callback Endpoint
Query Parameters
Authorization code returned by Google OAuth
Response
Redirects tohttp://localhost:3000/dashboard after successful authentication.
Token Exchange Request
POST tohttps://oauth2.googleapis.com/token:
Authorization code from callback
Google OAuth client ID
Google OAuth client secret
Same redirect URI used in authorization request
Always “authorization_code”
Session Data Created
Google Cloud Platform access token for API calls
Array of connected cloud provider accounts
Always “gcp” for Google Cloud accounts
User’s Google email (unique identifier)
User’s display name from Google profile
GCP API access token
Refresh token for obtaining new access tokens (only provided on first authorization)
Error Responses
401 Unauthorized - Missing CodeAuthentication Flow Details
Step 1: Initiate Login
User navigates to/api/login/google, which redirects to Google OAuth authorization endpoint.
Step 2: User Authenticates
User selects Google account and grants permissions for:- OpenID authentication
- Email and profile access
- Full Google Cloud Platform access
Step 3: Callback Processing
Google redirects back to/google/callback with authorization code:
-
Exchange code for tokens via POST to Google’s token endpoint:
-
Verify ID token using Google’s verification library:
- Store user info and tokens in session
- Create GCP account object with email, display name, and tokens
-
Update session accounts:
- If account with same email exists, replace it (update tokens)
- Otherwise, append new account to list
-
Redirect to dashboard at
http://localhost:3000/dashboard
Account Management
The GCP authentication automatically manages accounts in the session: Duplicate Prevention: If a GCP account with the same email already exists, it will be updated with new tokens instead of creating a duplicate entry. Token Refresh: Access tokens expire after 1 hour. The refresh token can be used to obtain new access tokens without requiring the user to re-authenticate.Environment Configuration
The following environment variables must be configured:Google OAuth 2.0 client ID from Google Cloud Console
Google OAuth 2.0 client secret
OAuth callback URL (e.g.,
http://localhost:5000/google/callback)Code Reference
Implementation inbackend/auth/gcp_auth.py:15-84
Token Exchange: