website/docs/users-sources/sources/social-logins/github/index.mdx
Allows users to authenticate using their GitHub credentials by configuring GitHub as a federated identity provider via OAuth2.
The following placeholders are used in this guide:
authentik.company is the FQDN of the authentik installation.www.my.company is the Homepage URL for your siteTo integrate GitHub with authentik, you need to create an OAuth application in GitHub Developer Settings.
Log in to GitHub and open the Developer Settings menu.
Create an OAuth app by clicking on the Register a new application button and set the following values:
authentikwww.my.companyhttps://authentik.company/source/oauth/callback/githubClick Register Application
Click Generate a new client secret and take note of the Client Secret and Client ID. These values will be required in the next section.
To support the integration of GitHub with authentik, you need to create a GitHub OAuth source in authentik.
Authorization callback URL field (e.g. github), and set the following required configurations:
<client_ID><client_secret>:::info Display new source on login screen For instructions on how to display the new source on the authentik login page, refer to the Add sources to default login page documentation. :::
:::info Embed new source in flow :ak-enterprise For instructions on embedding the new source within a flow, such as an authorization flow, refer to the Source Stage documentation. :::
:::info
Ensure that the GitHub OAuth source in Federation & Social login has the additional read:org scope added under Protocol settings > Scopes.
:::
To check if the user is a member of an organization, you can use the following policy on your flows.
from authentik.sources.oauth.models import OAuthSource
# Set this value
accepted_org = "your_organization"
# Ensure flow is only run during OAuth logins via GitHub
if not isinstance(context['source'], OAuthSource) or context["source"].provider_type != "github":
return True
# Get the user-source connection object from the context, and get the access token
connection = context["goauthentik.io/sources/connection"]
access_token = connection.access_token
# We also access the user info authentik already retrieved, to get the correct username
github_username = context["oauth_userinfo"]
# GitHub does not include organizations in the userinfo endpoint, so we have to call another URL
orgs_response = requests.get(
"https://api.github.com/user/orgs",
auth=(github_username["login"], access_token),
headers={
"accept": "application/vnd.github.v3+json"
}
)
orgs_response.raise_for_status()
orgs = orgs_response.json()
# `orgs` will be formatted like this
# [
# {
# "login": "goauthentik",
# [...]
# }
# ]
user_matched = any(org['login'] == accepted_org for org in orgs)
if not user_matched:
ak_message(f"User is not member of {accepted_org}.")
return user_matched
If a user is not a member of the chosen organization, they will see this message:
Source property mappings allow you to modify or gather extra information from sources. See the overview for more information.