3title: Auth Configuration
4permalink: /auth-configuration
8## OAuth Provider Configuration
10You will need to register an OAuth application with a Provider (Google, GitHub or another provider), and configure it with Redirect URI(s) for the domain you intend to run `oauth2-proxy` on.
14- [Google](#google-auth-provider) _default_
15- [Azure](#azure-auth-provider)
16- [Facebook](#facebook-auth-provider)
17- [GitHub](#github-auth-provider)
18- [Keycloak](#keycloak-auth-provider)
19- [GitLab](#gitlab-auth-provider)
20- [LinkedIn](#linkedin-auth-provider)
21- [Microsoft Azure AD](#microsoft-azure-ad-provider)
22- [OpenID Connect](#openid-connect-provider)
23- [login.gov](#logingov-provider)
24- [Nextcloud](#nextcloud-provider)
25- [DigitalOcean](#digitalocean-auth-provider)
26- [Bitbucket](#bitbucket-auth-provider)
28The provider can be selected using the `provider` configuration value.
30Please note that not all provides support all claims. The `preferred_username` claim is currently only supported by the OpenID Connect provider.
32### Google Auth Provider
34For Google, the registration steps are:
361. Create a new project: https://console.developers.google.com/project
372. Choose the new project from the top right project dropdown (only if another project is selected)
383. In the project Dashboard center pane, choose **"API Manager"**
394. In the left Nav pane, choose **"Credentials"**
405. In the center pane, choose **"OAuth consent screen"** tab. Fill in **"Product name shown to users"** and hit save.
416. In the center pane, choose **"Credentials"** tab.
42 - Open the **"New credentials"** drop down
43 - Choose **"OAuth client ID"**
44 - Choose **"Web application"**
45 - Application name is freeform, choose something appropriate
46 - Authorized JavaScript origins is your domain ex: `https://internal.yourcompany.com`
47 - Authorized redirect URIs is the location of oauth2/callback ex: `https://internal.yourcompany.com/oauth2/callback`
497. Take note of the **Client ID** and **Client Secret**
51It's recommended to refresh sessions on a short interval (1h) with `cookie-refresh` setting which validates that the account is still authorized.
53#### Restrict auth to specific Google groups on your domain. (optional)
551. Create a service account: https://developers.google.com/identity/protocols/OAuth2ServiceAccount and make sure to download the json file.
562. Make note of the Client ID for a future step.
573. Under "APIs & Auth", choose APIs.
584. Click on Admin SDK and then Enable API.
595. Follow the steps on https://developers.google.com/admin-sdk/directory/v1/guides/delegation#delegate_domain-wide_authority_to_your_service_account and give the client id from step 2 the following oauth scopes:
62https://www.googleapis.com/auth/admin.directory.group.readonly
63https://www.googleapis.com/auth/admin.directory.user.readonly
666. Follow the steps on https://support.google.com/a/answer/60757 to enable Admin API access.
677. Create or choose an existing administrative email address on the Gmail domain to assign to the `google-admin-email` flag. This email will be impersonated by this client to make calls to the Admin SDK. See the note on the link from step 5 for the reason why.
688. Create or choose an existing email group and set that email to the `google-group` flag. You can pass multiple instances of this flag with different groups
69 and the user will be checked against all the provided groups.
709. Lock down the permissions on the json file downloaded from step 1 so only oauth2-proxy is able to read the file and set the path to the file in the `google-service-account-json` flag.
7110. Restart oauth2-proxy.
73Note: The user is checked against the group members list on initial authentication and every time the token is refreshed ( about once an hour ).
75### Azure Auth Provider
771. Add an application: go to [https://portal.azure.com](https://portal.azure.com), choose **"Azure Active Directory"** in the left menu, select **"App registrations"** and then click on **"New app registration"**.
782. Pick a name and choose **"Webapp / API"** as application type. Use `https://internal.yourcompany.com` as Sign-on URL. Click **"Create"**.
793. On the **"Settings"** / **"Properties"** page of the app, pick a logo and select **"Multi-tenanted"** if you want to allow users from multiple organizations to access your app. Note down the application ID. Click **"Save"**.
804. On the **"Settings"** / **"Required Permissions"** page of the app, click on **"Windows Azure Active Directory"** and then on **"Access the directory as the signed in user"**. Hit **"Save"** and then then on **"Grant permissions"** (you might need another admin to do this).
815. On the **"Settings"** / **"Reply URLs"** page of the app, add `https://internal.yourcompanycom/oauth2/callback` for each host that you want to protect by the oauth2 proxy. Click **"Save"**.
826. On the **"Settings"** / **"Keys"** page of the app, add a new key and note down the value after hitting **"Save"**.
837. Configure the proxy with
87 --client-id=<application ID from step 3>
88 --client-secret=<value from step 6>
91Note: When using the Azure Auth provider with nginx and the cookie session store you may find the cookie is too large and doesn't get passed through correctly. Increasing the proxy_buffer_size in nginx or implementing the [redis session storage](configuration/sessions#redis-storage) should resolve this.
93### Facebook Auth Provider
951. Create a new FB App from <https://developers.facebook.com/>
962. Under FB Login, set your Valid OAuth redirect URIs to `https://internal.yourcompany.com/oauth2/callback`
98### GitHub Auth Provider
1001. Create a new project: https://github.com/settings/developers
1012. Under `Authorization callback URL` enter the correct url ie `https://internal.yourcompany.com/oauth2/callback`
103The GitHub auth provider supports two additional parameters to restrict authentication to Organization or Team level access. Restricting by org and team is normally accompanied with `--email-domain=*`
105 -github-org="": restrict logins to members of this organisation
106 -github-team="": restrict logins to members of any of these teams (slug), separated by a comma
108If you are using GitHub enterprise, make sure you set the following to the appropriate url:
110 -login-url="http(s)://<enterprise github host>/login/oauth/authorize"
111 -redeem-url="http(s)://<enterprise github host>/login/oauth/access_token"
112 -validate-url="http(s)://<enterprise github host>/api/v3"
114### Keycloak Auth Provider
1161. Create new client in your Keycloak with **Access Type** 'confidental' and **Valid Redirect URIs** 'https://internal.yourcompany.com/oauth2/callback'
1172. Take note of the Secret in the credential tab of the client
1183. Create a mapper with **Mapper Type** 'Group Membership' and **Token Claim Name** 'groups'.
120Make sure you set the following to the appropriate url:
123 -client-id=<client you have created>
124 -client-secret=<your client's secret>
125 -login-url="http(s)://<keycloak host>/realms/<your realm>/protocol/openid-connect/auth"
126 -redeem-url="http(s)://<keycloak host>/realms/<your realm>/protocol/openid-connect/token"
127 -validate-url="http(s)://<keycloak host>/realms/<your realm>/protocol/openid-connect/userinfo"
128 -keycloak-group=<user_group>
130The group management in keycloak is using a tree. If you create a group named admin in keycloak you should define the 'keycloak-group' value to /admin.
132### GitLab Auth Provider
134Whether you are using GitLab.com or self-hosting GitLab, follow [these steps to add an application](https://docs.gitlab.com/ce/integration/oauth_provider.html). Make sure to enable at least the `openid`, `profile` and `email` scopes.
136Restricting by group membership is possible with the following option:
138 -gitlab-group="": restrict logins to members of any of these groups (slug), separated by a comma
140If you are using self-hosted GitLab, make sure you set the following to the appropriate URL:
142 -oidc-issuer-url="<your gitlab url>"
144### LinkedIn Auth Provider
146For LinkedIn, the registration steps are:
1481. Create a new project: https://www.linkedin.com/secure/developer
1492. In the OAuth User Agreement section:
150 - In default scope, select r_basicprofile and r_emailaddress.
151 - In "OAuth 2.0 Redirect URLs", enter `https://internal.yourcompany.com/oauth2/callback`
1523. Fill in the remaining required fields and Save.
1534. Take note of the **Consumer Key / API Key** and **Consumer Secret / Secret Key**
155### Microsoft Azure AD Provider
157For adding an application to the Microsoft Azure AD follow [these steps to add an application](https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app).
159Take note of your `TenantId` if applicable for your situation. The `TenantId` can be used to override the default `common` authorization server with a tenant specific server.
161### OpenID Connect Provider
163OpenID Connect is a spec for OAUTH 2.0 + identity that is implemented by many major providers and several open source projects. This provider was originally built against CoreOS Dex and we will use it as an example.
1651. Launch a Dex instance using the [getting started guide](https://github.com/coreos/dex/blob/master/Documentation/getting-started.md).
1662. Setup oauth2-proxy with the correct provider and using the default ports and callbacks.
1673. Login with the fixture use in the dex guide and run the oauth2-proxy with the following args:
170 -provider-display-name "My OIDC Provider"
171 -client-id oauth2-proxy
173 -redirect-url http://127.0.0.1:4180/oauth2/callback
174 -oidc-issuer-url http://127.0.0.1:5556
176 -email-domain example.com
178The OpenID Connect Provider (OIDC) can also be used to connect to other Identity Providers such as Okta. To configure the OIDC provider for Okta, perform
181#### Configuring the OIDC Provider with Okta
1831. Log in to Okta using an administrative account. It is suggested you try this in preview first, `example.oktapreview.com`
1842. (OPTIONAL) If you want to configure authorization scopes and claims to be passed on to multiple applications,
185you may wish to configure an authorization server for each application. Otherwise, the provided `default` will work.
186* Navigate to **Security** then select **API**
187* Click **Add Authorization Server**, if this option is not available you may require an additional license for a custom authorization server.
188* Fill out the **Name** with something to describe the application you are protecting. e.g. 'Example App'.
189* For **Audience**, pick the URL of the application you wish to protect: https://example.corp.com
190* Fill out a **Description**
191* Add any **Access Policies** you wish to configure to limit application access.
192* The default settings will work for other options.
193[See Okta documentation for more information on Authorization Servers](https://developer.okta.com/docs/guides/customize-authz-server/overview/)
1943. Navigate to **Applications** then select **Add Application**.
195* Select **Web** for the **Platform** setting.
196* Select **OpenID Connect** and click **Create**
197* Pick an **Application Name** such as `Example App`.
198* Set the **Login redirect URI** to `https://example.corp.com`.
199* Under **General** set the **Allowed grant types** to `Authorization Code` and `Refresh Token`.
200* Leave the rest as default, taking note of the `Client ID` and `Client Secret`.
201* Under **Assignments** select the users or groups you wish to access your application.
2024. Create a configuration file like the following:
206redirect_url = "https://example.corp.com"
207oidc_issuer_url = "https://corp.okta.com/oauth2/abCd1234"
209 "https://example.corp.com"
215client_secret = "YYYYY"
216pass_access_token = true
217cookie_secret = "ZZZZZ"
218skip_provider_button = true
221The `oidc_issuer_url` is based on URL from your **Authorization Server**'s **Issuer** field in step 2, or simply https://corp.okta.com
222The `client_id` and `client_secret` are configured in the application settings.
223Generate a unique `client_secret` to encrypt the cookie.
225Then you can start the oauth2-proxy with `./oauth2-proxy -config /etc/example.cfg`
228### login.gov Provider
230login.gov is an OIDC provider for the US Government.
231If you are a US Government agency, you can contact the login.gov team through the contact information
232that you can find on https://login.gov/developers/ and work with them to understand how to get login.gov
233accounts for integration/test and production access.
235A developer guide is available here: https://developers.login.gov/, though this proxy handles everything
236but the data you need to create to register your application in the login.gov dashboard.
238As a demo, we will assume that you are running your application that you want to secure locally on
239http://localhost:3000/, that you will be starting your proxy up on http://localhost:4180/, and that
240you have an agency integration account for testing.
242First, register your application in the dashboard. The important bits are:
243 * Identity protocol: make this `Openid connect`
244 * Issuer: do what they say for OpenID Connect. We will refer to this string as `${LOGINGOV_ISSUER}`.
245 * Public key: This is a self-signed certificate in .pem format generated from a 2048 bit RSA private key.
246 A quick way to do this is `openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 3650 -nodes -subj '/C=US/ST=Washington/L=DC/O=GSA/OU=18F/CN=localhost'`,
247 The contents of the `key.pem` shall be referred to as `${OAUTH2_PROXY_JWT_KEY}`.
248 * Return to App URL: Make this be `http://localhost:4180/`
249 * Redirect URIs: Make this be `http://localhost:4180/oauth2/callback`.
250 * Attribute Bundle: Make sure that email is selected.
252Now start the proxy up with the following options:
254./oauth2-proxy -provider login.gov \
255 -client-id=${LOGINGOV_ISSUER} \
256 -redirect-url=http://localhost:4180/oauth2/callback \
257 -oidc-issuer-url=https://idp.int.identitysandbox.gov/ \
258 -cookie-secure=false \
259 -email-domain=gsa.gov \
260 -upstream=http://localhost:3000/ \
261 -cookie-secret=somerandomstring12341234567890AB \
262 -cookie-domain=localhost \
263 -skip-provider-button=true \
264 -pubjwk-url=https://idp.int.identitysandbox.gov/api/openid_connect/certs \
265 -profile-url=https://idp.int.identitysandbox.gov/api/openid_connect/userinfo \
266 -jwt-key="${OAUTH2_PROXY_JWT_KEY}"
268You can also set all these options with environment variables, for use in cloud/docker environments.
269One tricky thing that you may encounter is that some cloud environments will pass in environment
270variables in a docker env-file, which does not allow multiline variables like a PEM file.
271If you encounter this, then you can create a `jwt_signing_key.pem` file in the top level
272directory of the repo which contains the key in PEM format and then do your docker build.
273The docker build process will copy that file into your image which you can then access by
274setting the `OAUTH2_PROXY_JWT_KEY_FILE=/etc/ssl/private/jwt_signing_key.pem`
275environment variable, or by setting `-jwt-key-file=/etc/ssl/private/jwt_signing_key.pem` on the commandline.
277Once it is running, you should be able to go to `http://localhost:4180/` in your browser,
278get authenticated by the login.gov integration server, and then get proxied on to your
279application running on `http://localhost:3000/`. In a real deployment, you would secure
280your application with a firewall or something so that it was only accessible from the
281proxy, and you would use real hostnames everywhere.
283#### Skip OIDC discovery
285Some providers do not support OIDC discovery via their issuer URL, so oauth2-proxy cannot simply grab the authorization, token and jwks URI endpoints from the provider's metadata.
287In this case, you can set the `-skip-oidc-discovery` option, and supply those required endpoints manually:
291 -client-id oauth2-proxy
293 -redirect-url http://127.0.0.1:4180/oauth2/callback
294 -oidc-issuer-url http://127.0.0.1:5556
296 -login-url http://127.0.0.1:5556/authorize
297 -redeem-url http://127.0.0.1:5556/token
298 -oidc-jwks-url http://127.0.0.1:5556/keys
300 -email-domain example.com
303### Nextcloud Provider
305The Nextcloud provider allows you to authenticate against users in your
308When you are using the Nextcloud provider, you must specify the urls via
309configuration, environment variable, or command line argument. Depending
310on whether your Nextcloud instance is using pretty urls your urls may be of the
311form `/index.php/apps/oauth2/*` or `/apps/oauth2/*`.
314documentation](https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/oauth2.html)
315to setup the client id and client secret. Your "Redirection URI" will be
316`https://internalapp.yourcompany.com/oauth2/callback`.
320 -client-id <from nextcloud admin>
321 -client-secret <from nextcloud admin>
322 -login-url="<your nextcloud url>/index.php/apps/oauth2/authorize"
323 -redeem-url="<your nextcloud url>/index.php/apps/oauth2/api/v1/token"
324 -validate-url="<your nextcloud url>/ocs/v2.php/cloud/user?format=json"
327Note: in *all* cases the validate-url will *not* have the `index.php`.
329### DigitalOcean Auth Provider
3311. [Create a new OAuth application](https://cloud.digitalocean.com/account/api/applications)
332 * You can fill in the name, homepage, and description however you wish.
333 * In the "Application callback URL" field, enter: `https://oauth-proxy/oauth2/callback`, substituting `oauth2-proxy` with the actual hostname that oauth2-proxy is running on. The URL must match oauth2-proxy's configured redirect URL.
3342. Note the Client ID and Client Secret.
336To use the provider, pass the following options:
339 --provider=digitalocean
340 --client-id=<Client ID>
341 --client-secret=<Client Secret>
344 Alternatively, set the equivalent options in the config file. The redirect URL defaults to `https://<requested host header>/oauth2/callback`. If you need to change it, you can use the `--redirect-url` command-line option.
346### Bitbucket Auth Provider
3481. [Add a new OAuth consumer](https://confluence.atlassian.com/bitbucket/oauth-on-bitbucket-cloud-238027431.html)
349 * In "Callback URL" use `https://<oauth2-proxy>/oauth2/callback`, substituting `<oauth2-proxy>` with the actual hostname that oauth2-proxy is running on.
350 * In Permissions section select:
352 * Team membership -> Read
353 * Repositories -> Read
3542. Note the Client ID and Client Secret.
356To use the provider, pass the following options:
360 --client-id=<Client ID>
361 --client-secret=<Client Secret>
364The default configuration allows everyone with Bitbucket account to authenticate. To restrict the access to the team members use additional configuration option: `--bitbucket-team=<Team name>`. To restrict the access to only these users who has access to one selected repository use `--bitbucket-repository=<Repository name>`.
367## Email Authentication
369To authorize by email domain use `--email-domain=yourcompany.com`. To authorize individual email addresses use `--authenticated-emails-file=/path/to/file` with one email per line. To authorize all email addresses use `--email-domain=*`.
371## Adding a new Provider
373Follow the examples in the [`providers` package]({{ site.gitweb }}/providers/) to define a new
374`Provider` instance. Add a new `case` to
375[`providers.New()`]({{ site.gitweb }}/providers/providers.go) to allow `oauth2-proxy` to use the
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list