Repository navigation
Preserve URL hash on 'fragment' response - #251
Conversation
|
@djoho < 8000 a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/2manyvcos/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/2manyvcos">@2manyvcos could I ask you to test this implementation, and let me know if this solves the issues you are having? |
a96520c to
a056e35
Compare
|
I have a more solid idea for an implementation, marking this as draft until then. |
a056e35 to
5e2a7bd
Compare
|
Alright, I went ahead and changed the implementation. It now tries to find the place where Keycloak appends the parameters at the end of the fragment, taking advantage of the rigid way Keycloak adds the parameters (always at the end, only prefixed with a |
5e2a7bd to
eb1d089
Compare
|
I tightened up the implementation a little more, there are now some extra test cases that handle various things like duplicated parameters, and some other various edge cases. Marking this as ready for review. |
eb1d089 to
24ec11a
Compare
There was a problem hiding this comment.
@jonkoops Maybe it is easier to just change the parseCallbackParamsmethod. Something like this works for me with your tests:
#parseCallbackParams (paramsString, supportedParams) {
const params = paramsString.split("&")
/** @type {Record<string, string>} */
const oauthParams = {}
let result = ""
for (const param of params.reverse()) {
const entry = new URLSearchParams(param).entries().find(() => true);
if (entry && supportedParams.includes(entry[0]) && !oauthParams[entry[0]]) {
oauthParams[entry[0]] = entry[1]
} else {
result = result.length == 0 ? param : param + "&" + result
}
}
return {
paramsString: result,
oauthParams
}
}This does not modify the fragment or the query and respect all the characters. I have even added a test to see several &&& are maintained.
0d8cfbd to
dfaff40
Compare
|
@rmartinc Yes, I like your suggestion. I have pushed a slightly modified version and added you as a co-author. Can I ask you for a re-review? Initially, I was focussing a lot on having this code separated, as I want to eventually deprecate and remove this behavior, so I felt I needed to have a proper piece of code to detect this. However, I can simply introduce a flag to disable this behavior, and never send a fragment in the first place. |
There was a problem hiding this comment.
Just a minor comment. Just in case you want to also consider several ampersands in the original fragment...
Closes keycloak#241 Co-authored-by: rmartinc <rmartinc@redhat.com> Signed-off-by: Jon Koops <jonkoops@gmail.com>
dfaff40 to
d9ebc42
Compare
There was a problem hiding this comment.
Just check the length to not add the ampersand the first time.
Fixes an issue where URL fragments with path-style routing (e.g.,
#/admin/maintenance/scripts) were being URL-encoded after OAuth callback, breaking some applications using hash-based routing. The fix correctly separates the application portion of the hash (e.g. routes) from OAuth callback parameters in fragment response.Closes #241