-
-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Merged
techknowlogick
merged 17 commits into
go-gitea:main
from
techknowlogick:deprecate-azure-ad-auth
Aug 23, 2025
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ebb8c93
Remove deprecated auth sources
techknowlogick f63f49c
Merge branch 'main' into deprecate-azure-ad-auth
techknowlogick 57b24be
Merge branch 'main' into deprecate-azure-ad-auth
techknowlogick 441b0ab
Merge remote-tracking branch 'upstream/main' into deprecate-azure-ad-…
techknowlogick 931044c
reduce duplication
techknowlogick 587bf92
Merge branch 'main' into deprecate-azure-ad-auth
techknowlogick 6d34f62
dont use map per feedback
techknowlogick c9feca8
fix lint
techknowlogick 7a8ac61
Merge branch 'main' into deprecate-azure-ad-auth
techknowlogick 8d9790b
more specific
techknowlogick 4de3732
Merge branch 'deprecate-azure-ad-auth' of https://github.com/techknow…
techknowlogick 9de9bdd
Merge branch 'main' into deprecate-azure-ad-auth
techknowlogick 09f62ab
Merge branch 'main' into deprecate-azure-ad-auth
GiteaBot ea89329
Merge branch 'main' into deprecate-azure-ad-auth
GiteaBot 11d68dd
Merge branch 'deprecate-azure-ad-auth' of github.com:techknowlogick/g…
lunny 2847ed3
some improvements
lunny 686bc17
Merge branch 'main' into deprecate-azure-ad-auth
techknowlogick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,10 @@ func (p *AuthSourceProvider) IconHTML(size int) template.HTML { | |
// value is used to store display data | ||
var gothProviders = map[string]GothProvider{} | ||
|
||
func isAzureProvider(name string) bool { | ||
return name == "azuread" || name == "microsoftonline" || name == "azureadv2" | ||
} | ||
|
||
// RegisterGothProvider registers a GothProvider | ||
func RegisterGothProvider(provider GothProvider) { | ||
if _, has := gothProviders[provider.Name()]; has { | ||
|
@@ -83,13 +88,47 @@ 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, error) { | ||
authSources, err := db.Find[auth.Source](ctx, auth.FindSourcesOptions{ | ||
LoginType: auth.OAuth2, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var existingAzureProviders []string | ||
for _, source := range authSources { | ||
if oauth2Cfg, ok := source.Cfg.(*Source); ok { | ||
if isAzureProvider(oauth2Cfg.Provider) { | ||
existingAzureProviders = append(existingAzureProviders, oauth2Cfg.Provider) | ||
} | ||
} | ||
} | ||
return existingAzureProviders, nil | ||
} | ||
|
||
// 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)) | ||
existingAzureSources, err := getExistingAzureADAuthSources(ctx) | ||
if err != nil { | ||
log.Error("Failed to get existing OAuth2 auth sources: %v", err) | ||
} | ||
|
||
for _, provider := range gothProviders { | ||
if isAzureProvider(provider.Name()) && !slices.Contains(existingAzureSources, provider.Name()) { | ||
continue | ||
} | ||
providers = append(providers, provider) | ||
} | ||
sort.Slice(providers, func(i, j int) bool { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.