Skip to content

Commit 0548399

Browse files
author
wintbiit
committed
fix: dont manually unescape queries
1 parent 97fd30d commit 0548399

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

core/sign_in.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ func GenerateSignInUri(option *SignInUriGenerationOptions) (string, error) {
9595
}
9696
}
9797

98-
unescapedQueries, unescapeQueryErr := url.QueryUnescape(queries.Encode())
99-
100-
if unescapeQueryErr != nil {
101-
return "", unescapeQueryErr
102-
}
103-
104-
return uri.String() + "?" + unescapedQueries, nil
98+
uri.RawQuery = queries.Encode()
99+
return uri.String(), nil
105100
}

core/sign_in_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
func TestGenerateSignInUriShouldGenerateCorrectUri(t *testing.T) {
10-
testSignInUri := "https://example.com/authorize?client_id=clientId&code_challenge=codeChallenge&code_challenge_method=S256&prompt=login&redirect_uri=https://example.com/callback&resource=resourceA&resource=resourceB&response_type=code&scope=openid offline_access profile&state=state"
10+
testSignInUri := "https://example.com/authorize?client_id=clientId&code_challenge=codeChallenge&code_challenge_method=S256&prompt=login&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback&resource=resourceA&resource=resourceB&response_type=code&scope=openid+offline_access+profile&state=state"
1111

1212
signInUri, generateSignInUriErr := GenerateSignInUri(&SignInUriGenerationOptions{
1313
AuthorizationEndpoint: "https://example.com/authorize",
@@ -25,7 +25,7 @@ func TestGenerateSignInUriShouldGenerateCorrectUri(t *testing.T) {
2525
}
2626

2727
func TestGenerateSignInUriShouldContainReservedScopesByDefault(t *testing.T) {
28-
testSignInUri := "https://example.com/authorize?client_id=clientId&code_challenge=codeChallenge&code_challenge_method=S256&prompt=consent&redirect_uri=https://example.com/callback&resource=resourceA&resource=resourceB&response_type=code&scope=openid offline_access profile&state=state"
28+
testSignInUri := "https://example.com/authorize?client_id=clientId&code_challenge=codeChallenge&code_challenge_method=S256&prompt=consent&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback&resource=resourceA&resource=resourceB&response_type=code&scope=openid+offline_access+profile&state=state"
2929

3030
signInUri, generateSignInUriErr := GenerateSignInUri(&SignInUriGenerationOptions{
3131
AuthorizationEndpoint: "https://example.com/authorize",
@@ -42,7 +42,7 @@ func TestGenerateSignInUriShouldContainReservedScopesByDefault(t *testing.T) {
4242
}
4343

4444
func TestGenerateSignInUriShouldContainReservedScopesAndExtraScopes(t *testing.T) {
45-
testSignInUri := "https://example.com/authorize?client_id=clientId&code_challenge=codeChallenge&code_challenge_method=S256&prompt=consent&redirect_uri=https://example.com/callback&resource=resourceA&resource=resourceB&response_type=code&scope=openid offline_access profile extra_scope&state=state"
45+
testSignInUri := "https://example.com/authorize?client_id=clientId&code_challenge=codeChallenge&code_challenge_method=S256&prompt=consent&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback&resource=resourceA&resource=resourceB&response_type=code&scope=openid+offline_access+profile+extra_scope&state=state"
4646

4747
signInUri, generateSignInUriErr := GenerateSignInUri(&SignInUriGenerationOptions{
4848
AuthorizationEndpoint: "https://example.com/authorize",
@@ -60,7 +60,7 @@ func TestGenerateSignInUriShouldContainReservedScopesAndExtraScopes(t *testing.T
6060
}
6161

6262
func TestGenerateSignInUriShouldGenerateUriWithConsentAsThePromptValue(t *testing.T) {
63-
testSignInUri := "https://example.com/authorize?client_id=clientId&code_challenge=codeChallenge&code_challenge_method=S256&prompt=consent&redirect_uri=https://example.com/callback&resource=resourceA&resource=resourceB&response_type=code&scope=openid offline_access profile&state=state"
63+
testSignInUri := "https://example.com/authorize?client_id=clientId&code_challenge=codeChallenge&code_challenge_method=S256&prompt=consent&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback&resource=resourceA&resource=resourceB&response_type=code&scope=openid+offline_access+profile&state=state"
6464

6565
signInUri, generateSignInUriErr := GenerateSignInUri(&SignInUriGenerationOptions{
6666
AuthorizationEndpoint: "https://example.com/authorize",
@@ -77,7 +77,7 @@ func TestGenerateSignInUriShouldGenerateUriWithConsentAsThePromptValue(t *testin
7777
}
7878

7979
func TestGenerateSignInUriShouldNotContainResourcesIfNoResourcesAreProvided(t *testing.T) {
80-
testSignInUri := "https://example.com/authorize?client_id=clientId&code_challenge=codeChallenge&code_challenge_method=S256&prompt=consent&redirect_uri=https://example.com/callback&response_type=code&scope=openid offline_access profile&state=state"
80+
testSignInUri := "https://example.com/authorize?client_id=clientId&code_challenge=codeChallenge&code_challenge_method=S256&prompt=consent&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback&response_type=code&scope=openid+offline_access+profile&state=state"
8181

8282
signInUri, generateSignInUriErr := GenerateSignInUri(&SignInUriGenerationOptions{
8383
AuthorizationEndpoint: "https://example.com/authorize",

0 commit comments

Comments
 (0)