Got this error tonight setting up Google OAuth2 -
Thankfully found "OAuth Authorization Error: status 500" but only on my computer which put me on the right path of looking at cookies and how Authelia might be interfering …
I ended up with the following additional nginx configuration -
location /rest/oauth2-credential/auth {
set $upstream_n8n_oauth2 http://<my-n8n-host>:5678;
# save original "Cookie" header value
set $altered_cookie $http_cookie;
# check if the "my_cookie" cookie is present
if ($http_cookie ~ '(.*)(^|;\s)ph_phc_<MY-SPECIFIC-AUTHELIA-COOKIE>_posthog=("[^"]*"|[^\s]*[^;]?)(\2|$|;$)(?:;\s)?(.*)') {
# cut "my_cookie" cookie from the string
set $altered_cookie $1$4$5;
}
# hide original "Cookie" header
proxy_hide_header Cookie;
# set "Cookie" header to the new value
proxy_set_header Cookie $altered_cookie;
proxy_pass $upstream_n8n_oauth2;
}
I got my specific Authelia cookie by looking in the browser dev tools (Application → Cookies) - the cookie starts with ph_phc_
in my case …
Once I did that, I was able to get the OAuth2 handshake to work with Google. I first tried blocking the n8n-auth
cookie, but that gave a different Not Authorized error, which clued me into that not being the right one to block.
Replies weren’t allowed on the original topic anymore, so here’s a new one. Hope this helps someone else.