How Keycloak adds Google sign-in for your users
If you want staff or customers to sign in with Google accounts while keeping realms, roles and sessions under your control, the supported method is Keycloak's Google social provider, which is an OIDC-based identity provider configured inside a realm. The work centers on three things: an OAuth client that you register with Google, a domain restriction that limits sign-in to your Workspace domain, and a linking rule that decides how a Google identity maps to an account Keycloak already holds. Each of these is a configuration decision you own, and each one determines who can get into which applications.
Google sign-in is not the same as Google Workspace administration. The provider only proves that a person controls a Google account and returns claims about it to Keycloak. Keycloak still decides whether that person may enter a realm, which roles and groups apply, how long the session lasts and when it ends. Your Workspace admin still controls who has an account, whether accounts are suspended, and which Google services a user can reach. Before the build starts, agree which team owns each of those decisions, because a suspended Workspace account will not stop an existing Keycloak session on its own.
Ask your team to confirm three points in the Google Cloud console and in the Keycloak administration guide before scheduling work: which consent screen audience and OAuth client type your Workspace setup requires, which claims the provider returns in your Keycloak version, and whether the Google provider's domain and email verification settings match your policy. The Keycloak server administration guide documents the social provider settings. Treat any domain restriction you configure as an entry check only, and test it with accounts from outside your domain before you rely on it.
What you need before configuring Google in Keycloak
Google sign-in through Keycloak depends on four things lining up: a Keycloak instance you can change, a public HTTPS address Google can redirect to, a Google Cloud OAuth client, and a Workspace domain that a super admin can confirm. Check each one before you touch the identity provider settings, because most delays come from access and domain ownership rather than from Keycloak itself.
A supported Keycloak instance
Confirm you have a running Keycloak on a supported release. The current release is 26.8.1, so plan against that line and confirm your version against the upgrade notes before you start. Check that you have realm administrator rights in the target realm, and that you can test changes in a non-production realm first. A Google provider added to a realm that real users depend on can change how their logins behave.
Keycloak docsA public HTTPS redirect address
Google returns the user to Keycloak's broker endpoint after sign-in, so the Keycloak hostname must be reachable from the public internet over TLS with a certificate that browsers trust. Keycloak's production guidance expects TLS on all communication and a reverse proxy in front of the server. Confirm the frontend URL you will register with Google matches the hostname users see, and keep the admin console on a separate hostname or path.
Production guideGoogle Cloud project and OAuth client
Someone with administrator access to a Google Cloud project must create an OAuth 2.0 client for web application use and record its client ID and secret. Decide who owns that project and who can rotate the secret, because Keycloak stores the secret and every sign-in depends on it. Confirm the OAuth consent screen is configured for your Workspace users and that its user type and publishing status match who you intend to admit.
Workspace super admin confirmation
A Google Workspace super admin or owner must confirm that the domain you plan to restrict sign-in to is the primary domain and is verified for the organization. Without that confirmation, the domain restriction you configure in Keycloak can admit accounts you did not intend to trust. Ask the admin to confirm which additional domains belong to the organization, since aliases and secondary domains affect the restriction.
Console checks and current Google policy
Verify the consent screen settings and domain ownership in Google's console yourself, rather than relying on how a previous setup looked. Google changes its OAuth verification, scope and policy requirements over time, so check the current rules for OAuth clients and Workspace domains before go-live. Record who performed each check and the date, because an auditor or security reviewer will ask for that evidence later.
A test account and rollback plan
Prepare at least one Workspace test account and one existing Keycloak account that you can use to check linking behavior. Decide how you will keep password login available while Google is being tested, and who can disable the Google provider if sign-in misbehaves. Plan the rollback in writing before the first login attempt, so a broken mapper or redirect does not lock administrators out of the realm.
Configure the Google identity provider step by step
This sequence connects Keycloak to a Google OAuth client, limits sign-in to one Workspace domain, and sets how existing Keycloak accounts are linked. It finishes with tests from a Workspace account and an outside-domain account, so you can confirm both the allowed and the rejected paths before users rely on it.
Create the OAuth client in Google Cloud
A Google Cloud administrator selects or creates a project, configures the OAuth consent screen, and creates an OAuth 2.0 client ID of the web application type. For a Workspace-only setup, confirm in the current Google console whether the internal user type is available for your organization. Store the client ID and client secret in your secrets manager, not in tickets or chat. Done when the client appears under the project's credentials with its client ID.
Register the Keycloak redirect URI
In the same Google client, add an authorized redirect URI made from your public Keycloak base URL, then the realm path, then the Google broker endpoint for the realm. The value must match exactly, including scheme, host and path, and Keycloak must be reachable at that public hostname over TLS. Done when the URI is listed in the client and matches the redirect URI shown on the Keycloak provider page in the next step.
Add Google as an identity provider in the realm
In the Keycloak admin console, open the target realm, go to Identity providers, and select Google from the social providers. Keep the default alias unless you have a reason to change it, because the redirect URI in the previous step depends on it. Save the provider before editing other settings. Consult the Keycloak server administration guide for the options in your version. Done when Google appears in the provider list and its redirect URI matches the one registered with Google.
Enter the client ID and client secret
Paste the client ID and client secret from the Google client into the provider settings, make sure the provider is enabled, and save. Keep the secret out of exported realm files that you share. Open a private browser window and start a login for a test application in the realm, then choose Google. Done when the Google sign-in page loads and shows your OAuth client's name, with no redirect URI or client error.
Restrict sign-in with the hosted domain setting
Enter your primary Workspace domain in the hosted domain field of the Google provider and save. This asks Google to limit the account picker to accounts from that domain, but the setting alone does not prove that a returned account belongs to the domain. Check how your Keycloak version applies the value, and add an explicit check on the returned domain claim or email address in the first broker login flow if needed. Done when the provider settings show the domain and the check is in place.
Set first login account linking
Open the first broker login flow used by the Google provider and decide how an incoming Google identity matches an existing Keycloak user. Require the user to confirm a link to an existing local account with its password or a second factor, rather than merging silently. Only use email matching when Google reports the address as verified. Done when a test user with the same email as an existing Keycloak account is prompted to link, and no account is merged without confirmation.
Test with Workspace and outside-domain accounts
From separate private browser windows, sign in with a Workspace account on the allowed domain and then with an account from another domain, such as a personal mail account. The Workspace account should complete sign-in and show a Google link under the user's identity provider links. The outside-domain account should be rejected before access is granted. Repeat both tests after each change to the provider or the login flow, and keep the results with your change record.
How domain restriction and verified email decide who gets in
This model admits only people with accounts in one Google Workspace domain, such as a workforce realm for employees. Access depends on two checks working together: Google must return a hosted domain claim (hd) that matches your domain, and Keycloak must refuse any login whose email address falls outside that domain. Treat the Google side as the first gate and the Keycloak side as the one you control and can audit.
- Hosted domain restriction: Set the allowed hosted domain on the Google identity provider in Keycloak so that accounts from other domains, including personal Gmail accounts, are rejected at sign-in.
- Keycloak-side enforcement: Add a check in Keycloak, such as a first-broker-login or post-login control, that confirms the email domain before a user account is created or linked.
- Consumer accounts: Confirm that a personal Google account cannot reach the realm by testing with one, because a missing domain check is the most common gap.
- Account creation: Decide whether first login should create local accounts automatically or require an administrator to approve them.
- Account lifecycle: Plan how disabled Workspace accounts are removed from Keycloak, since a deleted Google account does not automatically disable the linked Keycloak user.
Before go-live, check the current option names for the hosted domain setting and the post-login controls in the Keycloak server administration guide, because the exact labels can change between releases.
This model lets customers, contractors or community members sign in with consumer Google accounts while staff sign in with Workspace accounts. The domain check cannot be the only control here, because it would block consumer accounts entirely. Instead, the realm or client has to decide which users get which role, and email verification becomes the main signal for any matching that uses email addresses.
- Separate routing: Use distinct identity provider settings or clients for consumer and Workspace access so that policy does not depend on one flag.
- Role assignment by domain: Map the hosted domain or email domain to groups or roles with identity provider mappers, so staff receive internal permissions and consumers receive limited ones.
- Verified email requirement: Reject or hold accounts where the email verified claim is false before they match any existing user by email.
- Lower trust for consumers: Keep consumer accounts out of administrative roles and sensitive applications unless a second factor or approval is added.
- Audit visibility: Record which provider and domain each user came through, so access reviews can separate the two populations.
Confirm with your own test accounts that the hosted domain claim is absent for consumer logins and present for Workspace logins, because the mapping rules depend on that difference.
In this model Google is one of several identity providers behind Keycloak, alongside a corporate directory, Microsoft Entra ID or local accounts. Keycloak becomes the policy point, and each provider contributes an identity that Keycloak evaluates. The domain check on Google matters less than making sure every provider path leads to the same decisions about who is allowed in and what they can do.
- Provider-specific trust: Set the trust level of each provider explicitly, since a Google account and a directory account do not carry the same assurance about the person behind them.
- Consistent linking rules: Use one rule for matching existing users by verified email across all providers, so that a Google login cannot take over an account created through another provider.
- Redirect control: Where users should not see a provider choice, configure the identity provider redirector so the right provider is used by default.
- Authorization in Keycloak: Keep roles and groups decided in Keycloak, not in the upstream provider, so that removing a provider does not silently change permissions.
- Fallback behavior: Decide what happens when Google is unavailable, and whether other providers or local accounts remain as a recovery path.
Review the account linking and first-login flow with a security engineer before enabling Google alongside other providers, because a permissive email match is the usual route for account takeover in this design.
Which Google claims map to Keycloak user attributes
This table maps each Google OpenID Connect claim to the Keycloak field or attribute it populates and notes whether the claim is used for matching, display or authorization. Read the matching rows first, because the email and sub choices decide whether an existing account is linked or a duplicate is created. Group membership is absent from the default sign-in token, so authorization based on Workspace groups needs a separate design.
| Google claim | Keycloak target | Primary use | Notes for the reader |
|---|---|---|---|
| sub | Identity provider user ID (federated identity link) | Matching | Stable Google account identifier. Use it as the durable link key, not the email address, which can change. |
| User email field | Matching and contact | Used by first-login linking when the account is verified. Confirm your first-login flow matches on email only when email_verified is true. | |
| email_verified | Review rule in first-login flow | Authorization gate | Reject or hold sign-in for unverified addresses before linking to any existing Keycloak account. |
| hd | Identity provider mapper or sign-in restriction | Authorization | Hosted domain claim for Workspace accounts. Check it against your allowed domain, and confirm that consumer Google accounts do not carry it. |
| given_name | User first name field | Display | Shown in account console and admin views. Can be overwritten on each login depending on your sync mode. |
| family_name | User last name field | Display | Same display role as given name. Confirm how your organization handles names that Google does not supply. |
| picture | User attribute (custom) | Display | Profile image URL. Store only if your applications need it, and review how long you keep a copied image. |
| Groups (not in default token) | Groups or roles via a separate integration | Authorization | Not included in the default sign-in token. Confirm with Google Workspace administrator APIs or a directory sync tool how group data would reach Keycloak. |
Linking Google identities to accounts that already exist
The central decision in this section is whether a Google sign-in may attach itself to an account that already exists in the realm, and under what conditions. Keycloak's identity provider settings include a first login flow that controls what happens when a user signs in through Google and Keycloak finds no linked identity. Automatic linking by email is convenient, but it is only safe when the email address Google asserts is verified and when the account it matches still belongs to the same person. Confirm in your Keycloak version how the first broker login flow handles an existing user with a matching email, and whether the verified-email check is enforced before linking happens, by testing it with a disposable account rather than relying on the default flow.
The main risk is account takeover through a reassigned or unverified address. A local account created years ago with a work email may still match a Google identity today if that mailbox was recycled, renamed, or created by someone outside your domain. Restrict automatic linking to Google identities from your Workspace domain, and require a confirmation screen where the user must re-authenticate to the existing account (with its password or another provider) before the link is stored. Block linking entirely for accounts with privileged roles, for accounts that have no second factor, and for any Google identity whose email domain is not in your approved list. Illustrative example: a contractor's former account with a personal address should never be linked silently to a new Workspace identity that happens to share a local part.
Users who already have a password or another provider need a clear path, and the choice affects support volume. If the existing account has a password, the confirmation step should ask for it, which proves the person controls that account before the Google identity is added. If the account is federated through another provider, such as a corporate directory, consider whether Google sign-in should be offered at all, since linking a second upstream source can create two login paths with different controls. Document the decision for each case, decide who approves exceptions, and record every link event in your audit trail so that a later review can show who linked what and when.
Security settings that keep Google sign-in from becoming a backdoor
A Google identity provider in Keycloak trusts another company's sign-in system, so a loose setting can let the wrong person into your realm. The cards below cover the credentials, redirect paths, domain and email checks, account linking and session scope that decide how much that trust is worth. Each one names a check to run before go-live and again after any change.
Client secret storage and rotation
The Google OAuth client secret lets Keycloak exchange authorization codes for tokens, so anyone holding it can impersonate your client. Store it in a secrets manager or an encrypted Kubernetes secret, never in realm exports checked into source control. Confirm who can read the identity provider configuration in the admin console, and set a rotation schedule with an owner. Test rotation in a non-production realm first, because a rotated secret that is not updated everywhere breaks all Google sign-in at once.
Keycloak production guideExact redirect URI matching
Google only returns the browser to redirect URIs registered on the OAuth client, so the list should contain only the Keycloak broker endpoint for each realm. Avoid wildcards, localhost entries and old staging hostnames, which widen the set of places an authorization code can be delivered. Confirm the registered URI matches the public frontend URL exactly, including scheme and path, and review the list whenever a hostname changes.
TLS on every endpoint
The broker callback, the token exchange and the admin console all carry sign-in data, so TLS must cover each hop, including the reverse proxy in front of Keycloak. Keycloak's production guidance expects TLS on all communication and recommends restricting which paths the reverse proxy exposes. Put the admin console and Administration REST API on a separate hostname or context path from public frontend URLs, so a public login page cannot reach administrative routes. Verify with an external scan that no plain HTTP listener answers on the public name.
Keycloak production guideHosted domain restriction
Without a restriction, any Google account, including a personal Gmail address, can complete the Google login. Set the hosted domain (hd) on the identity provider so Google only offers accounts from your Workspace domain, and treat that as a first filter rather than the only control. Keycloak should also reject any returned email whose domain does not match your allowed list. Test with an account from an unlisted domain and confirm the login fails before the user is created.
Verified email requirement
Google reports whether an email address has been verified, and Keycloak should refuse to trust an unverified address for account matching or user creation. If an unverified email is accepted, an attacker who controls a matching address could claim an existing local account on a later login. Confirm the identity provider is set to require verified email, and confirm the claim is present in the token Keycloak receives during a test login.
Limiting trust in account linking
First-login account linking decides which existing Keycloak user a Google identity attaches to, and it is the step most often abused. Keep the review step enabled so a user must confirm the link with their existing password or second factor, and avoid auto-linking by email alone for privileged accounts. Decide in advance which realm roles should never be reachable through a social login, and remove any default mapper that grants them to Google-created users.
Scope of Google-derived sessions
A session created through Google can reach every client that accepts it, so list which clients receive Google-derived sessions and why. Use client scopes and the identity provider redirector settings so only intended applications route to Google, and review administrative consoles separately. Record the owner of each client so that a Google-only app does not quietly become a path into a sensitive system.
Token and session lifetimes
Shorter access token lifetimes and session idle limits reduce how long a revoked Workspace account keeps access through Keycloak. Google's own token lifetime does not govern Keycloak's session, so set Keycloak values deliberately for each client and test what happens when a user is suspended in Google. Confirm that a disabled or deleted Workspace account cannot refresh a Keycloak session after the configured window, and document the values with the owner of each application.
Common Google sign-in failures and how to fix them
This table pairs each common failure in Google and Google Workspace sign-in through Keycloak with its most likely cause and the fix to try first. Read it as a triage list: match the symptom your users report, check the cause in the Google Cloud console or the Keycloak realm, and confirm the fix in a test realm before changing production.
| Failure | Likely cause | Fix |
|---|---|---|
| Redirect URI mismatch error from Google | The redirect URI registered on the Google OAuth client does not exactly match the Keycloak broker callback URL, including scheme, host, port or trailing path. | Copy the broker redirect URI shown on the Google identity provider settings in Keycloak and register it exactly in the Google OAuth client's authorized redirect URIs. |
| Users blocked by consent screen or test user restrictions | The OAuth consent screen is set to External with publishing status Testing, so only listed test users can sign in. | Publish the app or add the affected accounts as test users, and confirm the consent screen user type matches who must sign in. Check the scopes requested against what the consent screen declares. |
| Valid Workspace users rejected by hosted domain check | The hd parameter or the Hosted domain setting restricts sign-in to one domain, but the user's account uses an alias, a secondary domain or a different primary domain. | Confirm which domain the account's primary email belongs to, then set the Hosted domain value to the domain Google returns in the hd claim. Test with an account on each domain you intend to allow. |
| Account linking blocked for unverified email | Keycloak only links an external identity to an existing account when the email is verified, and the Google email or the local account email is not marked verified. | Verify the email on the existing Keycloak account, or use the first broker login flow with a verified-email check rather than enabling automatic linking. Confirm the Google account reports a verified email. |
| Duplicate accounts for one person | The user has two emails (for example a primary address and an alias or personal address), so Keycloak treats the Google login as a new user. | Link the Google identity to the existing account during first broker login, and decide in advance which address is the canonical identifier. Remove duplicates only after confirming which account holds the group and role assignments. |
| Login loop after redirect from Google | Keycloak sees the wrong frontend URL behind a reverse proxy, so the callback or session cookies do not match the external hostname. | Set the Keycloak hostname and proxy settings to the public frontend URL and forward the original host and protocol headers. Keep the admin console on a separate hostname or path, as the production guide advises. |
How a Google login flows through Keycloak
The login starts in the browser at the Keycloak login page, where the user picks Google as the identity provider. Keycloak redirects the browser to Google's authorization endpoint, and Google returns the user to the Keycloak callback with an authorization code that Keycloak exchanges for Google tokens. The trust boundary sits between Google and the Keycloak realm, so check the verified email claim and domain restriction before Keycloak accepts or links the account and issues its own tokens to the application.
Sign-in path from the browser through Google and back to Keycloak-issued tokens.
Questions buyers ask before setting up Google sign-in in Keycloak
What drives the cost of setting up Google sign-in in Keycloak?
The cost follows the written scope, and the main drivers are the number of realms that will accept Google sign-in, the linking rules for existing accounts, the domain restriction policy, and how much testing is required. A single realm with one Workspace domain and a clear linking rule is the smallest case. Each additional realm, domain or linking path adds configuration, mapper logic and test cases. Costs are one-time for the build and recur only if you buy ongoing support or retesting. Ask for a quote that lists each realm, each domain, each linking rule and the test accounts used to verify them.
How long does a Google sign-in project take in Keycloak?
Duration depends on the scope and on the state of your existing account data. A clean realm with no existing local accounts to link is faster to finish than one where thousands of users already exist under different email addresses, because the linking rules then need review against real data. Schedule time for the Google Cloud OAuth setup, which depends on your Workspace administrators, and for a test pass with real Workspace and personal Google accounts. Ask for a timeline tied to the written scope rather than a generic estimate.
What do we need from our side before the work starts?
You need administrative access to a Google Cloud project for creating the OAuth client, and access to Google Workspace admin settings so the domain restriction and any app access rules can be confirmed. You also need a decision on the linking policy, meaning whether existing Keycloak users may be linked to a Google identity by verified email and who approves that rule. Provide test accounts covering a Workspace user in the allowed domain, a Workspace user outside it, and a personal Google account, so each rule can be checked before go-live.
Can our internal team set up Google sign-in in Keycloak without a partner?
Yes, a team that already runs Keycloak can configure the Google social provider using the server administration guide. The harder parts are the decisions that shape security: restricting sign-in to your Workspace domain, deciding when a verified Google email may link to an existing account, and testing the failure paths. Those decisions affect account takeover risk, so they should be reviewed by someone who owns identity security. A partner is most useful when the team lacks Keycloak operations experience, needs the work documented as evidence for an audit, or wants the change tested before it reaches users.
How do we restrict Google sign-in to our Workspace domain?
Restricting sign-in to a Workspace domain is done by checking the hosted domain claim and the verified email address on each login, and by rejecting accounts that fail either check. Keycloak's Google provider settings and identity provider mappers are where this logic is configured, and the exact options depend on the Keycloak version you run, so confirm them against the server administration guide for that release. Personal Gmail accounts and accounts from other domains should be tested explicitly, because a permissive setting is the most common cause of unintended sign-ins.
What are the risks of linking Google identities to existing accounts?
The main risk is account takeover: if a Google identity is linked to an existing Keycloak user by email alone, anyone who controls that email in Google can reach the existing account. Limit linking to verified email addresses, decide whether linking requires the user to re-authenticate with their existing credentials, and log every link event. Review existing accounts for duplicate or stale email addresses before enabling linking. Confirm the first-login review flow with your security team, since it is the point where these rules are enforced.
Does the project need a formal audit or compliance review afterward?
DeployOpen prepares systems, configuration and evidence for compliance assessments, but it does not issue audit reports, attestations or certifications. Independent auditors and certification bodies perform those reviews. The evidence for Google sign-in usually includes the realm configuration, the domain restriction and linking rules, test results, and the change record. Ask your auditor which evidence they expect for federated sign-in and agree the format before testing begins.
How DeployOpen scopes and delivers Google sign-in for Keycloak
DeployOpen plans, builds, tests and documents Google and Google Workspace sign-in in Keycloak inside your own infrastructure. Each engagement starts with a written scope that names the Google accounts, Workspace domains and Keycloak realms in play, so the work and its deliverables are agreed before any configuration begins.
How we scope
- Confirm which Google Workspace domains and consumer Google sign-in paths are in scope for each realm
- Agree the Google Cloud project, OAuth client ownership and who holds administrative access to it
- Record how verified email, first-login linking and existing account matches will be handled, in writing
How we build
- Configure the Google identity provider in Keycloak with the agreed OAuth client, redirect URIs and scopes
- Restrict sign-in to approved Workspace domains and test that accounts outside them are refused
- Test account linking for existing users, including conflicting email addresses and unverified Google emails
How we hand over
- Deliver the realm configuration, identity provider settings and mapper definitions with a change record
- Provide a test plan and results covering allowed domains, blocked accounts and linking outcomes
- Document operator steps for rotating the OAuth client secret and for disabling Google sign-in safely
How we support
- Offer ongoing support, upgrades and continuous testing as retainers after handover
- Review Keycloak upgrade notes and Google-side changes against the agreed configuration
- Retest sign-in paths after each Keycloak upgrade or change to Google OAuth settings

