3e1e0b604f
This adds the oauth2 provider `oidc`. It needs an additional argument, the OIDC discovery endpoint to figure out where the auth and token URLs are. Configuration is similar to setting up the Google Authentication with these changes: * `OAUTH2_PROVIDER = oidc` * `OAUTH2_OIDC_DISCOVERY_ENDPOINT = https://auth.exampe.org/discovery`
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
// Copyright 2017 Frédéric Guillot. All rights reserved.
|
|
// Use of this source code is governed by the Apache 2.0
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package oauth2 // import "miniflux.app/oauth2"
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"miniflux.app/logger"
|
|
)
|
|
|
|
// Manager handles OAuth2 providers.
|
|
type Manager struct {
|
|
providers map[string]Provider
|
|
}
|
|
|
|
// Provider returns the given provider.
|
|
func (m *Manager) Provider(name string) (Provider, error) {
|
|
if provider, found := m.providers[name]; found {
|
|
return provider, nil
|
|
}
|
|
|
|
return nil, errors.New("oauth2 provider not found")
|
|
}
|
|
|
|
// AddProvider add a new OAuth2 provider.
|
|
func (m *Manager) AddProvider(name string, provider Provider) {
|
|
m.providers[name] = provider
|
|
}
|
|
|
|
// NewManager returns a new Manager.
|
|
func NewManager(ctx context.Context, clientID, clientSecret, redirectURL, oidcDiscoveryEndpoint string) *Manager {
|
|
m := &Manager{providers: make(map[string]Provider)}
|
|
m.AddProvider("google", newGoogleProvider(clientID, clientSecret, redirectURL))
|
|
|
|
if oidcDiscoveryEndpoint != "" {
|
|
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)
|
|
}
|
|
}
|
|
|
|
return m
|
|
}
|