File tree 2 files changed +13
-6
lines changed
2 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -117,8 +117,16 @@ func (r *Response) GetRedirectUrl() (string, error) {
117
117
return "" , err
118
118
}
119
119
120
+ var q url.Values
121
+ if r .RedirectInFragment {
122
+ // start with empty set for fragment
123
+ q = url.Values {}
124
+ } else {
125
+ // add parameters to existing query
126
+ q = u .Query ()
127
+ }
128
+
120
129
// add parameters
121
- q := u .Query ()
122
130
for n , v := range r .Output {
123
131
q .Set (n , fmt .Sprint (v ))
124
132
}
@@ -127,7 +135,6 @@ func (r *Response) GetRedirectUrl() (string, error) {
127
135
// Fragment should be encoded as application/x-www-form-urlencoded (%-escaped, spaces are represented as '+')
128
136
// The stdlib URL#String() doesn't make that easy to accomplish, so build this ourselves
129
137
if r .RedirectInFragment {
130
- u .RawQuery = ""
131
138
u .Fragment = ""
132
139
redirectURI := u .String () + "#" + q .Encode ()
133
140
return redirectURI , nil
Original file line number Diff line number Diff line change @@ -18,18 +18,18 @@ func TestGetRedirectUrl(t *testing.T) {
18
18
ExpectedURL string
19
19
}{
20
20
"query" : {
21
- URL : "https://foo.com/path" ,
21
+ URL : "https://foo.com/path?abc=123 " ,
22
22
Output : ResponseData {"access_token" : "12345" , "state" : state },
23
- ExpectedURL : "https://foo.com/path?access_token=12345&state=%7B%22then%22%3A+%22%2Findex.html%3Fa%3D1%26b%3D%252B%23fragment%22%2C+%22nonce%22%3A+%22014f%3Abff9a07c%22%7D" ,
23
+ ExpectedURL : "https://foo.com/path?abc=123& access_token=12345&state=%7B%22then%22%3A+%22%2Findex.html%3Fa%3D1%26b%3D%252B%23fragment%22%2C+%22nonce%22%3A+%22014f%3Abff9a07c%22%7D" ,
24
24
},
25
25
26
26
// https://tools.ietf.org/html/rfc6749#section-4.2.2
27
27
// Fragment should be encoded as application/x-www-form-urlencoded (%-escaped, spaces are represented as '+')
28
28
"fragment" : {
29
- URL : "https://foo.com/path" ,
29
+ URL : "https://foo.com/path?abc=123 " ,
30
30
Output : ResponseData {"access_token" : "12345" , "state" : state },
31
31
RedirectInFragment : true ,
32
- ExpectedURL : "https://foo.com/path#access_token=12345&state=%7B%22then%22%3A+%22%2Findex.html%3Fa%3D1%26b%3D%252B%23fragment%22%2C+%22nonce%22%3A+%22014f%3Abff9a07c%22%7D" ,
32
+ ExpectedURL : "https://foo.com/path?abc=123 #access_token=12345&state=%7B%22then%22%3A+%22%2Findex.html%3Fa%3D1%26b%3D%252B%23fragment%22%2C+%22nonce%22%3A+%22014f%3Abff9a07c%22%7D" ,
33
33
},
34
34
}
35
35
You can’t perform that action at this time.
0 commit comments