79103015

Date: 2024-10-18 17:06:16
Score: 3
Natty:
Report link

You can fix this issue by modifying nginx config and auth config: The configuration are given below.

    location /example {
    # Perform OAuth2 authentication
    auth_request /oauth2/auth;
    error_page 401 = /oauth2/sign_in;

    # Capture the user and redirection URL after authentication
    auth_request_set $user $upstream_http_x_user;
    auth_request_set $auth_redirect $upstream_http_x_auth_request_redirect;

    # Add debugging headers to ensure they are being passed properly
    add_header X-Debug-User $user always;
    add_header X-Debug-Redirect $auth_redirect always;

    # Pass the captured redirect URL and user headers to the backend
    proxy_set_header X-User $user;
    proxy_set_header X-Auth-Request-Redirect $auth_redirect;

    # Forward to the internal service after authentication
    proxy_pass https://localhost:6521/;
    proxy_ssl_verify off;
    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-Proto $scheme;
}

    # OAuth2 callback handling
    location /oauth2/ {
        proxy_pass http://localhost:4180;  # OAuth2 Proxy port
        proxy_pass_request_body off;  # Pass only headers
        proxy_set_header Content-Length "";  # No content length since body is removed
        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-Proto $scheme;
    }

And for the Auth config you can do look like that:

provider = "google"
client_id = "12345678901234567890.apps.googleusercontent.com"
client_secret = "abcde-abcdefghijklomn"
redirect_url = "https://mydns/oauth2/callback"
# Ensure tokens and headers are passed
pass_access_token = true
pass_host_header = true
pass_authorization_header = true
set_xauthrequest = true

Please let me know if I'm wrong.

Thanks,

Subrata Ghosh

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • RegEx Blacklisted phrase (2.5): Please let me know
  • Contains signature (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Subrata Ghosh