RealmDeployDocs
GuidesIdentity providers

Connect GitHub to Keycloak

Let users sign in to your Keycloak realm with GitHub through a GitHub OAuth App, and what to do when only members of one GitHub organization may get in.

Users choose GitHub on your Keycloak login page, approve the GitHub OAuth App once, and come back to your app with a Keycloak token. Keycloak's built-in GitHub provider handles the GitHub side.

Checked against the GitHub docs and Keycloak 26.8 on 25 November 2026.

Replace auth.example.com with your RealmDeploy hostname and acme with your realm. The guide uses github as the identity provider alias, so the redirect URI is https://auth.example.com/realms/acme/broker/github/endpoint.

GitHub sign-in is OAuth 2.0, not OpenID Connect: GitHub returns an access token but no ID token. Keycloak uses that token to read the user from GitHub's REST API (/user, and /user/emails when the profile has no public email). That matters for what you can check about the user, see Limit sign-in to one GitHub organization.

Keycloak calls GitHub from your tenant: it redeems the login code at github.com and reads the profile and email addresses from api.github.com, both on port 443. Outgoing connections from your tenant are closed by default. Tell us both hosts through How to reach us before you test, and we open them.

In GitHub

Create an OAuth App, in your own account or in the settings of the organization that should own it:

  1. Open Settings → Developer settings → OAuth apps and choose New OAuth App (or Register a new application if it is your first).
  2. Fill in:
FieldValue
Application nameThe name users see when they approve the app, for example Acme sign-in
Homepage URLYour app's address
Authorization callback URLhttps://auth.example.com/realms/acme/broker/github/endpoint
Enable Device FlowOff
  1. Choose Register application. On the app's page, copy the Client ID, generate a client secret and copy it.

Keycloak also works with a GitHub App instead of an OAuth App. Keycloak's docs note that only GitHub Apps can refresh tokens; you only need that if your apps use the stored GitHub token. This guide uses an OAuth App because its scopes are simple to reason about.

In Keycloak

  1. Open Identity providers and choose GitHub (from the list, or under Add provider).
  2. Check that Redirect URI matches the callback URL in GitHub, paste the Client ID and Client Secret, and choose Add.
  3. On the provider's settings, check these and choose Save:
SettingValue
Base URL, API URLLeave empty for github.com. Set them only for GitHub Enterprise Server.
JSON FormatOff for an OAuth App. Turn it on for a GitHub App whose tokens Keycloak should refresh.
Scopes (under Advanced settings)Leave empty for the default user:email. Add read:org only if your app checks organization membership (below).
Trust Email (under Advanced settings)Off. Keycloak takes the public or primary email from GitHub without checking whether GitHub verified it.

Keycloak sets the username to the GitHub login and the email to the user's public email, or the primary email when there is no public one. It links the account by GitHub's numeric user ID, which stays the same when the user renames their GitHub login.

ScopeWhat it gives
(no scope)Read access to public information, including the profile
user:emailRead access to the user's email addresses
read:orgRead access to organization membership and team membership

Limit sign-in to one GitHub organization

Keycloak's GitHub provider has no setting to allow only members of a GitHub organization or team. It does not read organization membership, and the essential-claim check (Verify essential claim) works only on ID tokens, which GitHub does not issue. Adding that check inside Keycloak would take an extension, and extensions cannot be installed on your tenant. Anyone with a GitHub account can therefore complete the GitHub sign-in. Pick one of these instead:

Approve users in Keycloak (simplest)

  1. Create a realm role such as github-approved under Realm roles.
  2. After someone signs in with GitHub for the first time, check who they are and assign the role under Users → (user) → Role mapping.
  3. Make each app require the role. Realm roles are in Keycloak's access token under realm_access.roles through the default roles client scope; your app refuses users without github-approved.

The Keycloak token roles tool shows where the role appears in a token.

