Skip to content

Commit ee1c07b

Browse files
committed
fix: accept code for PKCE token exchange
1 parent be317c1 commit ee1c07b

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

internal/api/token.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type PasswordGrantParams struct {
3030
// PKCEGrantParams are the parameters the PKCEGrant method accepts
3131
type PKCEGrantParams struct {
3232
AuthCode string `json:"auth_code"`
33+
Code string `json:"code"`
3334
CodeVerifier string `json:"code_verifier"`
3435
}
3536

@@ -227,11 +228,16 @@ func (a *API) PKCE(ctx context.Context, w http.ResponseWriter, r *http.Request)
227228
return err
228229
}
229230

230-
if params.AuthCode == "" || params.CodeVerifier == "" {
231+
authCode := params.Code
232+
if authCode == "" {
233+
authCode = params.AuthCode
234+
}
235+
236+
if authCode == "" || params.CodeVerifier == "" {
231237
return apierrors.NewBadRequestError(apierrors.ErrorCodeValidationFailed, "invalid request: both auth code and code verifier should be non-empty")
232238
}
233239

234-
flowState, err := models.FindFlowStateByAuthCode(db, params.AuthCode)
240+
flowState, err := models.FindFlowStateByAuthCode(db, authCode)
235241
// Sanity check in case user ID was not set properly
236242
if models.IsNotFoundError(err) || flowState.UserID == nil {
237243
return apierrors.NewNotFoundError(apierrors.ErrorCodeFlowStateNotFound, "invalid flow state, no valid flow state found")

internal/api/token_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ func (ts *TokenTestSuite) TestMagicLinkPKCESignIn() {
620620
// Extract token and sign in
621621
require.NoError(ts.T(), json.NewEncoder(&buffer).Encode(map[string]interface{}{
622622
"code_verifier": codeVerifier,
623-
"auth_code": authCode,
623+
"code": authCode,
624624
}))
625625
req = httptest.NewRequest(http.MethodPost, "http://localhost/token?grant_type=pkce", &buffer)
626626
req.Header.Set("Content-Type", "application/json")

openapi.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ paths:
9999
refresh_token: 4nYUCw0wZR_DNOTSDbSGMQ
100100
grant_type=pkce:
101101
value:
102-
auth_code: 009e5066-fc11-4eca-8c8c-6fd82aa263f2
102+
code: 009e5066-fc11-4eca-8c8c-6fd82aa263f2
103103
code_verifier: ktPNXpR65N6JtgzQA8_5HHtH6PBSAahMNoLKRzQEa0Tzgl.vdV~b6lPk004XOd.4lR0inCde.NoQx5K63xPfzL8o7tJAjXncnhw5Niv9ycQ.QRV9JG.y3VapqbgLfIrJ
104104
web3_solana:
105105
value:
@@ -151,9 +151,15 @@ paths:
151151
description: If `provider` is `azure` then you can specify any Azure OIDC issuer string here, which will be used for verification.
152152
gotrue_meta_security:
153153
$ref: "#/components/schemas/GoTrueSecurity"
154+
code:
155+
type: string
156+
format: uuid
157+
description: Authorization code returned in the PKCE redirect URL.
154158
auth_code:
155159
type: string
156160
format: uuid
161+
deprecated: true
162+
description: Deprecated alias for `code`.
157163
code_verifier:
158164
type: string
159165
message:

0 commit comments

Comments
 (0)