1
0
Fork 0
miniflux/internal/oauth2/manager.go

43 lines
1.1 KiB
Go
Raw Normal View History

// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
2017-11-23 01:22:33 -05:00
package oauth2 // import "miniflux.app/v2/internal/oauth2"
2017-11-23 01:22:33 -05:00
import (
"context"
"errors"
"miniflux.app/v2/internal/logger"
)
2017-11-23 01:22:33 -05:00
type Manager struct {
providers map[string]Provider
}
func (m *Manager) FindProvider(name string) (Provider, error) {
2017-11-23 01:22:33 -05:00
if provider, found := m.providers[name]; found {
return provider, nil
}
return nil, errors.New("oauth2 provider not found")
}
func (m *Manager) AddProvider(name string, provider Provider) {
m.providers[name] = provider
}
func NewManager(ctx context.Context, clientID, clientSecret, redirectURL, oidcDiscoveryEndpoint string) *Manager {
2017-11-23 01:22:33 -05:00
m := &Manager{providers: make(map[string]Provider)}
2023-09-03 00:35:10 -04:00
m.AddProvider("google", NewGoogleProvider(clientID, clientSecret, redirectURL))
if oidcDiscoveryEndpoint != "" {
2023-09-03 00:35:10 -04:00
if genericOidcProvider, err := NewOidcProvider(ctx, clientID, clientSecret, redirectURL, oidcDiscoveryEndpoint); err != nil {
logger.Error("[OAuth2] failed to initialize OIDC provider: %v", err)
} else {
m.AddProvider("oidc", genericOidcProvider)
}
}
2017-11-23 01:22:33 -05:00
return m
}