Skip to content
This repository was archived by the owner on Sep 11, 2018. It is now read-only.

Commit 366c7fd

Browse files
fodawimdlebech
authored andcommitted
Fix oauth when state (or other params) contain values that would be url encoded. (#64)
1 parent 3fbf10b commit 366c7fd

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

oauth.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,17 @@ func (app App) VerifyMessage(message, messageMAC string) bool {
6565
}
6666

6767
// Verifying URL callback parameters.
68-
func (app App) VerifyAuthorizationURL(u *url.URL) bool {
68+
func (app App) VerifyAuthorizationURL(u *url.URL) (bool, error) {
6969
q := u.Query()
7070
messageMAC := q.Get("hmac")
7171

7272
// Remove hmac and signature and leave the rest of the parameters alone.
7373
q.Del("hmac")
7474
q.Del("signature")
7575

76-
message := q.Encode()
76+
message, err := url.QueryUnescape(q.Encode())
7777

78-
return app.VerifyMessage(message, messageMAC)
78+
return app.VerifyMessage(message, messageMAC), err
7979
}
8080

8181
// Verifies a webhook http request, sent by Shopify.

oauth_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,16 @@ func TestAppVerifyAuthorizationURL(t *testing.T) {
6363
}
6464

6565
for _, c := range cases {
66-
actual := app.VerifyAuthorizationURL(c.u)
66+
actual, err := app.VerifyAuthorizationURL(c.u)
67+
if err != nil {
68+
t.Errorf("App.VerifyAuthorizationURL(..., %s) returned an error:", c.u, err)
69+
}
6770
if actual != c.expected {
6871
t.Errorf("App.VerifyAuthorizationURL(..., %s): expected %v, actual %v", c.u, c.expected, actual)
6972
}
7073
}
7174
}
7275

73-
7476
func TestVerifyWebhookRequest(t *testing.T) {
7577
setup()
7678
defer teardown()

0 commit comments

Comments
 (0)