Skip to main content

Add Google, GitHub and Apple Social Login to Keycloak

Keycloak ships Google and GitHub as built-in social identity providers: paste a client ID and secret, and the buttons appear on the login page. Apple is not built in. There is no apple provider in Keycloak 26.8.2 — you configure Sign in with Apple as a generic OIDC identity provider, and its client secret is an ES256-signed JWT that expires within six months and has to be regenerated on a schedule.

That asymmetry is the whole job. This tutorial gives you the tested kcadm.sh sequence for all three, the exact authorization request Keycloak builds for each, and the two Apple limits that will otherwise cost you an afternoon.

Does Keycloak support social login?​

Yes, for eleven providers out of the box. Ask the server rather than trusting a blog post — this is the authoritative list, read from a running Keycloak 26.8.2:

kcadm.sh get serverinfo -r master \
| jq -r '.socialProviders[].id' | sort
bitbucket
facebook
github
gitlab
google
linkedin-openid-connect
microsoft
openshift-v4
paypal
stackoverflow
twitter

Apple is absent from that list, and so is any Apple-specific provider. Anything else — Apple, Discord, Okta, Auth0, a partner's IdP — goes through the generic oidc or saml provider instead. That works, but you supply every endpoint yourself and you lose the provider-specific conveniences, which for Apple means you also take on secret rotation.

The three configurations at a glance​

GoogleGitHubApple
Keycloak providerIdgooglegithuboidc
Built inYesYesNo
Client secretStatic stringStatic stringES256 JWT, ≤6 months
Endpoints you supplyNoneNoneAll of them
Default scope Keycloak sendsopenid profile emailuser:emailopenid
Email arrives automaticallyYesYes, via a second API callOnly with a scope you cannot use — see below
Rotation workOn compromiseOn compromiseScheduled, forever

Prerequisites: a lab you can run​

docker rm -f kc 2>/dev/null
docker run -d --name kc --memory 1536m -p 127.0.0.1:8080:8080 \
-e KC_BOOTSTRAP_ADMIN_USERNAME=admin -e KC_BOOTSTRAP_ADMIN_PASSWORD=admin \
quay.io/keycloak/keycloak:26.8.2 start-dev

Give it about fifteen seconds, then authenticate kcadm.sh and make a realm to work in. For the rest of this page, kcadm.sh means the copy inside the container:

alias kcadm.sh='docker exec kc /opt/keycloak/bin/kcadm.sh'

kcadm.sh config credentials --server http://localhost:8080 \
--realm master --user admin --password admin
kcadm.sh create realms -s realm=social -s enabled=true

Get the redirect URI before you open any developer console​

Every provider asks for a callback URL, and all three reject a mismatch with an error that does not say "mismatch". Keycloak derives it from the realm and the alias you are about to choose:

{keycloak-base-url}/realms/{realm}/broker/{alias}/endpoint

So for alias google in realm social on a server at https://sso.example.com, it is https://sso.example.com/realms/social/broker/google/endpoint. Decide the alias first — it is in the URL, so renaming the provider later invalidates the registration at the provider.

One constraint worth knowing before you start: Apple will not accept an http:// redirect URI and will not accept localhost. Google and GitHub both allow http://localhost for development. You can build and test the Google and GitHub providers entirely on the lab server above; Apple needs a public HTTPS hostname before it will accept the registration.

Google​

On the Google side: Google Cloud console → APIs & Services → Credentials → Create credentials → OAuth client ID → Web application, and add the redirect URI to Authorized redirect URIs. You get a client ID ending in .apps.googleusercontent.com and a secret.

In Keycloak, Google needs exactly two values. Everything else Keycloak already knows:

kcadm.sh create identity-provider/instances -r social \
-s alias=google \
-s providerId=google \
-s enabled=true \
-s trustEmail=true \
-s 'config.clientId=YOUR_ID.apps.googleusercontent.com' \
-s 'config.clientSecret=YOUR_SECRET' \
-s 'config.syncMode=FORCE'

Read it back and note that Keycloak filled in the issuer itself:

