Skip to content

Commit d094cea

Browse files
committed
Clean up oauth2 providers
Signed-off-by: Andrew Thornton <[email protected]>
1 parent 6a33b29 commit d094cea

File tree

14 files changed

+504
-260
lines changed

14 files changed

+504
-260
lines changed

routers/web/admin/auths.go

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ func NewAuthSource(ctx *context.Context) {
9898
ctx.Data["AuthSources"] = authSources
9999
ctx.Data["SecurityProtocols"] = securityProtocols
100100
ctx.Data["SMTPAuths"] = smtp.Authenticators
101-
ctx.Data["OAuth2Providers"] = oauth2.Providers
102-
ctx.Data["OAuth2DefaultCustomURLMappings"] = oauth2.DefaultCustomURLMappings
101+
oauth2providers := oauth2.GetOAuth2Providers()
102+
ctx.Data["OAuth2Providers"] = oauth2providers
103103

104104
ctx.Data["SSPIAutoCreateUsers"] = true
105105
ctx.Data["SSPIAutoActivateUsers"] = true
@@ -108,10 +108,7 @@ func NewAuthSource(ctx *context.Context) {
108108
ctx.Data["SSPIDefaultLanguage"] = ""
109109

110110
// only the first as default
111-
for key := range oauth2.Providers {
112-
ctx.Data["oauth2_provider"] = key
113-
break
114-
}
111+
ctx.Data["oauth2_provider"] = oauth2providers[0]
115112

116113
ctx.HTML(http.StatusOK, tplAuthNew)
117114
}
@@ -220,8 +217,8 @@ func NewAuthSourcePost(ctx *context.Context) {
220217
ctx.Data["AuthSources"] = authSources
221218
ctx.Data["SecurityProtocols"] = securityProtocols
222219
ctx.Data["SMTPAuths"] = smtp.Authenticators
223-
ctx.Data["OAuth2Providers"] = oauth2.Providers
224-
ctx.Data["OAuth2DefaultCustomURLMappings"] = oauth2.DefaultCustomURLMappings
220+
oauth2providers := oauth2.GetOAuth2Providers()
221+
ctx.Data["OAuth2Providers"] = oauth2providers
225222

226223
ctx.Data["SSPIAutoCreateUsers"] = true
227224
ctx.Data["SSPIAutoActivateUsers"] = true
@@ -299,8 +296,8 @@ func EditAuthSource(ctx *context.Context) {
299296

300297
ctx.Data["SecurityProtocols"] = securityProtocols
301298
ctx.Data["SMTPAuths"] = smtp.Authenticators
302-
ctx.Data["OAuth2Providers"] = oauth2.Providers
303-
ctx.Data["OAuth2DefaultCustomURLMappings"] = oauth2.DefaultCustomURLMappings
299+
oauth2providers := oauth2.GetOAuth2Providers()
300+
ctx.Data["OAuth2Providers"] = oauth2providers
304301

305302
source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid"))
306303
if err != nil {
@@ -311,7 +308,17 @@ func EditAuthSource(ctx *context.Context) {
311308
ctx.Data["HasTLS"] = source.HasTLS()
312309

313310
if source.IsOAuth2() {
314-
ctx.Data["CurrentOAuth2Provider"] = oauth2.Providers[source.Cfg.(*oauth2.Source).Provider]
311+
type Named interface {
312+
Name() string
313+
}
314+
315+
for _, provider := range oauth2providers {
316+
if provider.Name() == source.Cfg.(Named).Name() {
317+
ctx.Data["CurrentOAuth2Provider"] = provider
318+
break
319+
}
320+
}
321+
315322
}
316323
ctx.HTML(http.StatusOK, tplAuthEdit)
317324
}
@@ -324,8 +331,8 @@ func EditAuthSourcePost(ctx *context.Context) {
324331
ctx.Data["PageIsAdminAuthentications"] = true
325332

326333
ctx.Data["SMTPAuths"] = smtp.Authenticators
327-
ctx.Data["OAuth2Providers"] = oauth2.Providers
328-
ctx.Data["OAuth2DefaultCustomURLMappings"] = oauth2.DefaultCustomURLMappings
334+
oauth2providers := oauth2.GetOAuth2Providers()
335+
ctx.Data["OAuth2Providers"] = oauth2providers
329336

330337
source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid"))
331338
if err != nil {

routers/web/user/setting/security.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"code.gitea.io/gitea/modules/base"
1313
"code.gitea.io/gitea/modules/context"
1414
"code.gitea.io/gitea/modules/setting"
15-
"code.gitea.io/gitea/services/auth/source/oauth2"
1615
)
1716

1817
const (
@@ -92,9 +91,19 @@ func loadSecurityData(ctx *context.Context) {
9291
for _, externalAccount := range accountLinks {
9392
if loginSource, err := models.GetLoginSourceByID(externalAccount.LoginSourceID); err == nil {
9493
var providerDisplayName string
95-
if loginSource.IsOAuth2() {
96-
providerTechnicalName := loginSource.Cfg.(*oauth2.Source).Provider
97-
providerDisplayName = oauth2.Providers[providerTechnicalName].DisplayName
94+
95+
type DisplayNamed interface {
96+
DisplayName() string
97+
}
98+
99+
type Named interface {
100+
Name() string
101+
}
102+
103+
if displayNamed, ok := loginSource.Cfg.(DisplayNamed); ok {
104+
providerDisplayName = displayNamed.DisplayName()
105+
} else if named, ok := loginSource.Cfg.(Named); ok {
106+
providerDisplayName = named.Name()
98107
} else {
99108
providerDisplayName = loginSource.Name
100109
}

0 commit comments

Comments
 (0)