Check membership in your app

  1. On the GitHub provider, add read:org to Scopes, and turn on Store tokens and Stored tokens readable (under Advanced settings).
  2. After login, your app calls GET https://auth.example.com/realms/acme/broker/github/token with the user's Keycloak access token and gets the user's GitHub token back.
  3. With that token, your app calls GitHub's GET https://api.github.com/user/memberships/orgs/<org>. A state of active means the user is a member; GitHub answers 404 when the user is not affiliated with the organization.

This call runs from your app, not from your tenant, so it needs no outgoing connection from us. Keycloak marks this token API (Identity Brokering API V1) as deprecated; it is still on by default in Keycloak 26.8. If the organization restricts OAuth app access, which GitHub turns on by default for new organizations, an owner may have to approve the OAuth App first; test with a member whose membership is private.

Let in only users you created

Keycloak documents a first login flow for this case: it links a GitHub login to a user who already exists in the realm and refuses everyone else.

  1. Under Authentication, choose Create flow, name it github-existing-users and create it as a basic flow.
  2. Add the step Detect existing broker user and set it to Required. Add Automatically set existing user and set it to Required.
  3. On the GitHub provider, set First login flow override to github-existing-users.
  4. Create each allowed user under Users before their first login.

Keycloak matches the GitHub account to an existing user by email first, then by username (the GitHub login). Keycloak does not check whether GitHub verified that email, and a GitHub login that someone gives up can later be taken by someone else. Only use this when you create the users yourself, with addresses and logins you checked. After the first login, the link is GitHub's numeric user ID and matching no longer applies.

Groups and roles

GitHub sends no groups or teams. Assign Keycloak groups and roles to GitHub users yourself, or add a Hardcoded Group or Hardcoded Role mapper on the provider's Mappers tab to give everyone who signs in with GitHub the same starting group or role. To store more GitHub profile fields, add an Attribute Importer mapper with a Social Profile JSON Field Path such as company and a User Attribute Name.

Your apps see Keycloak groups in tokens once their client has a Group Membership mapper (Client scopes → <client-id>-dedicated → Configure a new mapper).

Test it

  1. In a private browser window, open https://auth.example.com/realms/acme/account and choose GitHub.
  2. Approve the OAuth App. You come back to the account console, signed in.
  3. In the admin console, open Users, find the user (named after their GitHub login) and check the Identity provider links tab.
  4. If you limit sign-in, test with an account that should be refused as well.

Common errors

ErrorCauseFix
redirect_uri_mismatch from GitHubThe callback URL in GitHub differs from the one Keycloak sends.Copy the Redirect URI from Keycloak into Authorization callback URL. The redirect URI matcher shows the difference.
Keycloak shows Unexpected error when authenticating with identity provider after GitHubThe outgoing connections to github.com or api.github.com are not open yet, the client secret is wrong, or Keycloak found no primary email.Tell us the hosts through How to reach us. Check the secret and that the user's GitHub account has an email.
Account already exists pageA Keycloak user with the same email already exists.The user links the accounts by proving they own the existing one.
User ... authenticated with identity provider github does not existThe github-existing-users flow found no matching user.Expected for people you have not created. Otherwise create the user with the right email or GitHub login.
Membership check in your app returns 404 for a memberThe token lacks read:org, or the organization has not approved the OAuth App.Add read:org to Scopes and have the user sign in again; ask an organization owner to approve the app.

FAQ

Can I get GitHub teams into Keycloak?

Not with the built-in provider. Read them in your app with the stored GitHub token and read:org, or manage the matching groups in Keycloak yourself.

Does this work with GitHub Enterprise Server?

The provider has Base URL and API URL settings for that. Keycloak must be able to reach your server over HTTPS from your tenant: tell us its host and port, and we open the outgoing connection.

Can users skip the Keycloak login page?

Yes. Add kc_idp_hint=github to the app's login request; the identity provider redirect builder writes the URL.

Sources

On this page