kcadm.sh get identity-provider/instances/google -r social
{
"alias" : "google",
"providerId" : "google",
"enabled" : true,
"trustEmail" : true,
"config" : {
"clientSecret" : "**********",
"issuer" : "https://accounts.google.com",
"clientId" : "YOUR_ID.apps.googleusercontent.com",
"syncMode" : "FORCE"
}
}

trustEmail=true is the setting people miss. Without it, Keycloak sends its own verification email to an address Google has already verified, and your users get a confirmation step they cannot explain. Set it for Google. Think harder about it for GitHub, below.

syncMode=FORCE re-imports the profile on every login, so a name change at Google reaches Keycloak. The default, LEGACY, imports once at first login and never updates. Neither is wrong, but the default surprises people.

Restricting Google login to your own domain​

If the realm is for employees, hostedDomain stops personal Gmail accounts at the door:

kcadm.sh update identity-provider/instances/google -r social \
-s 'config.hostedDomain=example.com'

Keycloak forwards this as the hd parameter and validates the claim on the returned ID token, so it is a real restriction rather than a UI hint. Confirm it is actually on the wire rather than assuming — follow the provider's login link from the login page and inspect the redirect:

https://accounts.google.com/o/oauth2/v2/auth
scope = openid profile email
response_type = code
client_id = YOUR_ID.apps.googleusercontent.com
redirect_uri = https://sso.example.com/realms/social/broker/google/endpoint
hd = example.com

GitHub​

On the GitHub side: Settings → Developer settings → OAuth Apps → New OAuth App, and paste the redirect URI into Authorization callback URL. Copy the client secret immediately; GitHub will not show it again.

kcadm.sh create identity-provider/instances -r social \
-s alias=github \
-s providerId=github \
-s enabled=true \
-s 'config.clientId=Ov23liEXAMPLE' \
-s 'config.clientSecret=YOUR_SECRET' \
-s 'config.syncMode=FORCE'

Why GitHub email behaves differently, and what breaks it​

GitHub's OAuth user endpoint returns email: null when the user has set their email to private — which is the default for a large share of accounts. Keycloak works around this: the built-in provider requests the user:email scope and makes a second call to https://api.github.com/user/emails to find the primary address.

That second call is why the default scope matters more here than anywhere else. If you override defaultScope and drop user:email, the call fails and the login dies with one of two messages from Keycloak's own GitHub provider:

Primary email could not be retrieved from the github endpoint
Primary email from github is not found in the user's email list.

The fix is to leave defaultScope empty so Keycloak uses user:email, or to include user:email in whatever you set. Verify what is actually being sent rather than trusting the config — on a correctly configured provider the authorization request reads:

https://github.com/login/oauth/authorize
scope = user:email
response_type = code
client_id = Ov23liEXAMPLE
redirect_uri = https://sso.example.com/realms/social/broker/github/endpoint

Note what is not there: trustEmail. A GitHub primary email is confirmed by GitHub, but GitHub accounts are trivially self-registered and a GitHub login is a far weaker identity claim than a Google Workspace one. If this realm grants anything on the basis of email address, leave trustEmail off for GitHub and let Keycloak verify. That is a judgement call about your risk, not a Keycloak setting with a right answer.

GitHub Enterprise Server​

The same provider works against a self-hosted GitHub by overriding two URLs:

kcadm.sh update identity-provider/instances/github -r social \
-s 'config.baseUrl=https://github.example.com' \
-s 'config.apiUrl=https://github.example.com/api/v3' \
-s 'config.clientSecret=YOUR_SECRET'

baseUrl defaults to https://github.com and carries the authorize and token endpoints; apiUrl defaults to https://api.github.com and carries the profile and email lookups. Both must change together, and apiUrl on GitHub Enterprise Server ends in /api/v3.

Re-supplying config.clientSecret is not redundant. Omit it and Keycloak 26.8.2 rejects the whole update with exit code 1 and:

Client secret must be re-entered when the token URL, client ID, authentication method,
or related destination settings are changed

