Add sso.Group, context.Auth, context.APIAuth to allow auth special routes (#16086)
* Add sso.Group, context.Auth, context.APIAuth to allow auth special routes * Remove unnecessary check * Rename sso -> auth * remove unused method of Auth interface
This commit is contained in:
parent
da057996d5
commit
fb3ffeb18d
19 changed files with 286 additions and 220 deletions
|
@ -83,6 +83,7 @@ import (
|
|||
"code.gitea.io/gitea/routers/api/v1/settings"
|
||||
_ "code.gitea.io/gitea/routers/api/v1/swagger" // for swagger generation
|
||||
"code.gitea.io/gitea/routers/api/v1/user"
|
||||
"code.gitea.io/gitea/services/auth"
|
||||
"code.gitea.io/gitea/services/forms"
|
||||
|
||||
"gitea.com/go-chi/binding"
|
||||
|
@ -573,6 +574,9 @@ func Routes() *web.Route {
|
|||
}
|
||||
m.Use(context.APIContexter())
|
||||
|
||||
// Get user from session if logged in.
|
||||
m.Use(context.APIAuth(auth.NewGroup(auth.Methods()...)))
|
||||
|
||||
m.Use(context.ToggleAPI(&context.ToggleOptions{
|
||||
SignInRequired: setting.Service.RequireSignInView,
|
||||
}))
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/auth/sso"
|
||||
"code.gitea.io/gitea/modules/cache"
|
||||
"code.gitea.io/gitea/modules/cron"
|
||||
"code.gitea.io/gitea/modules/eventsource"
|
||||
|
@ -34,6 +33,7 @@ import (
|
|||
"code.gitea.io/gitea/routers/common"
|
||||
"code.gitea.io/gitea/routers/private"
|
||||
web_routers "code.gitea.io/gitea/routers/web"
|
||||
"code.gitea.io/gitea/services/auth"
|
||||
"code.gitea.io/gitea/services/mailer"
|
||||
mirror_service "code.gitea.io/gitea/services/mirror"
|
||||
pull_service "code.gitea.io/gitea/services/pull"
|
||||
|
@ -134,7 +134,7 @@ func GlobalInit(ctx context.Context) {
|
|||
} else {
|
||||
ssh.Unused()
|
||||
}
|
||||
sso.Init()
|
||||
auth.Init()
|
||||
|
||||
svg.Init()
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/auth/sso"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/httpcache"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
|
@ -23,6 +22,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/storage"
|
||||
"code.gitea.io/gitea/modules/templates"
|
||||
"code.gitea.io/gitea/modules/web/middleware"
|
||||
"code.gitea.io/gitea/services/auth"
|
||||
|
||||
"gitea.com/go-chi/session"
|
||||
)
|
||||
|
@ -158,7 +158,7 @@ func Recovery() func(next http.Handler) http.Handler {
|
|||
}
|
||||
if user == nil {
|
||||
// Get user from session if logged in - do not attempt to sign-in
|
||||
user = sso.SessionUser(sessionStore)
|
||||
user = auth.SessionUser(sessionStore)
|
||||
}
|
||||
if user != nil {
|
||||
store["IsSigned"] = true
|
||||
|
|
|
@ -13,13 +13,13 @@ import (
|
|||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/auth/sso"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/services/auth"
|
||||
"code.gitea.io/gitea/services/forms"
|
||||
|
||||
"gitea.com/go-chi/binding"
|
||||
|
@ -228,7 +228,7 @@ func InfoOAuth(ctx *context.Context) {
|
|||
ctx.HandleText(http.StatusUnauthorized, "no valid auth token authorization")
|
||||
return
|
||||
}
|
||||
uid := sso.CheckOAuthAccessToken(auths[1])
|
||||
uid := auth.CheckOAuthAccessToken(auths[1])
|
||||
if uid == 0 {
|
||||
handleBearerTokenError(ctx, BearerTokenError{
|
||||
ErrorCode: BearerTokenErrorCodeInvalidToken,
|
||||
|
|
|
@ -31,6 +31,7 @@ import (
|
|||
"code.gitea.io/gitea/routers/web/repo"
|
||||
"code.gitea.io/gitea/routers/web/user"
|
||||
userSetting "code.gitea.io/gitea/routers/web/user/setting"
|
||||
"code.gitea.io/gitea/services/auth"
|
||||
"code.gitea.io/gitea/services/forms"
|
||||
"code.gitea.io/gitea/services/lfs"
|
||||
"code.gitea.io/gitea/services/mailer"
|
||||
|
@ -149,6 +150,9 @@ func Routes() *web.Route {
|
|||
// Removed: toolbox.Toolboxer middleware will provide debug informations which seems unnecessary
|
||||
common = append(common, context.Contexter())
|
||||
|
||||
// Get user from session if logged in.
|
||||
common = append(common, context.Auth(auth.NewGroup(auth.Methods()...)))
|
||||
|
||||
// GetHead allows a HEAD request redirect to GET if HEAD method is not defined for that route
|
||||
common = append(common, middleware.GetHead)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue