chore(linting): apply gofumpt & goimports to all .go files (#225)
This commit is contained in:
parent
c4b7ef9160
commit
b5da6ec29b
45 changed files with 539 additions and 479 deletions
|
@ -16,9 +16,7 @@ import (
|
||||||
"github.com/zitadel/oidc/pkg/client/profile"
|
"github.com/zitadel/oidc/pkg/client/profile"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var client = http.DefaultClient
|
||||||
client = http.DefaultClient
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
keyPath := os.Getenv("KEY_PATH")
|
keyPath := os.Getenv("KEY_PATH")
|
||||||
|
@ -145,7 +143,6 @@ func main() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
lis := fmt.Sprintf("127.0.0.1:%s", port)
|
lis := fmt.Sprintf("127.0.0.1:%s", port)
|
||||||
logrus.Infof("listening on http://%s/", lis)
|
logrus.Infof("listening on http://%s/", lis)
|
||||||
|
|
|
@ -15,20 +15,17 @@ import (
|
||||||
"github.com/zitadel/oidc/pkg/oidc"
|
"github.com/zitadel/oidc/pkg/oidc"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var Encoder = func() httphelper.Encoder {
|
||||||
Encoder = func() httphelper.Encoder {
|
|
||||||
e := schema.NewEncoder()
|
e := schema.NewEncoder()
|
||||||
e.RegisterEncoder(oidc.SpaceDelimitedArray{}, func(value reflect.Value) string {
|
e.RegisterEncoder(oidc.SpaceDelimitedArray{}, func(value reflect.Value) string {
|
||||||
return value.Interface().(oidc.SpaceDelimitedArray).Encode()
|
return value.Interface().(oidc.SpaceDelimitedArray).Encode()
|
||||||
})
|
})
|
||||||
return e
|
return e
|
||||||
}()
|
}()
|
||||||
)
|
|
||||||
|
|
||||||
// Discover calls the discovery endpoint of the provided issuer and returns its configuration
|
// Discover calls the discovery endpoint of the provided issuer and returns its configuration
|
||||||
// It accepts an optional argument "wellknownUrl" which can be used to overide the dicovery endpoint url
|
// It accepts an optional argument "wellknownUrl" which can be used to overide the dicovery endpoint url
|
||||||
func Discover(issuer string, httpClient *http.Client, wellKnownUrl ...string) (*oidc.DiscoveryConfiguration, error) {
|
func Discover(issuer string, httpClient *http.Client, wellKnownUrl ...string) (*oidc.DiscoveryConfiguration, error) {
|
||||||
|
|
||||||
wellKnown := strings.TrimSuffix(issuer, "/") + oidc.DiscoveryEndpoint
|
wellKnown := strings.TrimSuffix(issuer, "/") + oidc.DiscoveryEndpoint
|
||||||
if len(wellKnownUrl) == 1 && wellKnownUrl[0] != "" {
|
if len(wellKnownUrl) == 1 && wellKnownUrl[0] != "" {
|
||||||
wellKnown = wellKnownUrl[0]
|
wellKnown = wellKnownUrl[0]
|
||||||
|
|
|
@ -23,9 +23,7 @@ const (
|
||||||
pkceCode = "pkce"
|
pkceCode = "pkce"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var ErrUserInfoSubNotMatching = errors.New("sub from userinfo does not match the sub from the id_token")
|
||||||
ErrUserInfoSubNotMatching = errors.New("sub from userinfo does not match the sub from the id_token")
|
|
||||||
)
|
|
||||||
|
|
||||||
// RelyingParty declares the minimal interface for oidc clients
|
// RelyingParty declares the minimal interface for oidc clients
|
||||||
type RelyingParty interface {
|
type RelyingParty interface {
|
||||||
|
@ -65,11 +63,9 @@ type RelyingParty interface {
|
||||||
|
|
||||||
type ErrorHandler func(w http.ResponseWriter, r *http.Request, errorType string, errorDesc string, state string)
|
type ErrorHandler func(w http.ResponseWriter, r *http.Request, errorType string, errorDesc string, state string)
|
||||||
|
|
||||||
var (
|
var DefaultErrorHandler ErrorHandler = func(w http.ResponseWriter, r *http.Request, errorType string, errorDesc string, state string) {
|
||||||
DefaultErrorHandler ErrorHandler = func(w http.ResponseWriter, r *http.Request, errorType string, errorDesc string, state string) {
|
|
||||||
http.Error(w, errorType+": "+errorDesc, http.StatusInternalServerError)
|
http.Error(w, errorType+": "+errorDesc, http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
type relyingParty struct {
|
type relyingParty struct {
|
||||||
issuer string
|
issuer string
|
||||||
|
|
|
@ -43,6 +43,7 @@ func NewResourceServerClientCredentials(issuer, clientID, clientSecret string, o
|
||||||
}
|
}
|
||||||
return newResourceServer(issuer, authorizer, option...)
|
return newResourceServer(issuer, authorizer, option...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewResourceServerJWTProfile(issuer, clientID, keyID string, key []byte, options ...Option) (ResourceServer, error) {
|
func NewResourceServerJWTProfile(issuer, clientID, keyID string, key []byte, options ...Option) (ResourceServer, error) {
|
||||||
signer, err := client.NewSignerFromPrivateKeyByte(key, keyID)
|
signer, err := client.NewSignerFromPrivateKeyByte(key, keyID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -9,9 +9,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var ErrCipherTextBlockSize = errors.New("ciphertext block size is too short")
|
||||||
ErrCipherTextBlockSize = errors.New("ciphertext block size is too short")
|
|
||||||
)
|
|
||||||
|
|
||||||
func EncryptAES(data string, key string) (string, error) {
|
func EncryptAES(data string, key string) (string, error) {
|
||||||
encrypted, err := EncryptBytesAES([]byte(data), key)
|
encrypted, err := EncryptBytesAES([]byte(data), key)
|
||||||
|
|
|
@ -11,9 +11,7 @@ import (
|
||||||
"gopkg.in/square/go-jose.v2"
|
"gopkg.in/square/go-jose.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var ErrUnsupportedAlgorithm = errors.New("unsupported signing algorithm")
|
||||||
ErrUnsupportedAlgorithm = errors.New("unsupported signing algorithm")
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetHashAlgorithm(sigAlgorithm jose.SignatureAlgorithm) (hash.Hash, error) {
|
func GetHashAlgorithm(sigAlgorithm jose.SignatureAlgorithm) (hash.Hash, error) {
|
||||||
switch sigAlgorithm {
|
switch sigAlgorithm {
|
||||||
|
|
|
@ -12,15 +12,14 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var DefaultHTTPClient = &http.Client{
|
||||||
DefaultHTTPClient = &http.Client{
|
|
||||||
Timeout: 30 * time.Second,
|
Timeout: 30 * time.Second,
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
type Decoder interface {
|
type Decoder interface {
|
||||||
Decode(dst interface{}, src map[string][]string) error
|
Decode(dst interface{}, src map[string][]string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type Encoder interface {
|
type Encoder interface {
|
||||||
Encode(src interface{}, dst map[string][]string) error
|
Encode(src interface{}, dst map[string][]string) error
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,8 @@ const (
|
||||||
var AllGrantTypes = []GrantType{
|
var AllGrantTypes = []GrantType{
|
||||||
GrantTypeCode, GrantTypeRefreshToken, GrantTypeClientCredentials,
|
GrantTypeCode, GrantTypeRefreshToken, GrantTypeClientCredentials,
|
||||||
GrantTypeBearer, GrantTypeTokenExchange, GrantTypeImplicit,
|
GrantTypeBearer, GrantTypeTokenExchange, GrantTypeImplicit,
|
||||||
ClientAssertionTypeJWTAssertion}
|
ClientAssertionTypeJWTAssertion,
|
||||||
|
}
|
||||||
|
|
||||||
type GrantType string
|
type GrantType string
|
||||||
|
|
||||||
|
|
|
@ -202,6 +202,7 @@ func CheckAuthorizationContextClassReference(claims Claims, acr ACRVerifier) err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckAuthTime(claims Claims, maxAge time.Duration) error {
|
func CheckAuthTime(claims Claims, maxAge time.Duration) error {
|
||||||
if maxAge == 0 {
|
if maxAge == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -364,191 +364,245 @@ func TestValidateAuthReqRedirectURI(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"empty fails",
|
"empty fails",
|
||||||
args{"",
|
args{
|
||||||
|
"",
|
||||||
mock.NewClientWithConfig(t, []string{"https://registered.com/callback"}, op.ApplicationTypeWeb, nil, false),
|
mock.NewClientWithConfig(t, []string{"https://registered.com/callback"}, op.ApplicationTypeWeb, nil, false),
|
||||||
oidc.ResponseTypeCode},
|
oidc.ResponseTypeCode,
|
||||||
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"unregistered https fails",
|
"unregistered https fails",
|
||||||
args{"https://unregistered.com/callback",
|
args{
|
||||||
|
"https://unregistered.com/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"https://registered.com/callback"}, op.ApplicationTypeWeb, nil, false),
|
mock.NewClientWithConfig(t, []string{"https://registered.com/callback"}, op.ApplicationTypeWeb, nil, false),
|
||||||
oidc.ResponseTypeCode},
|
oidc.ResponseTypeCode,
|
||||||
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"unregistered http fails",
|
"unregistered http fails",
|
||||||
args{"http://unregistered.com/callback",
|
args{
|
||||||
|
"http://unregistered.com/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"http://registered.com/callback"}, op.ApplicationTypeWeb, nil, false),
|
mock.NewClientWithConfig(t, []string{"http://registered.com/callback"}, op.ApplicationTypeWeb, nil, false),
|
||||||
oidc.ResponseTypeCode},
|
oidc.ResponseTypeCode,
|
||||||
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code flow registered https web ok",
|
"code flow registered https web ok",
|
||||||
args{"https://registered.com/callback",
|
args{
|
||||||
|
"https://registered.com/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"https://registered.com/callback"}, op.ApplicationTypeWeb, nil, false),
|
mock.NewClientWithConfig(t, []string{"https://registered.com/callback"}, op.ApplicationTypeWeb, nil, false),
|
||||||
oidc.ResponseTypeCode},
|
oidc.ResponseTypeCode,
|
||||||
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code flow registered https native ok",
|
"code flow registered https native ok",
|
||||||
args{"https://registered.com/callback",
|
args{
|
||||||
|
"https://registered.com/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"https://registered.com/callback"}, op.ApplicationTypeNative, nil, false),
|
mock.NewClientWithConfig(t, []string{"https://registered.com/callback"}, op.ApplicationTypeNative, nil, false),
|
||||||
oidc.ResponseTypeCode},
|
oidc.ResponseTypeCode,
|
||||||
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code flow registered https user agent ok",
|
"code flow registered https user agent ok",
|
||||||
args{"https://registered.com/callback",
|
args{
|
||||||
|
"https://registered.com/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"https://registered.com/callback"}, op.ApplicationTypeUserAgent, nil, false),
|
mock.NewClientWithConfig(t, []string{"https://registered.com/callback"}, op.ApplicationTypeUserAgent, nil, false),
|
||||||
oidc.ResponseTypeCode},
|
oidc.ResponseTypeCode,
|
||||||
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code flow registered http confidential (web) ok",
|
"code flow registered http confidential (web) ok",
|
||||||
args{"http://registered.com/callback",
|
args{
|
||||||
|
"http://registered.com/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"http://registered.com/callback"}, op.ApplicationTypeWeb, nil, false),
|
mock.NewClientWithConfig(t, []string{"http://registered.com/callback"}, op.ApplicationTypeWeb, nil, false),
|
||||||
oidc.ResponseTypeCode},
|
oidc.ResponseTypeCode,
|
||||||
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code flow registered http not confidential (native) fails",
|
"code flow registered http not confidential (native) fails",
|
||||||
args{"http://registered.com/callback",
|
args{
|
||||||
|
"http://registered.com/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"http://registered.com/callback"}, op.ApplicationTypeNative, nil, false),
|
mock.NewClientWithConfig(t, []string{"http://registered.com/callback"}, op.ApplicationTypeNative, nil, false),
|
||||||
oidc.ResponseTypeCode},
|
oidc.ResponseTypeCode,
|
||||||
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code flow registered http not confidential (user agent) fails",
|
"code flow registered http not confidential (user agent) fails",
|
||||||
args{"http://registered.com/callback",
|
args{
|
||||||
|
"http://registered.com/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"http://registered.com/callback"}, op.ApplicationTypeUserAgent, nil, false),
|
mock.NewClientWithConfig(t, []string{"http://registered.com/callback"}, op.ApplicationTypeUserAgent, nil, false),
|
||||||
oidc.ResponseTypeCode},
|
oidc.ResponseTypeCode,
|
||||||
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code flow registered http localhost native ok",
|
"code flow registered http localhost native ok",
|
||||||
args{"http://localhost:4200/callback",
|
args{
|
||||||
|
"http://localhost:4200/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"http://localhost/callback"}, op.ApplicationTypeNative, nil, false),
|
mock.NewClientWithConfig(t, []string{"http://localhost/callback"}, op.ApplicationTypeNative, nil, false),
|
||||||
oidc.ResponseTypeCode},
|
oidc.ResponseTypeCode,
|
||||||
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code flow registered http loopback v4 native ok",
|
"code flow registered http loopback v4 native ok",
|
||||||
args{"http://127.0.0.1:4200/callback",
|
args{
|
||||||
|
"http://127.0.0.1:4200/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"http://127.0.0.1/callback"}, op.ApplicationTypeNative, nil, false),
|
mock.NewClientWithConfig(t, []string{"http://127.0.0.1/callback"}, op.ApplicationTypeNative, nil, false),
|
||||||
oidc.ResponseTypeCode},
|
oidc.ResponseTypeCode,
|
||||||
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code flow registered http loopback v6 native ok",
|
"code flow registered http loopback v6 native ok",
|
||||||
args{"http://[::1]:4200/callback",
|
args{
|
||||||
|
"http://[::1]:4200/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"http://[::1]/callback"}, op.ApplicationTypeNative, nil, false),
|
mock.NewClientWithConfig(t, []string{"http://[::1]/callback"}, op.ApplicationTypeNative, nil, false),
|
||||||
oidc.ResponseTypeCode},
|
oidc.ResponseTypeCode,
|
||||||
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code flow unregistered http native fails",
|
"code flow unregistered http native fails",
|
||||||
args{"http://unregistered.com/callback",
|
args{
|
||||||
|
"http://unregistered.com/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"http://locahost/callback"}, op.ApplicationTypeNative, nil, false),
|
mock.NewClientWithConfig(t, []string{"http://locahost/callback"}, op.ApplicationTypeNative, nil, false),
|
||||||
oidc.ResponseTypeCode},
|
oidc.ResponseTypeCode,
|
||||||
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code flow unregistered custom native fails",
|
"code flow unregistered custom native fails",
|
||||||
args{"unregistered://callback",
|
args{
|
||||||
|
"unregistered://callback",
|
||||||
mock.NewClientWithConfig(t, []string{"registered://callback"}, op.ApplicationTypeNative, nil, false),
|
mock.NewClientWithConfig(t, []string{"registered://callback"}, op.ApplicationTypeNative, nil, false),
|
||||||
oidc.ResponseTypeCode},
|
oidc.ResponseTypeCode,
|
||||||
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code flow unregistered loopback native fails",
|
"code flow unregistered loopback native fails",
|
||||||
args{"http://[::1]:4200/unregistered",
|
args{
|
||||||
|
"http://[::1]:4200/unregistered",
|
||||||
mock.NewClientWithConfig(t, []string{"http://[::1]:4200/callback"}, op.ApplicationTypeNative, nil, false),
|
mock.NewClientWithConfig(t, []string{"http://[::1]:4200/callback"}, op.ApplicationTypeNative, nil, false),
|
||||||
oidc.ResponseTypeCode},
|
oidc.ResponseTypeCode,
|
||||||
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code flow registered custom not native (web) fails",
|
"code flow registered custom not native (web) fails",
|
||||||
args{"custom://callback",
|
args{
|
||||||
|
"custom://callback",
|
||||||
mock.NewClientWithConfig(t, []string{"custom://callback"}, op.ApplicationTypeWeb, nil, false),
|
mock.NewClientWithConfig(t, []string{"custom://callback"}, op.ApplicationTypeWeb, nil, false),
|
||||||
oidc.ResponseTypeCode},
|
oidc.ResponseTypeCode,
|
||||||
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code flow registered custom not native (user agent) fails",
|
"code flow registered custom not native (user agent) fails",
|
||||||
args{"custom://callback",
|
args{
|
||||||
|
"custom://callback",
|
||||||
mock.NewClientWithConfig(t, []string{"custom://callback"}, op.ApplicationTypeUserAgent, nil, false),
|
mock.NewClientWithConfig(t, []string{"custom://callback"}, op.ApplicationTypeUserAgent, nil, false),
|
||||||
oidc.ResponseTypeCode},
|
oidc.ResponseTypeCode,
|
||||||
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code flow registered custom native ok",
|
"code flow registered custom native ok",
|
||||||
args{"custom://callback",
|
args{
|
||||||
|
"custom://callback",
|
||||||
mock.NewClientWithConfig(t, []string{"custom://callback"}, op.ApplicationTypeNative, nil, false),
|
mock.NewClientWithConfig(t, []string{"custom://callback"}, op.ApplicationTypeNative, nil, false),
|
||||||
oidc.ResponseTypeCode},
|
oidc.ResponseTypeCode,
|
||||||
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code flow dev mode http ok",
|
"code flow dev mode http ok",
|
||||||
args{"http://registered.com/callback",
|
args{
|
||||||
|
"http://registered.com/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"http://registered.com/callback"}, op.ApplicationTypeUserAgent, nil, true),
|
mock.NewClientWithConfig(t, []string{"http://registered.com/callback"}, op.ApplicationTypeUserAgent, nil, true),
|
||||||
oidc.ResponseTypeCode},
|
oidc.ResponseTypeCode,
|
||||||
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"implicit flow registered ok",
|
"implicit flow registered ok",
|
||||||
args{"https://registered.com/callback",
|
args{
|
||||||
|
"https://registered.com/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"https://registered.com/callback"}, op.ApplicationTypeUserAgent, nil, false),
|
mock.NewClientWithConfig(t, []string{"https://registered.com/callback"}, op.ApplicationTypeUserAgent, nil, false),
|
||||||
oidc.ResponseTypeIDToken},
|
oidc.ResponseTypeIDToken,
|
||||||
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"implicit flow unregistered fails",
|
"implicit flow unregistered fails",
|
||||||
args{"https://unregistered.com/callback",
|
args{
|
||||||
|
"https://unregistered.com/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"https://registered.com/callback"}, op.ApplicationTypeUserAgent, nil, false),
|
mock.NewClientWithConfig(t, []string{"https://registered.com/callback"}, op.ApplicationTypeUserAgent, nil, false),
|
||||||
oidc.ResponseTypeIDToken},
|
oidc.ResponseTypeIDToken,
|
||||||
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"implicit flow registered http localhost native ok",
|
"implicit flow registered http localhost native ok",
|
||||||
args{"http://localhost:9999/callback",
|
args{
|
||||||
|
"http://localhost:9999/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"http://localhost:9999/callback"}, op.ApplicationTypeNative, nil, false),
|
mock.NewClientWithConfig(t, []string{"http://localhost:9999/callback"}, op.ApplicationTypeNative, nil, false),
|
||||||
oidc.ResponseTypeIDToken},
|
oidc.ResponseTypeIDToken,
|
||||||
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"implicit flow registered http localhost web fails",
|
"implicit flow registered http localhost web fails",
|
||||||
args{"http://localhost:9999/callback",
|
args{
|
||||||
|
"http://localhost:9999/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"http://localhost:9999/callback"}, op.ApplicationTypeWeb, nil, false),
|
mock.NewClientWithConfig(t, []string{"http://localhost:9999/callback"}, op.ApplicationTypeWeb, nil, false),
|
||||||
oidc.ResponseTypeIDToken},
|
oidc.ResponseTypeIDToken,
|
||||||
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"implicit flow registered http localhost user agent fails",
|
"implicit flow registered http localhost user agent fails",
|
||||||
args{"http://localhost:9999/callback",
|
args{
|
||||||
|
"http://localhost:9999/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"http://localhost:9999/callback"}, op.ApplicationTypeUserAgent, nil, false),
|
mock.NewClientWithConfig(t, []string{"http://localhost:9999/callback"}, op.ApplicationTypeUserAgent, nil, false),
|
||||||
oidc.ResponseTypeIDToken},
|
oidc.ResponseTypeIDToken,
|
||||||
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"implicit flow http non localhost fails",
|
"implicit flow http non localhost fails",
|
||||||
args{"http://registered.com/callback",
|
args{
|
||||||
|
"http://registered.com/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"http://registered.com/callback"}, op.ApplicationTypeNative, nil, false),
|
mock.NewClientWithConfig(t, []string{"http://registered.com/callback"}, op.ApplicationTypeNative, nil, false),
|
||||||
oidc.ResponseTypeIDToken},
|
oidc.ResponseTypeIDToken,
|
||||||
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"implicit flow custom fails",
|
"implicit flow custom fails",
|
||||||
args{"custom://callback",
|
args{
|
||||||
|
"custom://callback",
|
||||||
mock.NewClientWithConfig(t, []string{"custom://callback"}, op.ApplicationTypeNative, nil, false),
|
mock.NewClientWithConfig(t, []string{"custom://callback"}, op.ApplicationTypeNative, nil, false),
|
||||||
oidc.ResponseTypeIDToken},
|
oidc.ResponseTypeIDToken,
|
||||||
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"implicit flow dev mode http ok",
|
"implicit flow dev mode http ok",
|
||||||
args{"http://registered.com/callback",
|
args{
|
||||||
|
"http://registered.com/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"http://registered.com/callback"}, op.ApplicationTypeUserAgent, nil, true),
|
mock.NewClientWithConfig(t, []string{"http://registered.com/callback"}, op.ApplicationTypeUserAgent, nil, true),
|
||||||
oidc.ResponseTypeIDToken},
|
oidc.ResponseTypeIDToken,
|
||||||
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -647,20 +701,26 @@ func TestValidateAuthReqResponseType(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"empty response type",
|
"empty response type",
|
||||||
args{"",
|
args{
|
||||||
mock.NewClientWithConfig(t, nil, op.ApplicationTypeNative, []oidc.ResponseType{oidc.ResponseTypeCode}, true)},
|
"",
|
||||||
|
mock.NewClientWithConfig(t, nil, op.ApplicationTypeNative, []oidc.ResponseType{oidc.ResponseTypeCode}, true),
|
||||||
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"response type missing in client config",
|
"response type missing in client config",
|
||||||
args{oidc.ResponseTypeIDToken,
|
args{
|
||||||
mock.NewClientWithConfig(t, nil, op.ApplicationTypeNative, []oidc.ResponseType{oidc.ResponseTypeCode}, true)},
|
oidc.ResponseTypeIDToken,
|
||||||
|
mock.NewClientWithConfig(t, nil, op.ApplicationTypeNative, []oidc.ResponseType{oidc.ResponseTypeCode}, true),
|
||||||
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"valid response type",
|
"valid response type",
|
||||||
args{oidc.ResponseTypeCode,
|
args{
|
||||||
mock.NewClientWithConfig(t, nil, op.ApplicationTypeNative, []oidc.ResponseType{oidc.ResponseTypeCode}, true)},
|
oidc.ResponseTypeCode,
|
||||||
|
mock.NewClientWithConfig(t, nil, op.ApplicationTypeNative, []oidc.ResponseType{oidc.ResponseTypeCode}, true),
|
||||||
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,7 @@ type Verifier struct{}
|
||||||
func (v *Verifier) Verify(ctx context.Context, accessToken, idToken string) (*oidc.IDTokenClaims, error) {
|
func (v *Verifier) Verify(ctx context.Context, accessToken, idToken string) (*oidc.IDTokenClaims, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Verifier) VerifyIDToken(ctx context.Context, idToken string) (*oidc.IDTokenClaims, error) {
|
func (v *Verifier) VerifyIDToken(ctx context.Context, idToken string) (*oidc.IDTokenClaims, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,8 @@ func NewClientExpectAny(t *testing.T, appType op.ApplicationType) op.Client {
|
||||||
"https://registered.com/callback",
|
"https://registered.com/callback",
|
||||||
"http://registered.com/callback",
|
"http://registered.com/callback",
|
||||||
"http://localhost:9999/callback",
|
"http://localhost:9999/callback",
|
||||||
"custom://callback"})
|
"custom://callback",
|
||||||
|
})
|
||||||
m.EXPECT().ApplicationType().AnyTimes().Return(appType)
|
m.EXPECT().ApplicationType().AnyTimes().Return(appType)
|
||||||
m.EXPECT().LoginURL(gomock.Any()).AnyTimes().DoAndReturn(
|
m.EXPECT().LoginURL(gomock.Any()).AnyTimes().DoAndReturn(
|
||||||
func(id string) string {
|
func(id string) string {
|
||||||
|
|
|
@ -44,6 +44,7 @@ func NewMockStorageSigningKeyInvalid(t *testing.T) op.Storage {
|
||||||
ExpectSigningKeyInvalid(m)
|
ExpectSigningKeyInvalid(m)
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMockStorageSigningKey(t *testing.T) op.Storage {
|
func NewMockStorageSigningKey(t *testing.T) op.Storage {
|
||||||
m := NewStorage(t)
|
m := NewStorage(t)
|
||||||
ExpectSigningKey(m)
|
ExpectSigningKey(m)
|
||||||
|
@ -120,6 +121,7 @@ func (c *ConfClient) RedirectURIs() []string {
|
||||||
"custom://callback",
|
"custom://callback",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConfClient) PostLogoutRedirectURIs() []string {
|
func (c *ConfClient) PostLogoutRedirectURIs() []string {
|
||||||
return []string{}
|
return []string{}
|
||||||
}
|
}
|
||||||
|
@ -143,34 +145,43 @@ func (c *ConfClient) GetID() string {
|
||||||
func (c *ConfClient) AccessTokenLifetime() time.Duration {
|
func (c *ConfClient) AccessTokenLifetime() time.Duration {
|
||||||
return 5 * time.Minute
|
return 5 * time.Minute
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConfClient) IDTokenLifetime() time.Duration {
|
func (c *ConfClient) IDTokenLifetime() time.Duration {
|
||||||
return 5 * time.Minute
|
return 5 * time.Minute
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConfClient) AccessTokenType() op.AccessTokenType {
|
func (c *ConfClient) AccessTokenType() op.AccessTokenType {
|
||||||
return c.accessTokenType
|
return c.accessTokenType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConfClient) ResponseTypes() []oidc.ResponseType {
|
func (c *ConfClient) ResponseTypes() []oidc.ResponseType {
|
||||||
return c.responseTypes
|
return c.responseTypes
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConfClient) GrantTypes() []oidc.GrantType {
|
func (c *ConfClient) GrantTypes() []oidc.GrantType {
|
||||||
return c.grantTypes
|
return c.grantTypes
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConfClient) DevMode() bool {
|
func (c *ConfClient) DevMode() bool {
|
||||||
return c.devMode
|
return c.devMode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConfClient) AllowedScopes() []string {
|
func (c *ConfClient) AllowedScopes() []string {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConfClient) RestrictAdditionalIdTokenScopes() func(scopes []string) []string {
|
func (c *ConfClient) RestrictAdditionalIdTokenScopes() func(scopes []string) []string {
|
||||||
return func(scopes []string) []string {
|
return func(scopes []string) []string {
|
||||||
return scopes
|
return scopes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConfClient) RestrictAdditionalAccessTokenScopes() func(scopes []string) []string {
|
func (c *ConfClient) RestrictAdditionalAccessTokenScopes() func(scopes []string) []string {
|
||||||
return func(scopes []string) []string {
|
return func(scopes []string) []string {
|
||||||
return scopes
|
return scopes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConfClient) IsScopeAllowed(scope string) bool {
|
func (c *ConfClient) IsScopeAllowed(scope string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,7 @@ const (
|
||||||
defaultKeysEndpoint = "keys"
|
defaultKeysEndpoint = "keys"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var DefaultEndpoints = &endpoints{
|
||||||
DefaultEndpoints = &endpoints{
|
|
||||||
Authorization: NewEndpoint(defaultAuthorizationEndpoint),
|
Authorization: NewEndpoint(defaultAuthorizationEndpoint),
|
||||||
Token: NewEndpoint(defaultTokenEndpoint),
|
Token: NewEndpoint(defaultTokenEndpoint),
|
||||||
Introspection: NewEndpoint(defaultIntrospectEndpoint),
|
Introspection: NewEndpoint(defaultIntrospectEndpoint),
|
||||||
|
@ -39,7 +38,6 @@ var (
|
||||||
EndSession: NewEndpoint(defaultEndSessionEndpoint),
|
EndSession: NewEndpoint(defaultEndSessionEndpoint),
|
||||||
JwksURI: NewEndpoint(defaultKeysEndpoint),
|
JwksURI: NewEndpoint(defaultKeysEndpoint),
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
type OpenIDProvider interface {
|
type OpenIDProvider interface {
|
||||||
Configuration
|
Configuration
|
||||||
|
|
|
@ -39,6 +39,7 @@ func ReadySigner(s Signer) ProbesFn {
|
||||||
return s.Health(ctx)
|
return s.Health(ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadyStorage(s Storage) ProbesFn {
|
func ReadyStorage(s Storage) ProbesFn {
|
||||||
return func(ctx context.Context) error {
|
return func(ctx context.Context) error {
|
||||||
if s == nil {
|
if s == nil {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue