mirror of
https://github.com/pomerium/pomerium.git
synced 2025-04-29 18:36:30 +02:00
- import path comments are obsoleted by the go.mod file's module statement Signed-off-by: Bobby DeSimone <bobbydesimone@gmail.com>
40 lines
1 KiB
Go
40 lines
1 KiB
Go
package identity
|
|
|
|
import (
|
|
"context"
|
|
|
|
oidc "github.com/coreos/go-oidc"
|
|
"golang.org/x/oauth2"
|
|
)
|
|
|
|
// OIDCProvider provides a standard, OpenID Connect implementation
|
|
// of an authorization identity provider.
|
|
// https://openid.net/specs/openid-connect-core-1_0.html
|
|
type OIDCProvider struct {
|
|
*Provider
|
|
}
|
|
|
|
// NewOIDCProvider creates a new instance of a generic OpenID Connect provider.
|
|
func NewOIDCProvider(p *Provider) (*OIDCProvider, error) {
|
|
ctx := context.Background()
|
|
if p.ProviderURL == "" {
|
|
return nil, ErrMissingProviderURL
|
|
}
|
|
var err error
|
|
p.provider, err = oidc.NewProvider(ctx, p.ProviderURL)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(p.Scopes) == 0 {
|
|
p.Scopes = []string{oidc.ScopeOpenID, "profile", "email", "offline_access"}
|
|
}
|
|
p.verifier = p.provider.Verifier(&oidc.Config{ClientID: p.ClientID})
|
|
p.oauth = &oauth2.Config{
|
|
ClientID: p.ClientID,
|
|
ClientSecret: p.ClientSecret,
|
|
Endpoint: p.provider.Endpoint(),
|
|
RedirectURL: p.RedirectURL.String(),
|
|
Scopes: p.Scopes,
|
|
}
|
|
return &OIDCProvider{Provider: p}, nil
|
|
}
|