Because the secret is masked on read, you cannot round-trip a provider through get and update — any edit touching a destination setting has to carry the secret again. Edits to other fields are unaffected: hostedDomain on Google and defaultScope on the Apple provider below both update without it.

Apple​

This is the part the documentation skips, because Keycloak has no Apple provider to document.

Step 1: the four Apple identifiers​

In the Apple Developer portal you need all four, and they are created in different places:

ValueWhereLooks likeUsed as
Team IDMembership detailsABC123DEFGiss claim
Services IDIdentifiers → Services IDscom.example.loginclient_id and sub claim
Key IDKeys → new key, Sign in with Apple enabledDEF456HIJKkid header
Private keyDownloaded once with that keyAuthKey_DEF456HIJK.p8signs the JWT

The .p8 file downloads exactly once. Apple will not reissue it; losing it means creating a new key and a new Key ID.

Configure the Services ID with your domain and the Keycloak redirect URI. Apple calls these "Domains and Subdomains" and "Return URLs", and requires HTTPS for both.

Step 2: generate the client secret​

Apple does not issue a client secret. You sign one, using the .p8 key. Apple's own documentation is unambiguous about the constraint that matters:

It's an error to request an expiration time more than 15777000 seconds (six months) in the future, as measured by the clock on Apple's servers.

So this is a credential with a maximum six-month life, and nothing in Keycloak renews it.

# gen_apple_secret.py — pip install pyjwt cryptography
import sys, time, jwt

team_id, key_id, services_id, p8 = sys.argv[1:5]
now = int(time.time())
print(jwt.encode(
{"iss": team_id, "iat": now, "exp": now + 15552000, # 180d, under Apple's max
"aud": "https://appleid.apple.com", "sub": services_id},
open(p8).read(), algorithm="ES256", headers={"kid": key_id}))
python3 gen_apple_secret.py ABC123DEFG DEF456HIJK com.example.login AuthKey_DEF456HIJK.p8

Decode what you just produced before pasting it anywhere — a wrong kid or a sub that is the Team ID instead of the Services ID both fail at Apple as invalid_client, which tells you nothing:

{"alg": "ES256", "kid": "DEF456HIJK", "typ": "JWT"}
{"iss": "ABC123DEFG", "iat": 1796022656, "exp": 1811574656,
"aud": "https://appleid.apple.com", "sub": "com.example.login"}

The script uses 180 days rather than Apple's maximum deliberately: exp is checked against Apple's clock, so a secret generated at exactly 15777000 seconds can be rejected over a few seconds of skew. Leaving a margin costs nothing.

Put the renewal in a calendar or a cron job now, before you forget. The failure mode is that social login for every Apple user stops on a date six months from today, with no warning and no gradual degradation.

Step 3: create the provider​

Apple publishes a discovery document, which is where the endpoint values below come from:

curl -s https://appleid.apple.com/.well-known/openid-configuration | jq
{
"issuer": "https://appleid.apple.com",
"authorization_endpoint": "https://appleid.apple.com/auth/authorize",
"token_endpoint": "https://appleid.apple.com/auth/token",
"jwks_uri": "https://appleid.apple.com/auth/keys",
"response_modes_supported": ["query", "fragment", "form_post"],
"subject_types_supported": ["pairwise"],
"scopes_supported": ["openid", "email", "name"],
"token_endpoint_auth_methods_supported": ["client_secret_post"],
"claims_supported": ["aud", "email", "email_verified", "exp", "iat",
"is_private_email", "iss", "nonce", "nonce_supported",
"real_user_status", "sub", "transfer_sub"]
}

Two things in that document decide the configuration. token_endpoint_auth_methods_supported is client_secret_post only, so clientAuthMethod must be set — Apple rejects HTTP Basic. And claims_supported contains no name claims at all, which Step 5 returns to.

