diff options
author | zeripath <art27@cantab.net> | 2021-08-06 02:11:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-05 21:11:08 -0400 |
commit | ab9bb54144f136bbbba2ce2e94fd88c0be0ee1cf (patch) | |
tree | f8b283e33e70cbc3d827879c4774de2b41450ab0 /routers | |
parent | 7e7006e00d8d0d5ce4c871685d421269049e4b39 (diff) | |
download | gitea-ab9bb54144f136bbbba2ce2e94fd88c0be0ee1cf.tar.gz gitea-ab9bb54144f136bbbba2ce2e94fd88c0be0ee1cf.zip |
Add microsoft oauth2 providers (#16544)
* Clean up oauth2 providers
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Add AzureAD, AzureADv2, MicrosoftOnline OAuth2 providers
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Apply suggestions from code review
* remove unused Scopes
Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'routers')
-rw-r--r-- | routers/web/admin/auths.go | 34 | ||||
-rw-r--r-- | routers/web/user/setting/security.go | 17 |
2 files changed, 34 insertions, 17 deletions
diff --git a/routers/web/admin/auths.go b/routers/web/admin/auths.go index 20efd4a2ac..2e9697533a 100644 --- a/routers/web/admin/auths.go +++ b/routers/web/admin/auths.go @@ -98,8 +98,8 @@ func NewAuthSource(ctx *context.Context) { ctx.Data["AuthSources"] = authSources ctx.Data["SecurityProtocols"] = securityProtocols ctx.Data["SMTPAuths"] = smtp.Authenticators - ctx.Data["OAuth2Providers"] = oauth2.Providers - ctx.Data["OAuth2DefaultCustomURLMappings"] = oauth2.DefaultCustomURLMappings + oauth2providers := oauth2.GetOAuth2Providers() + ctx.Data["OAuth2Providers"] = oauth2providers ctx.Data["SSPIAutoCreateUsers"] = true ctx.Data["SSPIAutoActivateUsers"] = true @@ -108,10 +108,7 @@ func NewAuthSource(ctx *context.Context) { ctx.Data["SSPIDefaultLanguage"] = "" // only the first as default - for key := range oauth2.Providers { - ctx.Data["oauth2_provider"] = key - break - } + ctx.Data["oauth2_provider"] = oauth2providers[0] ctx.HTML(http.StatusOK, tplAuthNew) } @@ -170,6 +167,7 @@ func parseOAuth2Config(form forms.AuthenticationForm) *oauth2.Source { AuthURL: form.Oauth2AuthURL, ProfileURL: form.Oauth2ProfileURL, EmailURL: form.Oauth2EmailURL, + Tenant: form.Oauth2Tenant, } } else { customURLMapping = nil @@ -220,8 +218,8 @@ func NewAuthSourcePost(ctx *context.Context) { ctx.Data["AuthSources"] = authSources ctx.Data["SecurityProtocols"] = securityProtocols ctx.Data["SMTPAuths"] = smtp.Authenticators - ctx.Data["OAuth2Providers"] = oauth2.Providers - ctx.Data["OAuth2DefaultCustomURLMappings"] = oauth2.DefaultCustomURLMappings + oauth2providers := oauth2.GetOAuth2Providers() + ctx.Data["OAuth2Providers"] = oauth2providers ctx.Data["SSPIAutoCreateUsers"] = true ctx.Data["SSPIAutoActivateUsers"] = true @@ -299,8 +297,8 @@ func EditAuthSource(ctx *context.Context) { ctx.Data["SecurityProtocols"] = securityProtocols ctx.Data["SMTPAuths"] = smtp.Authenticators - ctx.Data["OAuth2Providers"] = oauth2.Providers - ctx.Data["OAuth2DefaultCustomURLMappings"] = oauth2.DefaultCustomURLMappings + oauth2providers := oauth2.GetOAuth2Providers() + ctx.Data["OAuth2Providers"] = oauth2providers source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid")) if err != nil { @@ -311,7 +309,17 @@ func EditAuthSource(ctx *context.Context) { ctx.Data["HasTLS"] = source.HasTLS() if source.IsOAuth2() { - ctx.Data["CurrentOAuth2Provider"] = oauth2.Providers[source.Cfg.(*oauth2.Source).Provider] + type Named interface { + Name() string + } + + for _, provider := range oauth2providers { + if provider.Name() == source.Cfg.(Named).Name() { + ctx.Data["CurrentOAuth2Provider"] = provider + break + } + } + } ctx.HTML(http.StatusOK, tplAuthEdit) } @@ -324,8 +332,8 @@ func EditAuthSourcePost(ctx *context.Context) { ctx.Data["PageIsAdminAuthentications"] = true ctx.Data["SMTPAuths"] = smtp.Authenticators - ctx.Data["OAuth2Providers"] = oauth2.Providers - ctx.Data["OAuth2DefaultCustomURLMappings"] = oauth2.DefaultCustomURLMappings + oauth2providers := oauth2.GetOAuth2Providers() + ctx.Data["OAuth2Providers"] = oauth2providers source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid")) if err != nil { diff --git a/routers/web/user/setting/security.go b/routers/web/user/setting/security.go index 02969fb1e6..36c6d7df72 100644 --- a/routers/web/user/setting/security.go +++ b/routers/web/user/setting/security.go @@ -12,7 +12,6 @@ import ( "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/setting" - "code.gitea.io/gitea/services/auth/source/oauth2" ) const ( @@ -92,9 +91,19 @@ func loadSecurityData(ctx *context.Context) { for _, externalAccount := range accountLinks { if loginSource, err := models.GetLoginSourceByID(externalAccount.LoginSourceID); err == nil { var providerDisplayName string - if loginSource.IsOAuth2() { - providerTechnicalName := loginSource.Cfg.(*oauth2.Source).Provider - providerDisplayName = oauth2.Providers[providerTechnicalName].DisplayName + + type DisplayNamed interface { + DisplayName() string + } + + type Named interface { + Name() string + } + + if displayNamed, ok := loginSource.Cfg.(DisplayNamed); ok { + providerDisplayName = displayNamed.DisplayName() + } else if named, ok := loginSource.Cfg.(Named); ok { + providerDisplayName = named.Name() } else { providerDisplayName = loginSource.Name } |