docs/versioned_docs/version-7.12.x/configuration/providers/openid_connect.md
OpenID 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. The OpenID Connect Provider (OIDC) can also be used to connect to other Identity Providers such as Okta, an example can be found below.
To configure the OIDC provider for Dex, perform the following steps:
Download Dex:
go get github.com/dexidp/dex
See the getting started guide for more details.
Setup oauth2-proxy with the correct provider and using the default ports and callbacks. Add a configuration block to
the staticClients section of examples/config-dev.yaml:
- id: oauth2-proxy
redirectURIs:
- 'http://127.0.0.1:4180/oauth2/callback'
name: 'oauth2-proxy'
secret: proxy
Launch Dex: from $GOPATH/github.com/dexidp/dex, run:
bin/dex serve examples/config-dev.yaml
In a second terminal, run the oauth2-proxy with the following args:
--provider oidc
--provider-display-name "My OIDC Provider"
--client-id oauth2-proxy
--client-secret proxy
--redirect-url http://127.0.0.1:4180/oauth2/callback
--oidc-issuer-url http://127.0.0.1:5556/dex
--cookie-secure=false
--cookie-secret=secret
--email-domain kilgore.trout
To serve the current working directory as a website under the /static endpoint, add:
--upstream file://$PWD/#/static/
Test the setup by visiting http://127.0.0.1:4180 or http://127.0.0.1:4180/static .
See also our local testing environment for a self-contained example using Docker and etcd as storage for Dex.
To configure the OIDC provider for Okta, perform the following steps:
Log in to Okta using an administrative account. It is suggested you try this in preview first, example.oktapreview.com
(OPTIONAL) If you want to configure authorization scopes and claims to be passed on to multiple applications,
you may wish to configure an authorization server for each application. Otherwise, the provided default will work.
Navigate to Applications then select Add Application.
Example App.https://example.corp.com.Authorization Code and Refresh Token.Client ID and Client Secret.Create a configuration file like the following:
provider = "oidc"
redirect_url = "https://example.corp.com/oauth2/callback"
oidc_issuer_url = "https://corp.okta.com/oauth2/abCd1234"
upstreams = [
"https://example.corp.com"
]
email_domains = [
"corp.com"
]
client_id = "XXXXX"
client_secret = "YYYYY"
pass_access_token = true
cookie_secret = "ZZZZZ"
skip_provider_button = true
The oidc_issuer_url is based on URL from your Authorization Server's Issuer field in step 2, or simply
https://corp.okta.com. The client_id and client_secret are configured in the application settings.
Generate a unique cookie_secret to encrypt the cookie.
Then you can start the oauth2-proxy with ./oauth2-proxy --config /etc/example.cfg
Web Application: https://${your-okta-domain}/dev/console/apps/newEveryoneAuthorization Code and Refresh TokenClient ID and Client secret, they are needed in a future step/etc/localhost.cfg
provider = "oidc"
redirect_url = "http://localhost:4180/oauth2/callback"
oidc_issuer_url = "https://$\{your-okta-domain\}/oauth2/default"
upstreams = [
"http://0.0.0.0:8080"
]
email_domains = [
"*"
]
client_id = "XXX"
client_secret = "YYY"
pass_access_token = true
cookie_secret = "ZZZ"
cookie_secure = false
skip_provider_button = true
# Note: use the following for testing within a container
# http_address = "0.0.0.0:4180"
./oauth2-proxy --config /etc/localhost.cfg