kcadm.sh create identity-provider/instances -r social \
-s alias=apple \
-s providerId=oidc \
-s enabled=true \
-s displayName="Sign in with Apple" \
-s trustEmail=true \
-s 'config.clientId=com.example.login' \
-s 'config.clientSecret=PASTE_THE_GENERATED_JWT' \
-s 'config.issuer=https://appleid.apple.com' \
-s 'config.authorizationUrl=https://appleid.apple.com/auth/authorize' \
-s 'config.tokenUrl=https://appleid.apple.com/auth/token' \
-s 'config.jwksUrl=https://appleid.apple.com/auth/keys' \
-s 'config.useJwksUrl=true' \
-s 'config.clientAuthMethod=client_secret_post' \
-s 'config.syncMode=IMPORT'

clientId is the Services ID, not the App ID. They look similar and are not interchangeable.

Step 4: leave the scopes alone — this is the one that bites​

Apple accepts name and email as scopes, and asking for them seems obviously correct. It breaks the login, and the reason is worth understanding because the error gives no hint.

Apple's authorization documentation states:

The type of response mode expected. Valid values are query, fragment, and form_post. If you requested any scopes, the value must be form_post.

form_post means Apple returns the authorization code by POSTing a form to your redirect URI instead of redirecting with query parameters. Keycloak's generic OIDC broker endpoint does not accept POST:

curl -s -o /dev/null -w "%{http_code}\n" -X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
--data "code=abc&state=def" \
http://127.0.0.1:8080/realms/social/broker/apple/endpoint
405

405 Method Not Allowed, because OIDCIdentityProvider$OIDCEndpoint in Keycloak 26.8.2 declares a @GET handler and no @POST one. This is not a configuration problem you can fix from the admin console.

It is also not something Keycloak warns you about. Setting defaultScope to openid email name produces a provider that looks correct and sends this:

https://appleid.apple.com/auth/authorize
scope = openid email name
response_type = code
client_id = com.example.login
redirect_uri = https://sso.example.com/realms/social/broker/apple/endpoint
nonce = x6qNAXJgWJkateOBUMpPWw

No response_mode. Apple requires form_post for that request and Keycloak has not sent it. Keycloak's OIDC provider has no response_mode setting — a config.responseMode key is accepted by the API and then silently ignored, which is a convincing way to waste an hour. forwardParameters will relay a response_mode from the original client request, but that only gets you to the 405 above faster.

So leave defaultScope empty or set it to openid. Both send scope=openid and nothing else, Apple uses its default query response mode, and the login completes:

kcadm.sh update identity-provider/instances/apple -r social \
-s 'config.defaultScope=openid'

Step 5: what you give up, stated plainly​

With scope=openid only, the ID token carries sub and — for most account configurations — email. It does not carry the user's name, and it never would have: Apple's claims_supported has no name, given_name or family_name. Apple delivers the name exactly once, in a separate user field in the form_post body on the user's first authorization:

{
"authorization": { "code": "...", "id_token": "...", "state": "..." },
"user": { "email": "...", "name": { "firstName": "...", "lastName": "..." } }
}

Keycloak's OIDC broker never sees that field, because it never receives a form post. Apple users will arrive with an empty first and last name, and no Keycloak setting changes this.

Plan for it rather than fighting it: let the first-broker-login flow's Review Profile step collect the name, which it does by default, or accept blank names and prompt in your application. If you genuinely need Apple's one-shot name, you need a custom identity provider SPI with a POST endpoint, which is a different piece of work from configuring a provider.

Two more Apple behaviours to design around:

  • subject_types_supported is pairwise. The sub is derived from the Services ID, so changing the Services ID gives every existing user a new sub and Keycloak stops matching them to their accounts. Treat the Services ID as permanent.
  • Private relay addresses. Users may choose to hide their email, in which case you get a working @privaterelay.appleid.com forwarding address and is_private_email is true. Mail to it only delivers if you have registered your sending domain with Apple.

Verify it worked​

With all three providers created, the login page renders all three buttons. You need some client to render a login page for, so make a throwaway one:

kcadm.sh create clients -r social \
-s clientId=demo-app -s enabled=true -s publicClient=true \
-s 'redirectUris=["http://localhost:3000/*"]'

Then check for the buttons rather than taking a screenshot's word for it:

