Skip to content

Commit 9900b1d

Browse files
committed
some improvements
1 parent 5de17ab commit 9900b1d

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

routers/api/v1/api.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,8 @@ func bind(obj interface{}) http.HandlerFunc {
569569
func buildAuthGroup() *auth.Group {
570570
group := auth.NewGroup(
571571
&auth.OAuth2{},
572-
&auth.Basic{},
573-
auth.SharedSession,
572+
&auth.Basic{}, // FIXME: this should be removed once we don't allow basic auth in API
573+
auth.SharedSession, // FIXME: this should be removed once all UI don't reference API/v1, see https://github.com/go-gitea/gitea/pull/16052
574574
)
575575
if setting.Service.EnableReverseProxyAuth {
576576
group.Add(&auth.ReverseProxy{})
@@ -600,8 +600,13 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route {
600600
}
601601
m.Use(context.APIContexter())
602602

603+
group := buildAuthGroup()
604+
if err := group.Init(); err != nil {
605+
log.Error("Could not initialize '%s' auth method, error: %s", group.Name(), err)
606+
}
607+
603608
// Get user from session if logged in.
604-
m.Use(context.APIAuth(buildAuthGroup()))
609+
m.Use(context.APIAuth(group))
605610

606611
m.Use(context.ToggleAPI(&context.ToggleOptions{
607612
SignInRequired: setting.Service.RequireSignInView,

routers/web/web.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ func CorsHandler() func(next http.Handler) http.Handler {
7979
// for users that have already signed in.
8080
func buildAuthGroup() *auth_service.Group {
8181
group := auth_service.NewGroup(
82-
&auth_service.OAuth2{},
83-
&auth_service.Basic{},
82+
&auth_service.OAuth2{}, // FIXME: this should be removed and only applied in download and oauth realted routers
83+
&auth_service.Basic{}, // FIXME: this should be removed and only applied in download and git/lfs routers
8484
auth_service.SharedSession,
8585
)
8686
if setting.Service.EnableReverseProxyAuth {

services/auth/auth.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var (
2626
_ = handleSignIn
2727

2828
// SharedSession the session auth should only be used by web, but now both web and API/v1
29-
// will use it. We can remvoe this after Web removed dependent API/v1
29+
// will use it. We can remove this after Web removed dependent API/v1
3030
SharedSession = &Session{}
3131
)
3232

0 commit comments

Comments
 (0)