Skip to content

Commit 3b141e1

Browse files
committed
Rename sso -> auth
1 parent 558b2fc commit 3b141e1

File tree

16 files changed

+56
-56
lines changed

16 files changed

+56
-56
lines changed

modules/context/api.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import (
1414
"strings"
1515

1616
"code.gitea.io/gitea/models"
17-
"code.gitea.io/gitea/modules/auth/sso"
1817
"code.gitea.io/gitea/modules/git"
1918
"code.gitea.io/gitea/modules/log"
2019
"code.gitea.io/gitea/modules/setting"
2120
"code.gitea.io/gitea/modules/web/middleware"
21+
"code.gitea.io/gitea/services/auth"
2222

2323
"gitea.com/go-chi/session"
2424
)
@@ -217,16 +217,16 @@ func (ctx *APIContext) CheckForOTP() {
217217
}
218218
}
219219

220-
// APIAuth converts sso.SingleSignOn as a middleware
221-
func APIAuth(authMethod sso.SingleSignOn) func(*APIContext) {
220+
// APIAuth converts auth.Auth as a middleware
221+
func APIAuth(authMethod auth.Auth) func(*APIContext) {
222222
return func(ctx *APIContext) {
223223
if !authMethod.IsEnabled() {
224224
return
225225
}
226226
// Get user from session if logged in.
227227
ctx.User = authMethod.VerifyAuthData(ctx.Req, ctx.Resp, ctx, ctx.Session)
228228
if ctx.User != nil {
229-
ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == new(sso.Basic).Name()
229+
ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == new(auth.Basic).Name()
230230
ctx.IsSigned = true
231231
ctx.Data["IsSigned"] = ctx.IsSigned
232232
ctx.Data["SignedUser"] = ctx.User

modules/context/context.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ import (
2121
"time"
2222

2323
"code.gitea.io/gitea/models"
24-
"code.gitea.io/gitea/modules/auth/sso"
2524
"code.gitea.io/gitea/modules/base"
2625
mc "code.gitea.io/gitea/modules/cache"
2726
"code.gitea.io/gitea/modules/log"
2827
"code.gitea.io/gitea/modules/setting"
2928
"code.gitea.io/gitea/modules/templates"
3029
"code.gitea.io/gitea/modules/translation"
3130
"code.gitea.io/gitea/modules/web/middleware"
31+
"code.gitea.io/gitea/services/auth"
3232

3333
"gitea.com/go-chi/cache"
3434
"gitea.com/go-chi/session"
@@ -605,16 +605,16 @@ func getCsrfOpts() CsrfOptions {
605605
}
606606
}
607607

608-
// Auth converts sso.SingleSignOn as a middleware
609-
func Auth(authMethod sso.SingleSignOn) func(*Context) {
608+
// Auth converts auth.Auth as a middleware
609+
func Auth(authMethod auth.Auth) func(*Context) {
610610
return func(ctx *Context) {
611611
if !authMethod.IsEnabled() {
612612
return
613613
}
614614

615615
ctx.User = authMethod.VerifyAuthData(ctx.Req, ctx.Resp, ctx, ctx.Session)
616616
if ctx.User != nil {
617-
ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == new(sso.Basic).Name()
617+
ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == new(auth.Basic).Name()
618618
ctx.IsSigned = true
619619
ctx.Data["IsSigned"] = ctx.IsSigned
620620
ctx.Data["SignedUser"] = ctx.User

routers/api/v1/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ import (
7070
"strings"
7171

7272
"code.gitea.io/gitea/models"
73-
"code.gitea.io/gitea/modules/auth/sso"
7473
"code.gitea.io/gitea/modules/context"
7574
"code.gitea.io/gitea/modules/log"
7675
"code.gitea.io/gitea/modules/setting"
@@ -84,6 +83,7 @@ import (
8483
"code.gitea.io/gitea/routers/api/v1/settings"
8584
_ "code.gitea.io/gitea/routers/api/v1/swagger" // for swagger generation
8685
"code.gitea.io/gitea/routers/api/v1/user"
86+
"code.gitea.io/gitea/services/auth"
8787
"code.gitea.io/gitea/services/forms"
8888

8989
"gitea.com/go-chi/binding"
@@ -575,7 +575,7 @@ func Routes() *web.Route {
575575
m.Use(context.APIContexter())
576576

577577
// Get user from session if logged in.
578-
m.Use(context.APIAuth(sso.NewGroup(sso.Methods()...)))
578+
m.Use(context.APIAuth(auth.NewGroup(auth.Methods()...)))
579579

580580
m.Use(context.ToggleAPI(&context.ToggleOptions{
581581
SignInRequired: setting.Service.RequireSignInView,

routers/init.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"strings"
1010

1111
"code.gitea.io/gitea/models"
12-
"code.gitea.io/gitea/modules/auth/sso"
1312
"code.gitea.io/gitea/modules/cache"
1413
"code.gitea.io/gitea/modules/cron"
1514
"code.gitea.io/gitea/modules/eventsource"
@@ -34,6 +33,7 @@ import (
3433
"code.gitea.io/gitea/routers/common"
3534
"code.gitea.io/gitea/routers/private"
3635
web_routers "code.gitea.io/gitea/routers/web"
36+
"code.gitea.io/gitea/services/auth"
3737
"code.gitea.io/gitea/services/mailer"
3838
mirror_service "code.gitea.io/gitea/services/mirror"
3939
pull_service "code.gitea.io/gitea/services/pull"
@@ -134,7 +134,7 @@ func GlobalInit(ctx context.Context) {
134134
} else {
135135
ssh.Unused()
136136
}
137-
sso.Init()
137+
auth.Init()
138138

139139
svg.Init()
140140
}

routers/web/base.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ import (
1515
"strings"
1616

1717
"code.gitea.io/gitea/models"
18-
"code.gitea.io/gitea/modules/auth/sso"
1918
"code.gitea.io/gitea/modules/context"
2019
"code.gitea.io/gitea/modules/httpcache"
2120
"code.gitea.io/gitea/modules/log"
2221
"code.gitea.io/gitea/modules/setting"
2322
"code.gitea.io/gitea/modules/storage"
2423
"code.gitea.io/gitea/modules/templates"
2524
"code.gitea.io/gitea/modules/web/middleware"
25+
"code.gitea.io/gitea/services/auth"
2626

2727
"gitea.com/go-chi/session"
2828
)
@@ -158,7 +158,7 @@ func Recovery() func(next http.Handler) http.Handler {
158158
}
159159
if user == nil {
160160
// Get user from session if logged in - do not attempt to sign-in
161-
user = sso.SessionUser(sessionStore)
161+
user = auth.SessionUser(sessionStore)
162162
}
163163
if user != nil {
164164
store["IsSigned"] = true

routers/web/user/oauth.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import (
1313
"strings"
1414

1515
"code.gitea.io/gitea/models"
16-
"code.gitea.io/gitea/modules/auth/sso"
1716
"code.gitea.io/gitea/modules/base"
1817
"code.gitea.io/gitea/modules/context"
1918
"code.gitea.io/gitea/modules/log"
2019
"code.gitea.io/gitea/modules/setting"
2120
"code.gitea.io/gitea/modules/timeutil"
2221
"code.gitea.io/gitea/modules/web"
22+
"code.gitea.io/gitea/services/auth"
2323
"code.gitea.io/gitea/services/forms"
2424

2525
"gitea.com/go-chi/binding"
@@ -228,7 +228,7 @@ func InfoOAuth(ctx *context.Context) {
228228
ctx.HandleText(http.StatusUnauthorized, "no valid auth token authorization")
229229
return
230230
}
231-
uid := sso.CheckOAuthAccessToken(auths[1])
231+
uid := auth.CheckOAuthAccessToken(auths[1])
232232
if uid == 0 {
233233
handleBearerTokenError(ctx, BearerTokenError{
234234
ErrorCode: BearerTokenErrorCodeInvalidToken,

routers/web/web.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"path"
1212

1313
"code.gitea.io/gitea/models"
14-
"code.gitea.io/gitea/modules/auth/sso"
1514
"code.gitea.io/gitea/modules/context"
1615
"code.gitea.io/gitea/modules/httpcache"
1716
"code.gitea.io/gitea/modules/log"
@@ -32,6 +31,7 @@ import (
3231
"code.gitea.io/gitea/routers/web/repo"
3332
"code.gitea.io/gitea/routers/web/user"
3433
userSetting "code.gitea.io/gitea/routers/web/user/setting"
34+
"code.gitea.io/gitea/services/auth"
3535
"code.gitea.io/gitea/services/forms"
3636
"code.gitea.io/gitea/services/lfs"
3737
"code.gitea.io/gitea/services/mailer"
@@ -151,7 +151,7 @@ func Routes() *web.Route {
151151
common = append(common, context.Contexter())
152152

153153
// Get user from session if logged in.
154-
common = append(common, context.Auth(sso.NewGroup(sso.Methods()...)))
154+
common = append(common, context.Auth(auth.NewGroup(auth.Methods()...)))
155155

156156
// GetHead allows a HEAD request redirect to GET if HEAD method is not defined for that route
157157
common = append(common, middleware.GetHead)

modules/auth/sso/sso.go renamed to services/auth/auth.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Use of this source code is governed by a MIT-style
44
// license that can be found in the LICENSE file.
55

6-
package sso
6+
package auth
77

88
import (
99
"fmt"
@@ -18,7 +18,7 @@ import (
1818
"code.gitea.io/gitea/modules/web/middleware"
1919
)
2020

21-
// ssoMethods contains the list of SSO authentication plugins in the order they are expected to be
21+
// authMethods contains the list of authentication plugins in the order they are expected to be
2222
// executed.
2323
//
2424
// The OAuth2 plugin is expected to be executed first, as it must ignore the user id stored
@@ -27,7 +27,7 @@ import (
2727
//
2828
// The Session plugin is expected to be executed second, in order to skip authentication
2929
// for users that have already signed in.
30-
var ssoMethods = []SingleSignOn{
30+
var authMethods = []Auth{
3131
&OAuth2{},
3232
&Basic{},
3333
&Session{},
@@ -40,34 +40,34 @@ var (
4040
_ = handleSignIn
4141
)
4242

43-
// Methods returns the instances of all registered SSO methods
44-
func Methods() []SingleSignOn {
45-
return ssoMethods
43+
// Methods returns the instances of all registered methods
44+
func Methods() []Auth {
45+
return authMethods
4646
}
4747

48-
// Register adds the specified instance to the list of available SSO methods
49-
func Register(method SingleSignOn) {
50-
ssoMethods = append(ssoMethods, method)
48+
// Register adds the specified instance to the list of available methods
49+
func Register(method Auth) {
50+
authMethods = append(authMethods, method)
5151
}
5252

53-
// Init should be called exactly once when the application starts to allow SSO plugins
53+
// Init should be called exactly once when the application starts to allow plugins
5454
// to allocate necessary resources
5555
func Init() {
5656
for _, method := range Methods() {
5757
err := method.Init()
5858
if err != nil {
59-
log.Error("Could not initialize '%s' SSO method, error: %s", reflect.TypeOf(method).String(), err)
59+
log.Error("Could not initialize '%s' auth method, error: %s", reflect.TypeOf(method).String(), err)
6060
}
6161
}
6262
}
6363

64-
// Free should be called exactly once when the application is terminating to allow SSO plugins
64+
// Free should be called exactly once when the application is terminating to allow Auth plugins
6565
// to release necessary resources
6666
func Free() {
6767
for _, method := range Methods() {
6868
err := method.Free()
6969
if err != nil {
70-
log.Error("Could not free '%s' SSO method, error: %s", reflect.TypeOf(method).String(), err)
70+
log.Error("Could not free '%s' auth method, error: %s", reflect.TypeOf(method).String(), err)
7171
}
7272
}
7373
}

modules/auth/sso/sso_test.go renamed to services/auth/auth_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Use of this source code is governed by a MIT-style
44
// license that can be found in the LICENSE file.
55

6-
package sso
6+
package auth
77

88
import (
99
"net/http"

modules/auth/sso/basic.go renamed to services/auth/basic.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Use of this source code is governed by a MIT-style
44
// license that can be found in the LICENSE file.
55

6-
package sso
6+
package auth
77

88
import (
99
"net/http"
@@ -19,10 +19,10 @@ import (
1919

2020
// Ensure the struct implements the interface.
2121
var (
22-
_ SingleSignOn = &Basic{}
22+
_ Auth = &Basic{}
2323
)
2424

25-
// Basic implements the SingleSignOn interface and authenticates requests (API requests
25+
// Basic implements the Auth interface and authenticates requests (API requests
2626
// only) by looking for Basic authentication data or "x-oauth-basic" token in the "Authorization"
2727
// header.
2828
type Basic struct {

modules/auth/sso/group.go renamed to services/auth/group.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5-
package sso
5+
package auth
66

77
import (
88
"net/http"
@@ -12,16 +12,16 @@ import (
1212

1313
// Ensure the struct implements the interface.
1414
var (
15-
_ SingleSignOn = &Group{}
15+
_ Auth = &Group{}
1616
)
1717

18-
// Group implements the SingleSignOn interface with serval SingleSignOn.
18+
// Group implements the Auth interface with serval Auth.
1919
type Group struct {
20-
methods []SingleSignOn
20+
methods []Auth
2121
}
2222

2323
// NewGroup creates a new auth group
24-
func NewGroup(methods ...SingleSignOn) *Group {
24+
func NewGroup(methods ...Auth) *Group {
2525
return &Group{
2626
methods: methods,
2727
}

modules/auth/sso/interface.go renamed to services/auth/interface.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5-
package sso
5+
package auth
66

77
import (
88
"net/http"
@@ -18,8 +18,8 @@ type DataStore middleware.DataStore
1818
// SessionStore represents a session store
1919
type SessionStore session.Store
2020

21-
// SingleSignOn represents a SSO authentication method (plugin) for HTTP requests.
22-
type SingleSignOn interface {
21+
// Auth represents an authentication method (plugin) for HTTP requests.
22+
type Auth interface {
2323
Name() string
2424

2525
// Init should be called exactly once before using any of the other methods,
@@ -30,10 +30,10 @@ type SingleSignOn interface {
3030
// give chance to the plugin to free any allocated resources
3131
Free() error
3232

33-
// IsEnabled checks if the current SSO method has been enabled in settings.
33+
// IsEnabled checks if the current auth method has been enabled in settings.
3434
IsEnabled() bool
3535

36-
// VerifyAuthData tries to verify the SSO authentication data contained in the request.
36+
// VerifyAuthData tries to verify the authentication data contained in the request.
3737
// If verification is successful returns either an existing user object (with id > 0)
3838
// or a new user object (with id = 0) populated with the information that was found
3939
// in the authentication data (username or email).

modules/auth/sso/oauth2.go renamed to services/auth/oauth2.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Use of this source code is governed by a MIT-style
44
// license that can be found in the LICENSE file.
55

6-
package sso
6+
package auth
77

88
import (
99
"net/http"
@@ -18,7 +18,7 @@ import (
1818

1919
// Ensure the struct implements the interface.
2020
var (
21-
_ SingleSignOn = &OAuth2{}
21+
_ Auth = &OAuth2{}
2222
)
2323

2424
// CheckOAuthAccessToken returns uid of user from oauth token
@@ -45,7 +45,7 @@ func CheckOAuthAccessToken(accessToken string) int64 {
4545
return grant.UserID
4646
}
4747

48-
// OAuth2 implements the SingleSignOn interface and authenticates requests
48+
// OAuth2 implements the Auth interface and authenticates requests
4949
// (API requests only) by looking for an OAuth token in query parameters or the
5050
// "Authorization" header.
5151
type OAuth2 struct {

0 commit comments

Comments
 (0)