2020-10-06 14:11:57 +00:00
|
|
|
// Copyright 2020 the Pinniped contributors. All Rights Reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
// Package oidc contains common OIDC functionality needed by Pinniped.
|
|
|
|
package oidc
|
|
|
|
|
2020-11-04 23:04:50 +00:00
|
|
|
import (
|
|
|
|
"github.com/ory/fosite"
|
|
|
|
"github.com/ory/fosite/compose"
|
|
|
|
)
|
|
|
|
|
2020-10-06 14:11:57 +00:00
|
|
|
const (
|
2020-10-08 18:28:21 +00:00
|
|
|
WellKnownEndpointPath = "/.well-known/openid-configuration"
|
|
|
|
AuthorizationEndpointPath = "/oauth2/authorize"
|
|
|
|
TokenEndpointPath = "/oauth2/token" //nolint:gosec // ignore lint warning that this is a credential
|
|
|
|
JWKSEndpointPath = "/jwks.json"
|
2020-10-06 14:11:57 +00:00
|
|
|
)
|
2020-11-04 23:04:50 +00:00
|
|
|
|
|
|
|
func PinnipedCLIOIDCClient() *fosite.DefaultOpenIDConnectClient {
|
|
|
|
return &fosite.DefaultOpenIDConnectClient{
|
|
|
|
DefaultClient: &fosite.DefaultClient{
|
|
|
|
ID: "pinniped-cli",
|
|
|
|
Public: true,
|
|
|
|
RedirectURIs: []string{"http://127.0.0.1/callback"},
|
|
|
|
ResponseTypes: []string{"code"},
|
|
|
|
GrantTypes: []string{"authorization_code"},
|
|
|
|
Scopes: []string{"openid", "profile", "email"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-05 01:06:47 +00:00
|
|
|
func FositeOauth2Helper(oauthStore interface{}, hmacSecretOfLengthAtLeast32 []byte) fosite.OAuth2Provider {
|
2020-11-04 23:04:50 +00:00
|
|
|
oauthConfig := &compose.Config{
|
|
|
|
EnforcePKCEForPublicClients: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
return compose.Compose(
|
|
|
|
oauthConfig,
|
|
|
|
oauthStore,
|
|
|
|
&compose.CommonStrategy{
|
2020-11-05 01:06:47 +00:00
|
|
|
// Note that Fosite requires the HMAC secret to be at least 32 bytes.
|
|
|
|
CoreStrategy: compose.NewOAuth2HMACStrategy(oauthConfig, hmacSecretOfLengthAtLeast32, nil),
|
2020-11-04 23:04:50 +00:00
|
|
|
},
|
|
|
|
nil, // hasher, defaults to using BCrypt when nil. Used for hashing client secrets.
|
|
|
|
compose.OAuth2AuthorizeExplicitFactory,
|
|
|
|
// compose.OAuth2RefreshTokenGrantFactory,
|
2020-11-06 22:44:58 +00:00
|
|
|
compose.OpenIDConnectExplicitFactory,
|
2020-11-04 23:04:50 +00:00
|
|
|
// compose.OpenIDConnectRefreshFactory,
|
|
|
|
compose.OAuth2PKCEFactory,
|
|
|
|
)
|
|
|
|
}
|