curl -s "http://127.0.0.1:8080/realms/social/protocol/openid-connect/auth\
?client_id=demo-app&response_type=code&scope=openid\
&redirect_uri=http://localhost:3000/cb" \
| grep -oE 'id="social-[a-z]+"'
id="social-apple"
id="social-github"
id="social-google"

Then confirm each provider's stored configuration is what you believe it is. The secret is masked on read, so this checks everything except the one value you cannot check:

for a in google github apple; do
echo "--- $a"
kcadm.sh get identity-provider/instances/$a -r social \
| jq '{providerId, enabled, trustEmail,
scope: .config.defaultScope, authMethod: .config.clientAuthMethod}'
done

For Apple specifically, check the secret has not quietly expired. This decodes the stored JWT locally without calling Apple:

python3 - <<'EOF'
import base64, json, time
secret = input("paste the Apple client secret JWT: ").strip()
p = json.loads(base64.urlsafe_b64decode(
secret.split('.')[1] + '=' * (-len(secret.split('.')[1]) % 4)))
days = (p['exp'] - time.time()) / 86400
print(f"sub={p['sub']} iss={p['iss']} expires in {days:.1f} days")
EOF

A negative or small number there is your warning. Nothing else in the stack will give you one.

Troubleshooting​

What you seeCause
invalid_client from Applesub is the Team ID instead of the Services ID, wrong kid, or the secret has passed exp
Apple login worked for months, then stopped for everyone at onceThe client secret hit its six-month expiry
redirect_uri_mismatchThe alias in the registered URI no longer matches the provider alias, or you registered http:// where Apple needs https://
Primary email could not be retrieved from the github endpointdefaultScope was overridden and no longer includes user:email
Apple users have blank namesExpected. Apple sends the name only in a form_post body Keycloak cannot receive
Account already exists on the login pageA local account already has that email address. Keycloak's first-broker-login flow is offering to link them — see below
Profile changes at the provider never reach KeycloaksyncMode is LEGACY, which imports once and never again. Set FORCE

"Account already exists" is the one you will hit in production​

Enable three social providers and the same person will eventually sign in with two of them. Because duplicateEmailsAllowed is false by default, the second login cannot create a second account, so Keycloak's first broker login flow intercepts it. Inspect what that flow actually does before you decide whether to change it:

kcadm.sh get 'authentication/flows/first%20broker%20login/executions' -r social \
| jq -r '.[] | "\(.level) \(.displayName) [\(.requirement)]"'

On a default realm the relevant branch is:

0 Review Profile [REQUIRED]
0 User creation or linking [REQUIRED]
1 Create User If Unique [ALTERNATIVE]
1 Handle Existing Account [ALTERNATIVE]
2 Confirm link existing account [REQUIRED]
2 Account verification options [REQUIRED]
3 Verify existing account by Email [ALTERNATIVE]
3 Verify Existing Account by Re-authentication [ALTERNATIVE]

The level column is the nesting depth, so the two ALTERNATIVE entries at level 1 are the branch: create a new user, or handle the account that already exists.

So the user sees a page headed Account already exists with an Add to existing account button, and then has to prove they own the original account — by email, or by entering its password. That is correct behaviour and you should generally leave it alone.

The trap is Verify existing account by Email, which needs working SMTP. On a realm with no SMTP configured, a user who signs in with GitHub having previously registered with Google reaches the linking page and then cannot get past it. Configure SMTP before enabling a second social provider, or disable the email option and leave re-authentication as the only path.

The related configuration decision is duplicateEmailsAllowed. Turning it on makes the collision disappear by letting the same email exist on several accounts — which also means loginWithEmailAllowed must be off, and one human now has two unlinked accounts. That is usually worse than the linking page.

Next steps​

Phase Two's own social login documentation covers the admin console path and token storage for calling a provider's API afterwards, and the Keycloak identity provider overview covers brokering concepts. The upstream reference for the built-in providers is the Keycloak server administration guide.

Everything above was configured and run against Keycloak 26.8.2. Apple's requirements were taken from its OpenID configuration document and its Sign in with Apple documentation, checked on 2026-11-30.