Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
//
// Security:
// - BasicAuth :
// - ReverseProxyAuth :
// - Token :
// - AccessToken :
// - AuthorizationHeaderToken :
Expand All @@ -32,6 +33,9 @@
// SecurityDefinitions:
// BasicAuth:
// type: basic
// ReverseProxyAuth:
// type: reverseProxy
// description: Reverse proxy auth using HTTP header.
// Token:
// type: apiKey
// name: token
Expand Down Expand Up @@ -59,7 +63,7 @@
// type: apiKey
// name: X-GITEA-OTP
// in: header
// description: Must be used in combination with BasicAuth if two-factor authentication is enabled.
// description: Must be used in combination with BasicOrReverseProxyAuth if two-factor authentication is enabled.
//
// swagger:meta
package v1
Expand Down Expand Up @@ -212,10 +216,13 @@ func reqExploreSignIn() func(ctx *context.APIContext) {
}
}

func reqBasicAuth() func(ctx *context.APIContext) {
func reqBasicOrRevProxyAuth() func(ctx *context.APIContext) {
return func(ctx *context.APIContext) {
if ctx.IsSigned && setting.Service.EnableReverseProxyAuth {
return
}
if !ctx.Context.IsBasicAuth {
ctx.Error(http.StatusUnauthorized, "reqBasicAuth", "basic auth required")
ctx.Error(http.StatusUnauthorized, "reqBasicOrRevProxyAuth", "auth required")
return
}
ctx.CheckForOTP()
Expand Down Expand Up @@ -625,7 +632,7 @@ func Routes() *web.Route {
m.Combo("").Get(user.ListAccessTokens).
Post(bind(api.CreateAccessTokenOption{}), user.CreateAccessToken)
m.Combo("/{id}").Delete(user.DeleteAccessToken)
}, reqBasicAuth())
}, reqBasicOrRevProxyAuth())
})
})

Expand Down