Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
some improvements
  • Loading branch information
lunny committed Aug 23, 2025
commit 2847ed3864cf0c3e12f532aaedddcfc95bb39552
21 changes: 11 additions & 10 deletions services/auth/source/oauth2/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@ 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",
func isAzureProvider(name string) bool {
return name == "azuread" || name == "microsoftonline" || name == "azureadv2"
}

// RegisterGothProvider registers a GothProvider
Expand All @@ -91,23 +89,23 @@ func RegisterGothProvider(provider GothProvider) {
}

// getExistingAzureADAuthSources returns a list of Azure AD provider names that are already configured
func getExistingAzureADAuthSources(ctx context.Context) []string {
func getExistingAzureADAuthSources(ctx context.Context) ([]string, error) {
authSources, err := db.Find[auth.Source](ctx, auth.FindSourcesOptions{
LoginType: auth.OAuth2,
})
if err != nil {
return nil
return nil, err
}

var existingAzureProviders []string
for _, source := range authSources {
if oauth2Cfg, ok := source.Cfg.(*Source); ok {
if slices.Contains(azureProviders, oauth2Cfg.Provider) {
if isAzureProvider(oauth2Cfg.Provider) {
existingAzureProviders = append(existingAzureProviders, oauth2Cfg.Provider)
}
}
}
return existingAzureProviders
return existingAzureProviders, nil
}

// GetSupportedOAuth2Providers returns the map of unconfigured OAuth2 providers
Expand All @@ -122,10 +120,13 @@ func GetSupportedOAuth2Providers() []Provider {
// 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)
existingAzureSources, err := getExistingAzureADAuthSources(ctx)
if err != nil {
log.Error("Failed to get existing OAuth2 auth sources: %v", err)
}

for _, provider := range gothProviders {
if slices.Contains(azureProviders, provider.Name()) && !slices.Contains(existAuthSources, provider.Name()) {
if isAzureProvider(provider.Name()) && !slices.Contains(existingAzureSources, provider.Name()) {
continue
}
providers = append(providers, provider)
Expand Down