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:
- Open Settings → Developer settings → OAuth apps and choose New OAuth App (or Register a new application if it is your first).
- Fill in:
| Field | Value |
|---|---|
| Application name | The name users see when they approve the app, for example Acme sign-in |
| Homepage URL | Your app's address |
| Authorization callback URL | https://auth.example.com/realms/acme/broker/github/endpoint |
| Enable Device Flow | Off |
- 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
- Open Identity providers and choose GitHub (from the list, or under Add provider).
- Check that Redirect URI matches the callback URL in GitHub, paste the Client ID and Client Secret, and choose Add.
- On the provider's settings, check these and choose Save:
| Setting | Value |
|---|---|
| Base URL, API URL | Leave empty for github.com. Set them only for GitHub Enterprise Server. |
| JSON Format | Off 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.
| Scope | What it gives |
|---|---|
| (no scope) | Read access to public information, including the profile |
user:email | Read access to the user's email addresses |
read:org | Read 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)
- Create a realm role such as
github-approvedunder Realm roles. - After someone signs in with GitHub for the first time, check who they are and assign the role under Users → (user) → Role mapping.
- Make each app require the role. Realm roles are in Keycloak's access token under
realm_access.rolesthrough the defaultrolesclient scope; your app refuses users withoutgithub-approved.
The Keycloak token roles tool shows where the role appears in a token.
Check membership in your app
- On the GitHub provider, add
read:orgto Scopes, and turn on Store tokens and Stored tokens readable (under Advanced settings). - After login, your app calls
GET https://auth.example.com/realms/acme/broker/github/tokenwith the user's Keycloak access token and gets the user's GitHub token back. - With that token, your app calls GitHub's
GET https://api.github.com/user/memberships/orgs/<org>. Astateofactivemeans 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.
- Under Authentication, choose Create flow, name it
github-existing-usersand create it as a basic flow. - Add the step Detect existing broker user and set it to Required. Add Automatically set existing user and set it to Required.
- On the GitHub provider, set First login flow override to
github-existing-users. - 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
- In a private browser window, open
https://auth.example.com/realms/acme/accountand choose GitHub. - Approve the OAuth App. You come back to the account console, signed in.
- In the admin console, open Users, find the user (named after their GitHub login) and check the Identity provider links tab.
- If you limit sign-in, test with an account that should be refused as well.
Common errors
| Error | Cause | Fix |
|---|---|---|
redirect_uri_mismatch from GitHub | The 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 GitHub | The 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 page | A 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 exist | The 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 member | The 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
- Keycloak Server Administration Guide: GitHub, common identity provider settings, first login flow ("Detect existing user first login flow")
- Keycloak source 26.8.1: GitHubIdentityProvider and GitHubIdentityProviderFactory (endpoints, email handling, settings)
- Keycloak Server Developer Guide: Retrieving external IDP tokens
- GitHub: Creating an OAuth app
- GitHub: Scopes for OAuth apps
- GitHub: Differences between GitHub Apps and OAuth apps
- GitHub REST API: Organization members
- GitHub: About OAuth app access restrictions
Connect Okta to Keycloak
Broker Okta logins into your Keycloak realm over OpenID Connect, with Okta's groups claim mapped to Keycloak groups.
Connect Active Directory to Keycloak (LDAP)
Federate Microsoft Active Directory users and groups into your Keycloak realm over LDAPS, read-only, with password checks against your domain controllers.