Skip to content

Commit ebb8c93

Browse files
Remove deprecated auth sources
Entra ID users should use the OIDC oauth2 provider
1 parent ef613ee commit ebb8c93

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

routers/web/admin/auths.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func NewAuthSource(ctx *context.Context) {
9797
ctx.Data["AuthSources"] = authSources
9898
ctx.Data["SecurityProtocols"] = securityProtocols
9999
ctx.Data["SMTPAuths"] = smtp.Authenticators
100-
oauth2providers := oauth2.GetSupportedOAuth2Providers()
100+
oauth2providers := oauth2.GetSupportedOAuth2ProvidersWithContext(ctx)
101101
ctx.Data["OAuth2Providers"] = oauth2providers
102102

103103
ctx.Data["SSPIAutoCreateUsers"] = true
@@ -107,7 +107,9 @@ func NewAuthSource(ctx *context.Context) {
107107
ctx.Data["SSPIDefaultLanguage"] = ""
108108

109109
// only the first as default
110-
ctx.Data["oauth2_provider"] = oauth2providers[0].Name()
110+
if len(oauth2providers) > 0 {
111+
ctx.Data["oauth2_provider"] = oauth2providers[0].Name()
112+
}
111113

112114
ctx.HTML(http.StatusOK, tplAuthNew)
113115
}
@@ -240,7 +242,7 @@ func NewAuthSourcePost(ctx *context.Context) {
240242
ctx.Data["AuthSources"] = authSources
241243
ctx.Data["SecurityProtocols"] = securityProtocols
242244
ctx.Data["SMTPAuths"] = smtp.Authenticators
243-
oauth2providers := oauth2.GetSupportedOAuth2Providers()
245+
oauth2providers := oauth2.GetSupportedOAuth2ProvidersWithContext(ctx)
244246
ctx.Data["OAuth2Providers"] = oauth2providers
245247

246248
ctx.Data["SSPIAutoCreateUsers"] = true

services/auth/source/oauth2/providers.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,55 @@ func RegisterGothProvider(provider GothProvider) {
8383
gothProviders[provider.Name()] = provider
8484
}
8585

86+
// hasExistingAzureADAuthSources checks if there are any existing Azure AD auth sources configured
87+
func hasExistingAzureADAuthSources(ctx context.Context) bool {
88+
azureProviders := map[string]bool{
89+
"azuread": true,
90+
"microsoftonline": true,
91+
"azureadv2": true,
92+
}
93+
94+
authSources, err := db.Find[auth.Source](ctx, auth.FindSourcesOptions{
95+
LoginType: auth.OAuth2,
96+
})
97+
if err != nil {
98+
return false
99+
}
100+
101+
for _, source := range authSources {
102+
if oauth2Cfg, ok := source.Cfg.(*Source); ok {
103+
if azureProviders[oauth2Cfg.Provider] {
104+
return true
105+
}
106+
}
107+
}
108+
return false
109+
}
110+
86111
// GetSupportedOAuth2Providers returns the map of unconfigured OAuth2 providers
87112
// key is used as technical name (like in the callbackURL)
88113
// values to display
114+
// Note: Azure AD providers (azuread, microsoftonline, azureadv2) are filtered out
115+
// unless they already exist in the system to encourage use of OpenID Connect
89116
func GetSupportedOAuth2Providers() []Provider {
117+
return GetSupportedOAuth2ProvidersWithContext(context.Background())
118+
}
119+
120+
// GetSupportedOAuth2ProvidersWithContext returns the list of supported OAuth2 providers with context for filtering
121+
func GetSupportedOAuth2ProvidersWithContext(ctx context.Context) []Provider {
90122
providers := make([]Provider, 0, len(gothProviders))
123+
hasExistingAzure := hasExistingAzureADAuthSources(ctx)
124+
125+
azureProviders := map[string]bool{
126+
"azuread": true,
127+
"microsoftonline": true,
128+
"azureadv2": true,
129+
}
91130

92131
for _, provider := range gothProviders {
132+
if azureProviders[provider.Name()] && !hasExistingAzure {
133+
continue
134+
}
93135
providers = append(providers, provider)
94136
}
95137
sort.Slice(providers, func(i, j int) bool {

0 commit comments

Comments
 (0)