Create OAuth 2.0 Credentials in Google Cloud Console¶
- Go to the Google Cloud Console
- If you don't have a project already, create a new one.
- Select
APIs & Services - Navigate to the
CredentialsSection -
Create OAuth 2.0 Client ID:
- For
Application type, selectWeb application - Provide a name for the OAuth client (e.g.,
Virtomat Realm). - Under
Authorized JavaScript origins, add your Keycloak domain:https://auth.virtomat.dev - Under
Authorized redirect URIs, add the following URI:https://auth.virtomat.dev/realms/virtomat/broker/google/endpoint
- For
-
Obtain
Client IDandSecret
Note
Once you created the credentials, Google will provide you with a Client ID and Client Secret.
These are the keys you'll need to configure Google as an identity provider in Keycloak.
Configure Keycloak to Use Google as an Identity Provider¶
- Access Keycloak Admin Console
https://auth.virtomat.dev/admin/ - Select the Realm
virtomat - Select
Identity Providerson the left side menu - Add Google as an Identity Provider (use
Client IDandSecretobtained from Google Cloud Console) - Before saving, scroll down to Advanced Settings and configure:
- Scopes:
openid profile email - Default sync mode:
import
- Scopes:
- Save the Configuration
Note
The profile scope is required to import user profile information including the picture from Google.
The default scope is only openid, which is insufficient for profile data import.
The import sync mode ensures user core data (name, email) is only set on first login, maintaining stability.
Configure Google Profile Picture Import¶
To enable importing and using the Google profile picture in your application, follow these steps:
Step 1: Create Picture Attribute in User Profile¶
- In Keycloak Admin Console, go to realm
virtomat - Navigate to Realm settings → User profile tab
- Click Create attribute
- Configure the attribute:
- Attribute name:
picture - Display name:
Profile Picture - Required field:
No(OFF)
- Attribute name:
- Click Create
Step 2: Create Identity Provider Mapper¶
- Navigate to Identity providers in the left menu
- Click on google
- Go to the Mappers tab
- Click Add mapper
- Configure the mapper:
- Name:
google-picture-importer - Sync mode override:
force - Mapper type:
Attribute Importer - Social Profile JSON Field Path:
picture - User Attribute Name:
picture
- Name:
- Click Save
Note
The force sync mode for the picture mapper ensures the profile picture URL is updated on every login,
allowing users to see their latest Google profile picture even if they change it later.
Step 3: Create Client Mapper¶
- Navigate to Clients in the left menu
- Click on voyager client
- Go to the Client scopes tab
- Click on voyager-dedicated scope
- Go to the Mappers tab
- Click Configure a new mapper
- Select User Attribute as the mapper type
- Configure the mapper:
- Name:
picture - User Attribute:
picture - Token Claim Name:
picture - Claim JSON Type:
String - Add to ID token:
ON - Add to access token:
ON - Add to userinfo:
ON
- Name:
- Click Save
Verify Configuration¶
- Open a private/incognito browser window
- Go to
https://auth.virtomat.dev/realms/virtomat/account - Log in using Google
- Check Personal info section to verify the Picture field contains your Google profile picture URL