Repository navigation
Deal with relative url root installations - #903
Conversation
|
Closing to trigger CI |
This commit allows OmniAuth to handle relative url root installations by correctly prefixing the default `Strategy#request_path` and `Strategy#callback_path` with `SCRIPT_NAME` as provided by Rack. Also, in order to detect the full current path, uses `Rack::Request#path` instead of `#path_info`, as the latter does not include SCRIPT_NAME. A deeper question remains: What should happen with custom callback and request paths? I can't think of a case where a user with a relative url root installation would *not* want to prefix its paths, regardless of setting a custom path or not. However, since some people may have configured custom paths in order to deal with relative root, including this change may be breaking.
|
Great to see this repository is being worked on again. We're keeping a fork with this patch included until now. I will look into the potential changes and push again. |
51f579c to
f9a6c0f
Compare
|
@oliverguenther I just rebased, fixed some tests and force pushed to your branch |
|
@BobbyMcWho Excellent, thank you very much. Let us know if we can be of any help here |
|
I've read the issues linked, but I couldn't understand where exactly the issue was before. The problem is that this change seems to break usage with omniauth-facebook and omniauth-google_oauth2 when using relative roots (e.g. Rack's I feel like it would be possible to solve the original issue with relative roots without requiring the inclusion of the script name into |
|
Those strategies did that specifically because omniauth base didn't handle it correctly. With the 2.0 release, it's noted as a breaking change, so if the strategy needs updated to reflect the change in omniauth, then that should be done on their end. |
|
Yeah, I agree that ultimately the problem is on the end of these external strategies. However, my understanding was that they redefined I just wasn't able to understand what exactly was the original problem this PR solves, because with relative root path-matching of request/callback requests worked just fine, and Anyway, regardless of whether I understand it or not it's done now, and I appreciate the reply. I'll then send PRs for omniauth-facebook and omniauth-google_oauth2. |
|
My original PR dates back almost 4 years now so I'm no longer entirely sure of the potential workarounds, but the back redirect of omniauth at the time was invalid if RAILS_RELATIVE_URL_ROOT was being used to dynamically identify an application running in a subdirectory.
Our linked PR examined this behavior and returned paths from omniauth were definitely missing the script_name path.
Have there been intermittent changes to omniauth that renders this PR superfluous?
23.01.2021 12:57:02 Janko Marohnić <[email protected]>:
… Yeah, I agree that ultimately the problem is on the end of these external strategies. However, my understanding was that they redefined #callback_url because they wanted to remove the query string part, as that's the only thing that was missing compared to the original #callback_url implementation. But the correct way to do that would be something like super.sub(/\?.+/, ""), which would work with both OmniAuth 1.x and 2.x.
I just wasn't able to understand what exactly was the original problem this PR solves, because with relative root path-matching of request/callback requests worked just fine, and #callback_url returned the correct value (it included the script name). The only thing is that retrieving Strategy#request_path and Strategy#callback_path directly wouldn't include the script name, but I didn't consider that to be wrong behaviour (an OmniAuth configuration doesn't need to be aware that it's running under a relative root).
Anyway, regardless of whether I understand it or not it's done now, and I appreciate the reply. I'll then send PRs for omniauth-facebook and omniauth-google_oauth2.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub[#903 (comment)], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AADQFRWWRJHOJNXV5WPK3RDS3K2QXANCNFSM4DPB5SCQ].
[data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAD8AAAA/CAYAAABXXxDfAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAAmSURBVGiB7cEBDQAAAMKg909tDwcUAAAAAAAAAAAAAAAAAAAAJwY+QwABivJx1AAAAABJRU5ErkJggg==###24x24:true###][Tracking-Bild][https://github.com/notifications/beacon/AADQFRTCGVHGEP2DCKXGG7DS3K2QXA5CNFSM4DPB5SC2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOFWTOIIY.gif]
|
* One of the breaking changes in OmniAuth 2.0+ relates to how relative URL installations are handled. See: omniauth/omniauth#903 and https://github.com/omniauth/omniauth/wiki/Upgrading-to-2.0#relative-root-apps * As a result, when `azure_activedirectory_v2` is used with OmniAuth 2.0+ for an app that lives at a relative URl, the `#callback_url` is incorrect (the relative URL is included twice). * This is because OmniAuth is now prefixing the default Strategy#request_path and Strategy#callback_path with SCRIPT_NAME, but `azure_activedirectory_v2` is also adding `script_name` to `callback_url`. * This update makes this gem compatible with OmniAuth 2.0+ but will break relative URL installatons for OmniAuth 1.x so I've also updated the gemspec to rely on a version of omniauth-oauth2 that has a dependency on omniauth 2.0: omniauth/omniauth-oauth2#152 (comment)
* One of the breaking changes in OmniAuth 2.0+ relates to how relative URL installations are handled. See: omniauth/omniauth#903 and https://github.com/omniauth/omniauth/wiki/Upgrading-to-2.0#relative-root-apps * As a result, when `azure_activedirectory_v2` is used with OmniAuth 2.0+ for an app that lives at a relative URl, the `#callback_url` is incorrect (the relative URL is included twice). * This is because OmniAuth is now prefixing the default Strategy#request_path and Strategy#callback_path with SCRIPT_NAME, but `azure_activedirectory_v2` is also adding `script_name` to `callback_url`. * This update makes this gem compatible with OmniAuth 2.0+ but will break relative URL installatons for OmniAuth 1.x so I've also updated the gemspec to rely on a version of omniauth-oauth2 that has a dependency on omniauth 2.0: omniauth/omniauth-oauth2#152 (comment) * Similar change to omniauth-google-oauth2 was made here: zquestz/omniauth-google-oauth2#403
- First test so have init via rspec - Breaking change in Omniauth 2 - https://github.com/omniauth/omniauth/wiki/Upgrading-to-2.0#relative-root-apps - omniauth/omniauth#903
This PR allows OmniAuth to transparently handle relative url root installations by correctly prefixing the default
Strategy#request_pathandStrategy#callback_pathwithSCRIPT_NAMEas provided by Rack.Also, in order to detect the full current path, uses
Rack::Request#pathinstead of#path_info, as the latter does not include SCRIPT_NAME.A deeper question remains: What should happen with custom callback and request paths? I can't think of a case where a user with a relative url root installation would not want to prefix its paths, regardless of setting a custom path or not.
However, since some people may have configured custom paths in order to deal with relative root, including this change may be breaking.
I have thus included a specific spec that asserts that custom request paths are not prefixed.
This deals with:
#767
#753
We've stumbled over these bugs while fixing our own OmniAuth relative url root path helpers over at opf/openproject#4169
This is #837 updated to current master.