-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
keep 'secret' query parameter first to please the Google Authenticator #95
Conversation
c7b475f
to
bb6472b
Compare
@pquerna could you give this small PR a quick review? |
@@ -18,7 +18,6 @@ func EncodeQuery(v url.Values) string { | |||
for k := range v { | |||
keys = append(keys, k) | |||
} | |||
sort.Strings(keys) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we use a custom sort here instead of no sorting? i kinda liked it was stable rendering of the input. eg, sort where secret
is always first
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like this?
slices.SortFunc(keys, func(a, b string) bool {
if a == "secret" {
return true
}
if b == "secret" {
return false
}
return a < b
})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure thing - my biggest motivation is to roll out a fix for everyone to enjoy!
i can give you an alternative so you have another option to pick from:
// Google Authenticator expects the secret to be first, so handle it separately
keys := make([]string, 0, len(v) - 1)
for k := range v {
if k != "secret" {
keys = append(keys, k)
}
}
sort.Strings(keys)
for _, k := range append([]string{"secret"}, keys...) {
or maybe a little more optimised:
// Google Authenticator expects the secret to be first, so handle it separately
keys := make([]string, 0, len(v))
keys = append(keys, "secret")
for k := range v {
if k != "secret" {
keys = append(keys, k)
}
}
sort.Strings(keys[1:])
for _, k := range keys {
these solutions fail, though, if there' no secret at all
bb6472b
to
72700cd
Compare
72700cd
to
729c730
Compare
@pquerna i've amended the commit to keep the sorting in general, as you requested. |
closing this as the investigation over on issue #94 revealed that order of the parameters is not the root cause of the problem. |
No description provided.