mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2025-02-21 19:48:46 +02:00
doc: add example for caddy v2 forward_auth (#2759)
--------- Co-authored-by: Denis Dabischa <34655672+dabde@users.noreply.github.com> Co-authored-by: Brennan Kinney <5098581+polarathene@users.noreply.github.com>
This commit is contained in:
parent
bc034454f6
commit
fff5dd358f
@ -265,6 +265,42 @@ http:
|
||||
- Authorization
|
||||
```
|
||||
|
||||
## Configuring for use with the caddy v2 `forward_auth` directive
|
||||
|
||||
The [Caddy `forward_auth` directive](https://caddyserver.com/docs/caddyfile/directives/forward_auth) allows Caddy to authenticate requests via the `oauth2-proxy`'s `/auth`.
|
||||
|
||||
This example is for a simple reverse proxy setup where the `/oauth2/` path is kept under the same domain and failed auth requests (401 status returned) will be caught and redirected to the `sign_in` endpoint.
|
||||
|
||||
**Following options need to be set on `oauth2-proxy`:**
|
||||
- `--reverse-proxy=true`: Enables the use of `X-Forwarded-*` headers to determine redirects correctly
|
||||
|
||||
```nginx
|
||||
{{ domain }} {
|
||||
# define forward auth for any path under `/`, if not more specific defined
|
||||
forward_auth / {{ oauth.internalIP }}:4180 {
|
||||
uri /oauth2/auth
|
||||
copy_headers Authorization X-Auth-Request-User X-Auth-Request-Email
|
||||
|
||||
@error status 401
|
||||
handle_response @error {
|
||||
redir * /oauth2/sign_in?rd={scheme}://{host}{uri} 302
|
||||
}
|
||||
}
|
||||
|
||||
# define `/oauth2/*` as specific endpoint, to avoid forward auth protection to be able to use service
|
||||
reverse_proxy /oauth2/* {{ oauth.internalIP }}:4180 {
|
||||
header_up X-Real-IP {remote}
|
||||
header_up X-Forwarded-Proto https
|
||||
}
|
||||
|
||||
# unspecific reverse proxy will be protected from `forward_auth /`
|
||||
reverse_proxy {{ endpointIP }} {
|
||||
header_up X-Real-IP {remote}
|
||||
header_up X-Forwarded-Proto https
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
:::note
|
||||
If you set up your OAuth2 provider to rotate your client secret, you can use the `client-secret-file` option to reload the secret when it is updated.
|
||||
:::
|
||||
|
@ -265,6 +265,42 @@ http:
|
||||
- Authorization
|
||||
```
|
||||
|
||||
## Configuring for use with the caddy v2 `forward_auth` directive
|
||||
|
||||
The [Caddy `forward_auth` directive](https://caddyserver.com/docs/caddyfile/directives/forward_auth) allows Caddy to authenticate requests via the `oauth2-proxy`'s `/auth`.
|
||||
|
||||
This example is for a simple reverse proxy setup where the `/oauth2/` path is kept under the same domain and failed auth requests (401 status returned) will be caught and redirected to the `sign_in` endpoint.
|
||||
|
||||
**Following options need to be set on `oauth2-proxy`:**
|
||||
- `--reverse-proxy=true`: Enables the use of `X-Forwarded-*` headers to determine redirects correctly
|
||||
|
||||
```nginx
|
||||
{{ domain }} {
|
||||
# define forward auth for any path under `/`, if not more specific defined
|
||||
forward_auth / {{ oauth.internalIP }}:4180 {
|
||||
uri /oauth2/auth
|
||||
copy_headers Authorization X-Auth-Request-User X-Auth-Request-Email
|
||||
|
||||
@error status 401
|
||||
handle_response @error {
|
||||
redir * /oauth2/sign_in?rd={scheme}://{host}{uri} 302
|
||||
}
|
||||
}
|
||||
|
||||
# define `/oauth2/*` as specific endpoint, to avoid forward auth protection to be able to use service
|
||||
reverse_proxy /oauth2/* {{ oauth.internalIP }}:4180 {
|
||||
header_up X-Real-IP {remote}
|
||||
header_up X-Forwarded-Proto https
|
||||
}
|
||||
|
||||
# unspecific reverse proxy will be protected from `forward_auth /`
|
||||
reverse_proxy {{ endpointIP }} {
|
||||
header_up X-Real-IP {remote}
|
||||
header_up X-Forwarded-Proto https
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
:::note
|
||||
If you set up your OAuth2 provider to rotate your client secret, you can use the `client-secret-file` option to reload the secret when it is updated.
|
||||
:::
|
||||
|
Loading…
x
Reference in New Issue
Block a user