Continue with Google
Authenticates or registers a user using Google OAuth, returning available roles for the account.
Request Body
Google ID token obtained from Google Sign-In client library
Response
Unique identifier for the user account
User’s email address from Google account
List of roles assigned to this account (e.g., [“Customer”])
Response Codes
200 OK - Authentication successful
400 Bad Request - Invalid or expired Google token
403 Forbidden - Account disabled
404 Not Found - Account-related error
409 Conflict - Email conflict (rare)
500 Internal Server Error - Server error
Examples
curl -X POST "https://your-server.com/api/account/customer/google" \
-H "Content-Type: application/json" \
-d '{
"idToken": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjI3MGU..."
}'
Success Response Example
{
"accountId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"email": "[email protected]",
"roles": ["Customer"]
}
Error Response Examples
Invalid Google Token (400 Bad Request):
Email Conflict (409 Conflict):
"An account with this email already exists with password authentication"
Google Sign-In Integration
Client-Side Setup
Before calling this endpoint, you need to integrate Google Sign-In on your client:
Configure Google OAuth
Set up Google OAuth in Google Cloud Console and obtain a Client ID
Implement Google Sign-In
Use Google Sign-In library to authenticate users and obtain ID token
Send ID Token
Send the ID token to this endpoint to authenticate with your server
Get Role Token
Use the returned accountId to get a JWT token via /api/account/token
JavaScript Example with Google Sign-In
// Load Google Sign-In library
google.accounts.id.initialize({
client_id: 'YOUR_GOOGLE_CLIENT_ID',
callback: handleGoogleSignIn
});
async function handleGoogleSignIn(response) {
const idToken = response.credential;
// Send to server
const serverResponse = await fetch('https://your-server.com/api/account/customer/google', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ idToken })
});
const userRoles = await serverResponse.json();
// Now get a JWT token for Customer role
const tokenResponse = await fetch('https://your-server.com/api/account/token', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
accountId: userRoles.accountId,
role: 'Customer'
})
});
const jwtToken = await tokenResponse.json();
// Store jwtToken for authenticated requests
}
Behavior Notes
If the Google account email doesn’t exist in the system, a new customer account is automatically created.
The Google ID token must be valid and issued to your configured Google Client ID. Expired or invalid tokens will be rejected.
Configuration
Server configuration requires setting the GOOGLE_CLIENT_ID environment variable:
GOOGLE_CLIENT_ID=your-google-oauth-client-id.apps.googleusercontent.com
Next Steps
After Google authentication:
- Receive account information and available roles
- Call
/api/account/token to get a JWT token for the desired role
- Use the JWT token for authenticated API requests