-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Remove deprecated auth sources #35272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 14 commits
ebb8c93
f63f49c
57b24be
441b0ab
931044c
587bf92
6d34f62
c9feca8
7a8ac61
8d9790b
4de3732
9de9bdd
09f62ab
ea89329
11d68dd
2847ed3
686bc17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import ( | |
| "html" | ||
| "html/template" | ||
| "net/url" | ||
| "slices" | ||
| "sort" | ||
|
|
||
| "code.gitea.io/gitea/models/auth" | ||
|
|
@@ -75,6 +76,12 @@ func (p *AuthSourceProvider) IconHTML(size int) template.HTML { | |
| // value is used to store display data | ||
| var gothProviders = map[string]GothProvider{} | ||
|
|
||
| var azureProviders = []string{ | ||
| "azuread", | ||
| "microsoftonline", | ||
| "azureadv2", | ||
| } | ||
|
|
||
| // RegisterGothProvider registers a GothProvider | ||
| func RegisterGothProvider(provider GothProvider) { | ||
| if _, has := gothProviders[provider.Name()]; has { | ||
|
|
@@ -83,13 +90,44 @@ func RegisterGothProvider(provider GothProvider) { | |
| gothProviders[provider.Name()] = provider | ||
| } | ||
|
|
||
| // getExistingAzureADAuthSources returns a list of Azure AD provider names that are already configured | ||
| func getExistingAzureADAuthSources(ctx context.Context) []string { | ||
| authSources, err := db.Find[auth.Source](ctx, auth.FindSourcesOptions{ | ||
| LoginType: auth.OAuth2, | ||
| }) | ||
| if err != nil { | ||
| return nil | ||
| } | ||
|
|
||
| var existingAzureProviders []string | ||
lunny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| for _, source := range authSources { | ||
| if oauth2Cfg, ok := source.Cfg.(*Source); ok { | ||
| if slices.Contains(azureProviders, oauth2Cfg.Provider) { | ||
| existingAzureProviders = append(existingAzureProviders, oauth2Cfg.Provider) | ||
| } | ||
| } | ||
| } | ||
| return existingAzureProviders | ||
| } | ||
|
|
||
| // GetSupportedOAuth2Providers returns the map of unconfigured OAuth2 providers | ||
| // key is used as technical name (like in the callbackURL) | ||
| // values to display | ||
| // Note: Azure AD providers (azuread, microsoftonline, azureadv2) are filtered out | ||
| // unless they already exist in the system to encourage use of OpenID Connect | ||
| func GetSupportedOAuth2Providers() []Provider { | ||
| return GetSupportedOAuth2ProvidersWithContext(context.Background()) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In most cases, -> Fix context usages #35348 |
||
| } | ||
|
|
||
| // GetSupportedOAuth2ProvidersWithContext returns the list of supported OAuth2 providers with context for filtering | ||
| func GetSupportedOAuth2ProvidersWithContext(ctx context.Context) []Provider { | ||
| providers := make([]Provider, 0, len(gothProviders)) | ||
| existAuthSources := getExistingAzureADAuthSources(ctx) | ||
lunny marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| for _, provider := range gothProviders { | ||
| if slices.Contains(azureProviders, provider.Name()) && !slices.Contains(existAuthSources, provider.Name()) { | ||
|
||
| continue | ||
| } | ||
| providers = append(providers, provider) | ||
| } | ||
| sort.Slice(providers, func(i, j int) bool { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't silently ignore an unknown error.