onelogin: fix default scopes for v2 (#1896)

This commit is contained in:
Caleb Doxsey 2021-02-17 08:51:13 -07:00 committed by GitHub
parent 5be71b8e07
commit 64d247cfeb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,6 +6,7 @@ package onelogin
import (
"context"
"fmt"
"strings"
oidc "github.com/coreos/go-oidc/v3/oidc"
@ -20,7 +21,10 @@ const (
defaultProviderURL = "https://openid-connect.onelogin.com/oidc"
)
var defaultScopes = []string{oidc.ScopeOpenID, "profile", "email", "groups", "offline_access"}
var (
defaultV1Scopes = []string{oidc.ScopeOpenID, "profile", "email", "groups", "offline_access"}
defaultV2Scopes = []string{oidc.ScopeOpenID, "profile", "email", "groups"} // v2 does not support offline_access
)
// Provider is an OneLogin implementation of the Authenticator interface.
type Provider struct {
@ -34,8 +38,10 @@ func New(ctx context.Context, o *oauth.Options) (*Provider, error) {
if o.ProviderURL == "" {
o.ProviderURL = defaultProviderURL
}
if len(o.Scopes) == 0 {
o.Scopes = defaultScopes
if strings.Contains(o.ProviderURL, "/oidc/2") {
o.Scopes = defaultV2Scopes
} else {
o.Scopes = defaultV1Scopes
}
genericOidc, err := pom_oidc.New(ctx, o)
if err != nil {