Skip to content

Commit c363ef5

Browse files
authored
Add json tags for oauth2 form (#6627) (#6641)
(cherry picked from commit 62d3f49) Signed-off-by: Jonas Franz <[email protected]>
1 parent e8ca2da commit c363ef5

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

integrations/oauth_test.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,30 @@ func TestAccessTokenExchange(t *testing.T) {
7575

7676
func TestAccessTokenExchangeWithoutPKCE(t *testing.T) {
7777
prepareTestEnv(t)
78-
req := NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{
78+
req := NewRequestWithJSON(t, "POST", "/login/oauth/access_token", map[string]string{
79+
"grant_type": "authorization_code",
80+
"client_id": "da7da3ba-9a13-4167-856f-3899de0b0138",
81+
"client_secret": "4MK8Na6R55smdCY0WuCCumZ6hjRPnGY5saWVRHHjJiA=",
82+
"redirect_uri": "a",
83+
"code": "authcode",
84+
"code_verifier": "N1Zo9-8Rfwhkt68r1r29ty8YwIraXR8eh_1Qwxg7yQXsonBt", // test PKCE additionally
85+
})
86+
resp := MakeRequest(t, req, 200)
87+
type response struct {
88+
AccessToken string `json:"access_token"`
89+
TokenType string `json:"token_type"`
90+
ExpiresIn int64 `json:"expires_in"`
91+
RefreshToken string `json:"refresh_token"`
92+
}
93+
parsed := new(response)
94+
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed))
95+
assert.True(t, len(parsed.AccessToken) > 10)
96+
assert.True(t, len(parsed.RefreshToken) > 10)
97+
}
98+
99+
func TestAccessTokenExchangeJSON(t *testing.T) {
100+
prepareTestEnv(t)
101+
req := NewRequestWithJSON(t, "POST", "/login/oauth/access_token", map[string]string{
79102
"grant_type": "authorization_code",
80103
"client_id": "da7da3ba-9a13-4167-856f-3899de0b0138",
81104
"client_secret": "4MK8Na6R55smdCY0WuCCumZ6hjRPnGY5saWVRHHjJiA=",

modules/auth/user_form.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,15 @@ func (f *GrantApplicationForm) Validate(ctx *macaron.Context, errs binding.Error
168168

169169
// AccessTokenForm for issuing access tokens from authorization codes or refresh tokens
170170
type AccessTokenForm struct {
171-
GrantType string
172-
ClientID string
173-
ClientSecret string
174-
RedirectURI string
175-
Code string
176-
RefreshToken string
171+
GrantType string `json:"grant_type"`
172+
ClientID string `json:"client_id"`
173+
ClientSecret string `json:"client_secret"`
174+
RedirectURI string `json:"redirect_uri"`
175+
Code string `json:"code"`
176+
RefreshToken string `json:"refresh_token"`
177177

178178
// PKCE support
179-
CodeVerifier string
179+
CodeVerifier string `json:"code_verifier"`
180180
}
181181

182182
// Validate valideates the fields

0 commit comments

Comments
 (0)