Connect Google Workspace to Keycloak
Let your Google Workspace users sign in to your Keycloak realm, limited to your own domain, and learn how to bring Google groups along.
Users choose Google on your Keycloak login page and sign in with their Google Workspace account. Keycloak's built-in Google provider uses OpenID Connect and can be limited to your Workspace domain. Google's OpenID Connect sign-in does not send group membership; if you need groups, the last part of this page sets up Google Workspace as a SAML app instead.
Checked against the Google Cloud and Google Workspace Admin Help docs and Keycloak 26.8 on 25 November 2026.
Replace auth.example.com with your RealmDeploy hostname, acme with your realm and example.com with your Workspace domain. The guide uses google as the identity provider alias, so the redirect URI is https://auth.example.com/realms/acme/broker/google/endpoint.
Keycloak calls Google from your tenant: it redeems the login code at oauth2.googleapis.com, downloads Google's signing keys from www.googleapis.com and reads the profile from openidconnect.googleapis.com, all on port 443. Outgoing connections from your tenant are closed by default. Tell us these hosts through How to reach us before you test, and we open them.
In Google Cloud
Use a Google Cloud project that belongs to your Workspace organization, so you can make the app internal.
- In the Google Cloud console, open Google Auth Platform. If the project has no app registered yet, register it and enter the app name and support details.
- Under Audience, set User type to Internal. Only members of your organization can then authorize the app; anyone else gets an
org_internalerror. - Open Clients and choose Create client.
- Set Application type to Web application and enter a name.
- Under Authorized redirect URIs, add
https://auth.example.com/realms/acme/broker/google/endpoint. - Choose Create and copy the Client ID and Client secret. Google shows the secret only when the client is created.
Google says changes to these settings can take from 5 minutes to a few hours to apply. Google also deletes OAuth clients that have not been used for six months, after an email warning.
In Keycloak
- Open Identity providers and choose Google (from the list, or under Add provider).
- Check that Redirect URI matches the one you entered in Google, paste the Client ID and Client Secret, and choose Add.
- On the provider's settings, set these and choose Save:
| Setting | Value |
|---|---|
| Hosted Domain | example.com. Several domains are separated by commas. |
| Scopes (under Advanced settings) | Leave empty for the default openid profile email |
| Trust Email (under Advanced settings) | On. Google sends email_verified with the email, and Keycloak follows it: an address Google does not mark as verified stays unverified. |
| Sync mode (under Advanced settings) | Force, if you want name changes in Google to reach Keycloak at each login |
Hosted Domain does two things. Keycloak sends Google's hd parameter, which streamlines the Google sign-in for accounts of that domain. And Keycloak checks the hd claim in the ID token and refuses the login when it does not match: the user sees Unexpected error when authenticating with identity provider. That second check is what keeps other Google accounts out: Google warns that the hd parameter alone is a convenience that a user can remove from the request.
Groups and roles
Google's ID token has no groups claim, and Keycloak cannot read Google groups over OpenID Connect without an extension. Extensions cannot be installed on your tenant. Your options:
| Option | How |
|---|---|
| Assign groups in Keycloak | After a user's first login, add them to groups under Users → Groups, or use a group that you manage only in Keycloak. |
| Put everyone from Google in one group | On the provider's Mappers tab, add a Hardcoded Group mapper. Every user who signs in with Google joins that group. |
| Send Google groups over SAML | Set Google Workspace up as a SAML app with Group membership, as described below. Google sends up to 75 chosen groups. |
Whichever you choose, your apps see the groups in Keycloak's tokens once their client has a Group Membership mapper (Client scopes → <client-id>-dedicated → Configure a new mapper).
To store more Google profile fields on the user, add an Attribute Importer mapper with a Social Profile JSON Field Path (for example locale) and a User Attribute Name.
Test it
- In a private browser window, open
https://auth.example.com/realms/acme/accountand choose Google. - Sign in with a Workspace account. You come back to the account console, signed in.
- Try a personal Google account. Google refuses it with
org_internalbecause the app is internal; if it got through, Keycloak would refuse it because itshdclaim does not match. - In the admin console, open Users and check the new user and its Identity provider links tab.
Common errors
| Error | Cause | Fix |
|---|---|---|
redirect_uri_mismatch from Google | The authorized redirect URI differs from the one Keycloak sends, or the change has not applied yet. | Copy the Redirect URI from Keycloak into the Google client and wait a few minutes. The redirect URI matcher shows the difference. |
org_internal from Google | The user is not in your Workspace organization and the app is internal. | Expected for outside accounts. |
Keycloak shows Unexpected error when authenticating with identity provider after the Google sign-in | The outgoing connections to Google are not open yet, the secret is wrong, or the account's domain is not in Hosted Domain. | Tell us the hosts through How to reach us. Check the secret and the domain list (for a typo too). |
| Account already exists page | A Keycloak user with the same email already exists. | The user links the accounts by proving they own the existing one. |
Groups over SAML
Google Workspace can act as a SAML identity provider for a custom app and send the groups a user belongs to. You need a super administrator in the Google Admin console. Use the alias google-saml for this provider.
In the Google Admin console
- Go to Apps → Web and mobile apps, choose Add app → Add custom SAML app, enter a name and continue.
- On Google Identity Provider details, download the IdP metadata and continue.
- On Service provider details, enter:
| Field | Value |
|---|---|
| ACS URL | https://auth.example.com/realms/acme/broker/google-saml/endpoint |
| Entity ID | https://auth.example.com/realms/acme |
| Signed response | Leave unchecked. Google then signs the assertion only. |
| Name ID format | EMAIL |
| Name ID | Leave the default, the user's primary email |
- Under Attribute mapping, choose Add mapping and map the user's primary email to
email, first name tofirstNameand last name tolastName. - Under Group membership (optional), search for each group to send and set App attribute to
groups. Google sends only the groups among these that the user belongs to, directly or through another group, up to 75 groups. - Choose Finish, then open the app's User access, choose On for everyone (or turn it on for an organizational unit or group) and save. Google says this can take up to 24 hours, usually less.
In Keycloak
- Open Identity providers and choose SAML v2.0.
- Set Alias to
google-samland Display name toGoogle. Leave Service provider entity ID onhttps://auth.example.com/realms/acme. - Turn Use entity descriptor off and use Import config from file with the metadata you downloaded from Google. Choose Add.
- On the settings, check: NameID policy format Email, Principal type Subject NameID, Want Assertions signed On, Validate Signatures On, Use metadata descriptor URL Off. Choose Save.
- On Mappers, add an Attribute Importer for each of
email,firstNameandlastName(Attribute Name as you typed it in Google, User Attribute Name the same), and one Advanced Attribute to Group mapper per group with the keygroupsand the group's value as Google sends it.
Imported from a file, this provider needs no outgoing connection: Google posts the assertion through the browser, and Keycloak checks it with the certificate from the file. When Google's certificate changes, import the new metadata. To see the exact group values Google sends, capture the SAMLResponse in your browser's developer tools and paste it into the SAML response decoder.
FAQ
Can I limit sign-in to some users of my domain, not all?
With OpenID Connect, everyone in the domain who can use Google can sign in; control access in your apps with Keycloak groups or roles. With the SAML app, turn the app on only for an organizational unit or a group in User access.
Should I use the Google provider or the generic OpenID Connect v1.0 provider?
Use the built-in Google provider. It sets Google's endpoints and keys and checks the hd claim when Hosted Domain is set; the generic provider does not check hd by itself.
Can users skip the Keycloak login page?
Yes. Add kc_idp_hint=google to the app's login request; the identity provider redirect builder writes the URL. Or make google the default identity provider in the browser flow's Identity Provider Redirector.
Sources
- Keycloak Server Administration Guide: Google, SAML v2.0 identity providers and mappers
- Keycloak source 26.8.1: GoogleIdentityProvider (endpoints,
hdcheck) - Google: Manage OAuth clients
- Google: Manage app audience
- Google: OpenID Connect (
hdparameter and claim, ID token claims) - Google discovery document
- Google Workspace Admin Help: Set up your own custom SAML app
Connect Microsoft Entra ID to Keycloak (SAML)
Broker Microsoft Entra ID logins into your Keycloak realm over SAML 2.0 with a non-gallery enterprise app, signed assertions and Entra groups mapped to Keycloak groups.
Connect Okta to Keycloak
Broker Okta logins into your Keycloak realm over OpenID Connect, with Okta's groups claim mapped to Keycloak groups.