This repository was archived by the owner on Apr 5, 2022. It is now read-only.
Fix OAuth1 redirect URL when server is behind a proxy. #261
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is the same fix for
OAuth1AuthenticationService
that was applied toOAuth2AuthenticationService
in commit 385e7ca (SOCIAL-447). Specifically, if theHost
header is present in the request, theX-Forwarded-Proto
andX-Forwarded-Port
headers are used to generate the callback URL. This is because a reverse proxy may receive a request via HTTPS on port 443, but an internal application server will see the request as coming via HTTP over port 8080 (for example), and that information will subsequently be used to generate an incorrect redirect URL.The callback URL automatically generated by
OAuth1AuthenticationService
was:http://example.com/auth/twitter
...Despite our site being HTTPS. Due to Twitter recently beginning to enforce strict callback URL matching, Twitter logins were broken because our Twitter application configuration defined our callback URL as:
https://example.com/auth/twitter
I am using this fork in my production application and Twitter logins are now working. My specific setup is Spring Boot 2.0.5 running on Jetty, hosted behind nginx. The site is HTTPS-only, and HTTPS connections are terminated at nginx and forwarded to our internal Jetty host over HTTP, which is running on port 8080.
In case it's helpful for anybody, my nginx configuration for the reverse proxy section is as follows:
Tagging @jaffadog because he was the author of the original
OAuth2AuthenticationService
fix, in case he has any interest in following this or providing any feedback.Tagging @codeconsole because he has an open pull request (#259) that alters the corresponding logic in
OAuth2AuthenticationService
. You may want to include the same change inOAuth1AuthenticationService
if/when this is merged.