|
| 1 | +--- |
| 2 | +title: External Identity Providers |
| 3 | +sidebarTitle: External identity providers |
| 4 | +--- |
| 5 | + |
| 6 | +import LicenseKeyRequired from '/snippets/license-key-required.mdx' |
| 7 | + |
| 8 | +<LicenseKeyRequired /> |
| 9 | + |
| 10 | +You can connect Sourcebot to various **external identity providers** to associate a Sourcebot user with one or more external service accounts (ex. Google, GitHub, etc). |
| 11 | + |
| 12 | +External identity providers can be used for [authentication](/docs/configuration/auth) and/or [permission syncing](/docs/features/permission-syncing). They're defined in the |
| 13 | +[config file](/docs/configuration/config-file) in the top-level `identityProviders` object: |
| 14 | + |
| 15 | +```json wrap icon="code" Example config with both google and github identity providers defined |
| 16 | +{ |
| 17 | + "$schema": "https://raw.githubusercontent.com/sourcebot-dev/sourcebot/main/schemas/v3/index.json", |
| 18 | + "identityProviders": [ |
| 19 | + { |
| 20 | + "provider": "github", |
| 21 | + "purpose": "integration", |
| 22 | + "required": true, |
| 23 | +/* |
| 24 | +Secrets are provided through environment variables. Set the secret into |
| 25 | +an env var and provide the name here to tell Sourcebot where to get |
| 26 | +the value |
| 27 | +*/ |
| 28 | + "clientId": { |
| 29 | + "env": "GITHUB_IDENTITY_PROVIDER_CLIENT_ID" |
| 30 | + }, |
| 31 | + "clientSecret": { |
| 32 | + "env": "GITHUB_IDENTITY_PROVIDER_CLIENT_SECRET" |
| 33 | + } |
| 34 | + }, |
| 35 | + { |
| 36 | + "provider": "google", |
| 37 | + "clientId": { |
| 38 | + "env": "GOOGLE_IDENTITY_PROVIDER_CLIENT_ID" |
| 39 | + }, |
| 40 | + "clientSecret": { |
| 41 | + "env": "GOOGLE_IDENTITY_PROVIDER_CLIENT_SECRET" |
| 42 | + } |
| 43 | + } |
| 44 | + ] |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +# Supported External Identity Providers |
| 49 | + |
| 50 | +Sourcebot uses [Auth.js](https://authjs.dev/) to connect to external identity providers. If there's a provider supported by Auth.js that you don't see below, please submit a |
| 51 | +[feature request](https://github.com/sourcebot-dev/sourcebot/issues) to have it added. |
| 52 | + |
| 53 | +### GitHub |
| 54 | + |
| 55 | +[Auth.js GitHub Provider Docs](https://authjs.dev/getting-started/providers/github) |
| 56 | + |
| 57 | +A GitHub connection can be used for either [authentication](/docs/configuration/auth) or [permission syncing](/docs/features/permission-syncing). This is controlled using the `purpose` field |
| 58 | +in the GitHub identity provider config. |
| 59 | + |
| 60 | +<Accordion title="instructions"> |
| 61 | +<Steps> |
| 62 | + <Step title="Register an Oauth Client"> |
| 63 | + To begin, you must register an Oauth client in GitHub to faciliate the identity provider connection. You can do this by creating a **GitHub App** or a **GitHub OAuth App**. Either |
| 64 | + one works, but the **GitHub App** is the [modern way](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/differences-between-github-apps-and-oauth-apps). |
| 65 | + |
| 66 | + |
| 67 | + The result of registering an OAuth client is a `CLIENT_ID` and `CLIENT_SECRET` which you'll provide to Sourcebot. |
| 68 | + <Tabs> |
| 69 | + <Tab title="GitHub App"> |
| 70 | + <Note>You don't need to install the app to use it as an external identity provider</Note> |
| 71 | + Follow [this guide](https://docs.github.com/en/apps/creating-github-apps/registering-a-github-app/registering-a-github-app) to register a new GitHub App. |
| 72 | + |
| 73 | + When asked to provide a callback url, provide `<sourcebot_url>/api/auth/callback/github` (ex. https://sourcebot.coolcorp.com/api/auth/callback/github) |
| 74 | + |
| 75 | + Set the following fine-grained permissions in the GitHub App: |
| 76 | + - `“Email addresses” account permissions (read)` |
| 77 | + </Tab> |
| 78 | + <Tab title="GitHub OAuth App"> |
| 79 | + Follow [this guide](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/creating-an-oauth-app) by GitHub to create an OAuth App. |
| 80 | + |
| 81 | + When asked to provide a callback url, provide `<sourcebot_url>/api/auth/callback/github` (ex. https://sourcebot.coolcorp.com/api/auth/callback/github) |
| 82 | + </Tab> |
| 83 | + </Tabs> |
| 84 | + </Step> |
| 85 | + <Step title="Define environemnt variables"> |
| 86 | + To provide Sourcebot the client id and secret for your OAuth client you must set them as environment variables. These can be named whatever you like |
| 87 | + (ex. `GITHUB_IDENTITY_PROVIDER_CLIENT_ID` and `GITHUB_IDENTITY_PROVIDER_CLIENT_SECRET`) |
| 88 | + </Step> |
| 89 | + <Step title="Define the identity provider config"> |
| 90 | + Finally, pass the client id and secret to Sourcebot by defining a `identityProvider` object in the [config file](/docs/configuration/config-file): |
| 91 | + |
| 92 | + ```json wrap icon="code" |
| 93 | + { |
| 94 | + "$schema": "https://raw.githubusercontent.com/sourcebot-dev/sourcebot/main/schemas/v3/index.json", |
| 95 | + "identityProviders": [ |
| 96 | + { |
| 97 | + "provider": "github", |
| 98 | + // "sso" for auth + perm sync, "integration" for only perm sync |
| 99 | + "purpose": "integration", |
| 100 | + // if purpose == "integration" this controls if a user must connect to the IdP |
| 101 | + "required": true, |
| 102 | + "clientId": { |
| 103 | + "env": "YOUR_CLIENT_ID_ENV_VAR" |
| 104 | + }, |
| 105 | + "clientSecret": { |
| 106 | + "env": "YOUR_CLIENT_SECRET_ENV_VAR" |
| 107 | + } |
| 108 | + } |
| 109 | + ] |
| 110 | + } |
| 111 | + ``` |
| 112 | + </Step> |
| 113 | +</Steps> |
| 114 | +</Accordion> |
| 115 | + |
| 116 | +### GitLab |
| 117 | + |
| 118 | +### Google |
| 119 | + |
| 120 | +### Okta |
| 121 | + |
| 122 | +### Keycloak |
| 123 | + |
| 124 | +### Microsoft Entra ID |
| 125 | + |
0 commit comments