oauth2-proxy: 400 Error for app behind nginx
I have an application setup using Nginx forward-auth, with the oauth proxy also behind nginx. Proxy directs correctly to the OIDC login, however after completing the login flow, all I get is a 400 Bad Request error.
Expected Behavior
Redirection to application after auth.
Current Behavior
400 error instead of proper redirection
Possible Solution
I honestly have no idea.
Steps to Reproduce (for bugs)
NGINX setup for host to authenticate:
location / {
expires -1;
error_page 401 = /oauth2/sign_in?rd=$scheme://$host$request_uri;
auth_request_set $user $upstream_http_x_auth_request_user;
auth_request_set $token $upstream_http_x_auth_request_access_token;
auth_request_set $auth_cookie $upstream_http_set_cookie;
proxy_set_header X-User $user;
proxy_set_header X-Access-Token $token;
add_header Set-Cookie $auth_cookie;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-Proto $scheme;
auth_request /oauth2/auth;
}
location /oauth2 {
expires -1;
proxy_set_header Host oauth2proxy.example.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Auth-Request-Redirect $request_uri;
proxy_pass http://x.x.x.x:4180;
}
location = /oauth2/sign_out {
expires -1;
proxy_set_header Host oauth2proxy.example.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Auth-Request-Redirect /oauth2/sign_in;
proxy_pass http://x.x.x.x:4180;
}
proxy config:
provider = "oidc"
#user_id_claim = "sub" #uses the subject as ID instead of the email
provider_display_name = "SSO"
redirect_url = "https://oauth2proxy.example.com/oauth2/callback"
oidc_issuer_url = "https://sso.example.com"
upstreams = "https://oauth2proxy.example.com"
email_domains = [ "*" ]
cookie_domains = [".example.com"]
whitelist_domains = [".example.com"]
client_id = "SOME_CLIENT_ID"
client_secret = "SOME_CLIENT_SECRET"
pass_access_token = true
cookie_secret = "COOKIE_SECRET"
skip_provider_button = true
cookie_secure = true
http_address = "0.0.0.0:4180"
scope = "openid profile email users"
reverse_proxy = true
ssl_insecure_skip_verify = true
insecure_oidc_allow_unverified_email = true
The Issue is Zitadel, OIDC.
- Setup nginx and oauth2proxy with above configs
- visit url of host
- proceed through auth flow
- receive 400 error
Context
Your Environment
Everything is in Docker, NGINX is actually NGINX Proxy Manager. oauth2proxy.example.com is resolvable from inside and outside network, and points to nginx proxy manager and proxies requests to the oauth2 proxy container.
- Version used: 7.5.1
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (1 by maintainers)
Hey, got this exact error with frigate yesterday.
The “solution” was to add large_client_header_buffers to the nginx server block and increase the default value from
large_client_header_buffers 4 8kto something likelarge_client_header_buffers 4 32k