Skip to content

Commit d7f3ccb

Browse files
committed
Address review comments
Require PKCE for public clients
1 parent 5efd05e commit d7f3ccb

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

models/auth/oauth2.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ type OAuth2Application struct {
3131
Name string
3232
ClientID string `xorm:"unique"`
3333
ClientSecret string
34+
// OAuth defines both Confidential and Public client types
3435
// https://datatracker.ietf.org/doc/html/rfc6749#section-2.1
36+
// "Authorization servers MUST record the client type in the client registration details"
37+
// https://datatracker.ietf.org/doc/html/rfc8252#section-8.4
3538
Confidential bool `xorm:"NOT NULL DEFAULT TRUE"`
3639
RedirectURIs []string `xorm:"redirect_uris JSON TEXT"`
3740
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`

routers/web/auth/oauth.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,21 @@ func AuthorizeOAuth(ctx *context.Context) {
430430
log.Error("Unable to save changes to the session: %v", err)
431431
}
432432
case "":
433-
break
433+
// "Authorization servers SHOULD reject authorization requests from native apps that don't use PKCE by returning an error message"
434+
// https://datatracker.ietf.org/doc/html/rfc8252#section-8.1
435+
if !app.Confidential {
436+
// "the authorization endpoint MUST return the authorization error response with the "error" value set to "invalid_request""
437+
// https://datatracker.ietf.org/doc/html/rfc7636#section-4.4.1
438+
handleAuthorizeError(ctx, AuthorizeError{
439+
ErrorCode: ErrorCodeInvalidRequest,
440+
ErrorDescription: "",
441+
State: form.State,
442+
}, form.RedirectURI)
443+
}
444+
return
434445
default:
446+
// "If the server supporting PKCE does not support the requested transformation, the authorization endpoint MUST return the authorization error response with "error" value set to "invalid_request"."
447+
// https://www.rfc-editor.org/rfc/rfc7636#section-4.4.1
435448
handleAuthorizeError(ctx, AuthorizeError{
436449
ErrorCode: ErrorCodeInvalidRequest,
437450
ErrorDescription: "unsupported code challenge method",
@@ -685,7 +698,7 @@ func handleAuthorizationCode(ctx *context.Context, form forms.AccessTokenForm, s
685698
})
686699
return
687700
}
688-
if app.Confidential && !app.ValidateClientSecret([]byte(form.ClientSecret)) {
701+
if !app.ValidateClientSecret([]byte(form.ClientSecret)) {
689702
handleAccessTokenError(ctx, AccessTokenError{
690703
ErrorCode: AccessTokenErrorCodeUnauthorizedClient,
691704
ErrorDescription: "invalid client secret",

0 commit comments

Comments
 (0)