2023-05-15 00:32:10 +00:00
|
|
|
package oidc_test
|
2022-04-07 05:33:53 +00:00
|
|
|
|
|
|
|
import (
|
2023-05-15 00:32:10 +00:00
|
|
|
"encoding/json"
|
2022-04-07 05:33:53 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2023-05-15 00:32:10 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2023-03-06 03:58:50 +00:00
|
|
|
|
|
|
|
"github.com/authelia/authelia/v4/internal/configuration/schema"
|
2023-05-15 00:32:10 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/oidc"
|
2022-04-07 05:33:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewOpenIDConnectWellKnownConfiguration(t *testing.T) {
|
|
|
|
testCases := []struct {
|
2022-10-20 02:16:36 +00:00
|
|
|
desc string
|
|
|
|
pkcePlainChallenge bool
|
2023-03-06 03:58:50 +00:00
|
|
|
enforcePAR bool
|
2023-05-15 00:32:10 +00:00
|
|
|
clients map[string]oidc.Client
|
2023-05-15 00:03:19 +00:00
|
|
|
discovery schema.OpenIDConnectDiscovery
|
2022-10-20 02:16:36 +00:00
|
|
|
|
2023-05-15 00:32:10 +00:00
|
|
|
expectCodeChallengeMethodsSupported, expectSubjectTypesSupported []string
|
|
|
|
expectedIDTokenSigAlgsSupported, expectedUserInfoSigAlgsSupported []string
|
|
|
|
|
|
|
|
expectedRequestObjectSigAlgsSupported, expectedRevocationSigAlgsSupported, expectedTokenAuthSigAlgsSupported []string
|
2022-04-07 05:33:53 +00:00
|
|
|
}{
|
|
|
|
{
|
2023-05-22 11:14:32 +00:00
|
|
|
desc: "ShouldHaveStandardCodeChallengeMethods",
|
2023-05-15 00:32:10 +00:00
|
|
|
pkcePlainChallenge: false,
|
|
|
|
clients: map[string]oidc.Client{"a": &oidc.BaseClient{}},
|
|
|
|
expectCodeChallengeMethodsSupported: []string{oidc.PKCEChallengeMethodSHA256},
|
|
|
|
expectSubjectTypesSupported: []string{oidc.SubjectTypePublic, oidc.SubjectTypePairwise},
|
2023-05-22 11:14:32 +00:00
|
|
|
expectedIDTokenSigAlgsSupported: []string{oidc.SigningAlgRSAUsingSHA256, oidc.SigningAlgNone},
|
2023-05-15 00:32:10 +00:00
|
|
|
expectedUserInfoSigAlgsSupported: []string{oidc.SigningAlgRSAUsingSHA256, oidc.SigningAlgNone},
|
2023-05-22 11:14:32 +00:00
|
|
|
expectedRequestObjectSigAlgsSupported: []string{oidc.SigningAlgRSAUsingSHA256, oidc.SigningAlgRSAUsingSHA384, oidc.SigningAlgRSAUsingSHA512, oidc.SigningAlgECDSAUsingP256AndSHA256, oidc.SigningAlgECDSAUsingP384AndSHA384, oidc.SigningAlgECDSAUsingP521AndSHA512, oidc.SigningAlgRSAPSSUsingSHA256, oidc.SigningAlgRSAPSSUsingSHA384, oidc.SigningAlgRSAPSSUsingSHA512, oidc.SigningAlgNone},
|
|
|
|
expectedRevocationSigAlgsSupported: []string{oidc.SigningAlgHMACUsingSHA256, oidc.SigningAlgHMACUsingSHA384, oidc.SigningAlgHMACUsingSHA512, oidc.SigningAlgRSAUsingSHA256, oidc.SigningAlgRSAUsingSHA384, oidc.SigningAlgRSAUsingSHA512, oidc.SigningAlgECDSAUsingP256AndSHA256, oidc.SigningAlgECDSAUsingP384AndSHA384, oidc.SigningAlgECDSAUsingP521AndSHA512, oidc.SigningAlgRSAPSSUsingSHA256, oidc.SigningAlgRSAPSSUsingSHA384, oidc.SigningAlgRSAPSSUsingSHA512},
|
|
|
|
expectedTokenAuthSigAlgsSupported: []string{oidc.SigningAlgHMACUsingSHA256, oidc.SigningAlgHMACUsingSHA384, oidc.SigningAlgHMACUsingSHA512, oidc.SigningAlgRSAUsingSHA256, oidc.SigningAlgRSAUsingSHA384, oidc.SigningAlgRSAUsingSHA512, oidc.SigningAlgECDSAUsingP256AndSHA256, oidc.SigningAlgECDSAUsingP384AndSHA384, oidc.SigningAlgECDSAUsingP521AndSHA512, oidc.SigningAlgRSAPSSUsingSHA256, oidc.SigningAlgRSAPSSUsingSHA384, oidc.SigningAlgRSAPSSUsingSHA512},
|
2023-05-15 00:03:19 +00:00
|
|
|
},
|
|
|
|
{
|
2023-05-22 11:14:32 +00:00
|
|
|
desc: "ShouldHaveAllCodeChallengeMethods",
|
2023-05-15 00:32:10 +00:00
|
|
|
pkcePlainChallenge: true,
|
|
|
|
clients: map[string]oidc.Client{"a": &oidc.BaseClient{}},
|
|
|
|
expectCodeChallengeMethodsSupported: []string{oidc.PKCEChallengeMethodSHA256, oidc.PKCEChallengeMethodPlain},
|
|
|
|
expectSubjectTypesSupported: []string{oidc.SubjectTypePublic, oidc.SubjectTypePairwise},
|
2023-05-22 11:14:32 +00:00
|
|
|
expectedIDTokenSigAlgsSupported: []string{oidc.SigningAlgRSAUsingSHA256, oidc.SigningAlgNone},
|
2023-05-15 00:32:10 +00:00
|
|
|
expectedUserInfoSigAlgsSupported: []string{oidc.SigningAlgRSAUsingSHA256, oidc.SigningAlgNone},
|
2023-05-22 11:14:32 +00:00
|
|
|
expectedRequestObjectSigAlgsSupported: []string{oidc.SigningAlgRSAUsingSHA256, oidc.SigningAlgRSAUsingSHA384, oidc.SigningAlgRSAUsingSHA512, oidc.SigningAlgECDSAUsingP256AndSHA256, oidc.SigningAlgECDSAUsingP384AndSHA384, oidc.SigningAlgECDSAUsingP521AndSHA512, oidc.SigningAlgRSAPSSUsingSHA256, oidc.SigningAlgRSAPSSUsingSHA384, oidc.SigningAlgRSAPSSUsingSHA512, oidc.SigningAlgNone},
|
|
|
|
expectedRevocationSigAlgsSupported: []string{oidc.SigningAlgHMACUsingSHA256, oidc.SigningAlgHMACUsingSHA384, oidc.SigningAlgHMACUsingSHA512, oidc.SigningAlgRSAUsingSHA256, oidc.SigningAlgRSAUsingSHA384, oidc.SigningAlgRSAUsingSHA512, oidc.SigningAlgECDSAUsingP256AndSHA256, oidc.SigningAlgECDSAUsingP384AndSHA384, oidc.SigningAlgECDSAUsingP521AndSHA512, oidc.SigningAlgRSAPSSUsingSHA256, oidc.SigningAlgRSAPSSUsingSHA384, oidc.SigningAlgRSAPSSUsingSHA512},
|
|
|
|
expectedTokenAuthSigAlgsSupported: []string{oidc.SigningAlgHMACUsingSHA256, oidc.SigningAlgHMACUsingSHA384, oidc.SigningAlgHMACUsingSHA512, oidc.SigningAlgRSAUsingSHA256, oidc.SigningAlgRSAUsingSHA384, oidc.SigningAlgRSAUsingSHA512, oidc.SigningAlgECDSAUsingP256AndSHA256, oidc.SigningAlgECDSAUsingP384AndSHA384, oidc.SigningAlgECDSAUsingP521AndSHA512, oidc.SigningAlgRSAPSSUsingSHA256, oidc.SigningAlgRSAPSSUsingSHA384, oidc.SigningAlgRSAPSSUsingSHA512},
|
2023-05-15 00:03:19 +00:00
|
|
|
},
|
|
|
|
{
|
2023-05-22 11:14:32 +00:00
|
|
|
desc: "ShouldIncludeDiscoveredResponseObjectSigningAlgs",
|
|
|
|
pkcePlainChallenge: false,
|
|
|
|
clients: map[string]oidc.Client{"a": &oidc.BaseClient{}},
|
|
|
|
discovery: schema.OpenIDConnectDiscovery{
|
|
|
|
ResponseObjectSigningAlgs: []string{oidc.SigningAlgECDSAUsingP521AndSHA512},
|
2022-10-20 02:16:36 +00:00
|
|
|
},
|
2023-05-22 11:14:32 +00:00
|
|
|
expectCodeChallengeMethodsSupported: []string{oidc.PKCEChallengeMethodSHA256},
|
2023-05-15 00:32:10 +00:00
|
|
|
expectSubjectTypesSupported: []string{oidc.SubjectTypePublic, oidc.SubjectTypePairwise},
|
2023-05-22 11:14:32 +00:00
|
|
|
expectedIDTokenSigAlgsSupported: []string{oidc.SigningAlgRSAUsingSHA256, oidc.SigningAlgECDSAUsingP521AndSHA512, oidc.SigningAlgNone},
|
|
|
|
expectedUserInfoSigAlgsSupported: []string{oidc.SigningAlgRSAUsingSHA256, oidc.SigningAlgECDSAUsingP521AndSHA512, oidc.SigningAlgNone},
|
|
|
|
expectedRequestObjectSigAlgsSupported: []string{oidc.SigningAlgRSAUsingSHA256, oidc.SigningAlgRSAUsingSHA384, oidc.SigningAlgRSAUsingSHA512, oidc.SigningAlgECDSAUsingP256AndSHA256, oidc.SigningAlgECDSAUsingP384AndSHA384, oidc.SigningAlgECDSAUsingP521AndSHA512, oidc.SigningAlgRSAPSSUsingSHA256, oidc.SigningAlgRSAPSSUsingSHA384, oidc.SigningAlgRSAPSSUsingSHA512, oidc.SigningAlgNone},
|
|
|
|
expectedRevocationSigAlgsSupported: []string{oidc.SigningAlgHMACUsingSHA256, oidc.SigningAlgHMACUsingSHA384, oidc.SigningAlgHMACUsingSHA512, oidc.SigningAlgRSAUsingSHA256, oidc.SigningAlgRSAUsingSHA384, oidc.SigningAlgRSAUsingSHA512, oidc.SigningAlgECDSAUsingP256AndSHA256, oidc.SigningAlgECDSAUsingP384AndSHA384, oidc.SigningAlgECDSAUsingP521AndSHA512, oidc.SigningAlgRSAPSSUsingSHA256, oidc.SigningAlgRSAPSSUsingSHA384, oidc.SigningAlgRSAPSSUsingSHA512},
|
|
|
|
expectedTokenAuthSigAlgsSupported: []string{oidc.SigningAlgHMACUsingSHA256, oidc.SigningAlgHMACUsingSHA384, oidc.SigningAlgHMACUsingSHA512, oidc.SigningAlgRSAUsingSHA256, oidc.SigningAlgRSAUsingSHA384, oidc.SigningAlgRSAUsingSHA512, oidc.SigningAlgECDSAUsingP256AndSHA256, oidc.SigningAlgECDSAUsingP384AndSHA384, oidc.SigningAlgECDSAUsingP521AndSHA512, oidc.SigningAlgRSAPSSUsingSHA256, oidc.SigningAlgRSAPSSUsingSHA384, oidc.SigningAlgRSAPSSUsingSHA512},
|
2022-04-07 05:33:53 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
t.Run(tc.desc, func(t *testing.T) {
|
2023-01-26 02:23:47 +00:00
|
|
|
c := schema.IdentityProvidersOpenIDConnect{
|
2023-03-06 03:58:50 +00:00
|
|
|
EnablePKCEPlainChallenge: tc.pkcePlainChallenge,
|
2023-01-26 02:23:47 +00:00
|
|
|
PAR: schema.IdentityProvidersOpenIDConnectPAR{
|
2023-03-06 03:58:50 +00:00
|
|
|
Enforce: tc.enforcePAR,
|
|
|
|
},
|
2023-05-15 00:03:19 +00:00
|
|
|
Discovery: tc.discovery,
|
2023-03-06 03:58:50 +00:00
|
|
|
}
|
|
|
|
|
2023-05-15 00:32:10 +00:00
|
|
|
actual := oidc.NewOpenIDConnectWellKnownConfiguration(&c)
|
2022-04-07 05:33:53 +00:00
|
|
|
for _, codeChallengeMethod := range tc.expectCodeChallengeMethodsSupported {
|
|
|
|
assert.Contains(t, actual.CodeChallengeMethodsSupported, codeChallengeMethod)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, subjectType := range tc.expectSubjectTypesSupported {
|
|
|
|
assert.Contains(t, actual.SubjectTypesSupported, subjectType)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, codeChallengeMethod := range actual.CodeChallengeMethodsSupported {
|
|
|
|
assert.Contains(t, tc.expectCodeChallengeMethodsSupported, codeChallengeMethod)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, subjectType := range actual.SubjectTypesSupported {
|
|
|
|
assert.Contains(t, tc.expectSubjectTypesSupported, subjectType)
|
|
|
|
}
|
2023-05-15 00:03:19 +00:00
|
|
|
|
|
|
|
assert.Equal(t, tc.expectedUserInfoSigAlgsSupported, actual.UserinfoSigningAlgValuesSupported)
|
|
|
|
assert.Equal(t, tc.expectedIDTokenSigAlgsSupported, actual.IDTokenSigningAlgValuesSupported)
|
2023-05-15 00:32:10 +00:00
|
|
|
assert.Equal(t, tc.expectedRequestObjectSigAlgsSupported, actual.RequestObjectSigningAlgValuesSupported)
|
|
|
|
assert.Equal(t, tc.expectedRevocationSigAlgsSupported, actual.RevocationEndpointAuthSigningAlgValuesSupported)
|
|
|
|
assert.Equal(t, tc.expectedTokenAuthSigAlgsSupported, actual.TokenEndpointAuthSigningAlgValuesSupported)
|
2022-04-07 05:33:53 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2023-05-15 00:32:10 +00:00
|
|
|
|
|
|
|
func TestNewOpenIDConnectProviderDiscovery(t *testing.T) {
|
2023-01-26 02:23:47 +00:00
|
|
|
provider := oidc.NewOpenIDConnectProvider(&schema.IdentityProvidersOpenIDConnect{
|
2023-05-15 00:32:10 +00:00
|
|
|
IssuerCertificateChain: schema.X509CertificateChain{},
|
|
|
|
IssuerPrivateKey: keyRSA2048,
|
|
|
|
HMACSecret: "asbdhaaskmdlkamdklasmdlkams",
|
|
|
|
EnablePKCEPlainChallenge: true,
|
2023-01-26 02:23:47 +00:00
|
|
|
Clients: []schema.IdentityProvidersOpenIDConnectClient{
|
2023-05-15 00:32:10 +00:00
|
|
|
{
|
|
|
|
ID: "a-client",
|
|
|
|
Secret: tOpenIDConnectPlainTextClientSecret,
|
|
|
|
Policy: onefactor,
|
|
|
|
RedirectURIs: []string{
|
|
|
|
"https://google.com",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, nil, nil)
|
|
|
|
|
|
|
|
a := provider.GetOpenIDConnectWellKnownConfiguration("https://auth.example.com")
|
|
|
|
|
|
|
|
data, err := json.Marshal(&a)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
b := oidc.OpenIDConnectWellKnownConfiguration{}
|
|
|
|
|
|
|
|
assert.NoError(t, json.Unmarshal(data, &b))
|
|
|
|
|
|
|
|
assert.Equal(t, a, b)
|
|
|
|
|
|
|
|
y := provider.GetOAuth2WellKnownConfiguration("https://auth.example.com")
|
|
|
|
|
|
|
|
data, err = json.Marshal(&y)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
z := oidc.OAuth2WellKnownConfiguration{}
|
|
|
|
|
|
|
|
assert.NoError(t, json.Unmarshal(data, &z))
|
|
|
|
|
|
|
|
assert.Equal(t, y, z)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewOpenIDConnectProvider_GetOpenIDConnectWellKnownConfiguration(t *testing.T) {
|
2023-01-26 02:23:47 +00:00
|
|
|
provider := oidc.NewOpenIDConnectProvider(&schema.IdentityProvidersOpenIDConnect{
|
2023-05-15 00:32:10 +00:00
|
|
|
IssuerCertificateChain: schema.X509CertificateChain{},
|
|
|
|
IssuerPrivateKey: keyRSA2048,
|
|
|
|
HMACSecret: "asbdhaaskmdlkamdklasmdlkams",
|
2023-01-26 02:23:47 +00:00
|
|
|
Clients: []schema.IdentityProvidersOpenIDConnectClient{
|
2023-05-15 00:32:10 +00:00
|
|
|
{
|
|
|
|
ID: "a-client",
|
|
|
|
Secret: tOpenIDConnectPlainTextClientSecret,
|
|
|
|
Policy: onefactor,
|
|
|
|
RedirectURIs: []string{
|
|
|
|
"https://google.com",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, nil, nil)
|
|
|
|
|
|
|
|
require.NotNil(t, provider)
|
|
|
|
|
|
|
|
disco := provider.GetOpenIDConnectWellKnownConfiguration(examplecom)
|
|
|
|
|
|
|
|
assert.Equal(t, examplecom, disco.Issuer)
|
|
|
|
assert.Equal(t, "https://example.com/jwks.json", disco.JWKSURI)
|
|
|
|
assert.Equal(t, "https://example.com/api/oidc/authorization", disco.AuthorizationEndpoint)
|
|
|
|
assert.Equal(t, "https://example.com/api/oidc/token", disco.TokenEndpoint)
|
|
|
|
assert.Equal(t, "https://example.com/api/oidc/userinfo", disco.UserinfoEndpoint)
|
|
|
|
assert.Equal(t, "https://example.com/api/oidc/introspection", disco.IntrospectionEndpoint)
|
|
|
|
assert.Equal(t, "https://example.com/api/oidc/revocation", disco.RevocationEndpoint)
|
|
|
|
assert.Equal(t, "", disco.RegistrationEndpoint)
|
|
|
|
|
|
|
|
assert.Len(t, disco.CodeChallengeMethodsSupported, 1)
|
|
|
|
assert.Contains(t, disco.CodeChallengeMethodsSupported, oidc.PKCEChallengeMethodSHA256)
|
|
|
|
|
|
|
|
assert.Len(t, disco.ScopesSupported, 5)
|
|
|
|
assert.Contains(t, disco.ScopesSupported, oidc.ScopeOpenID)
|
|
|
|
assert.Contains(t, disco.ScopesSupported, oidc.ScopeOfflineAccess)
|
|
|
|
assert.Contains(t, disco.ScopesSupported, oidc.ScopeProfile)
|
|
|
|
assert.Contains(t, disco.ScopesSupported, oidc.ScopeGroups)
|
|
|
|
assert.Contains(t, disco.ScopesSupported, oidc.ScopeEmail)
|
|
|
|
|
|
|
|
assert.Len(t, disco.ResponseModesSupported, 3)
|
|
|
|
assert.Contains(t, disco.ResponseModesSupported, oidc.ResponseModeFormPost)
|
|
|
|
assert.Contains(t, disco.ResponseModesSupported, oidc.ResponseModeQuery)
|
|
|
|
assert.Contains(t, disco.ResponseModesSupported, oidc.ResponseModeFragment)
|
|
|
|
|
|
|
|
assert.Len(t, disco.SubjectTypesSupported, 2)
|
|
|
|
assert.Contains(t, disco.SubjectTypesSupported, oidc.SubjectTypePublic)
|
|
|
|
assert.Contains(t, disco.SubjectTypesSupported, oidc.SubjectTypePairwise)
|
|
|
|
|
|
|
|
assert.Len(t, disco.ResponseTypesSupported, 7)
|
|
|
|
assert.Contains(t, disco.ResponseTypesSupported, oidc.ResponseTypeAuthorizationCodeFlow)
|
|
|
|
assert.Contains(t, disco.ResponseTypesSupported, oidc.ResponseTypeImplicitFlowIDToken)
|
|
|
|
assert.Contains(t, disco.ResponseTypesSupported, oidc.ResponseTypeImplicitFlowToken)
|
|
|
|
assert.Contains(t, disco.ResponseTypesSupported, oidc.ResponseTypeImplicitFlowBoth)
|
|
|
|
assert.Contains(t, disco.ResponseTypesSupported, oidc.ResponseTypeHybridFlowIDToken)
|
|
|
|
assert.Contains(t, disco.ResponseTypesSupported, oidc.ResponseTypeHybridFlowToken)
|
|
|
|
assert.Contains(t, disco.ResponseTypesSupported, oidc.ResponseTypeHybridFlowBoth)
|
|
|
|
|
|
|
|
assert.Len(t, disco.TokenEndpointAuthMethodsSupported, 5)
|
|
|
|
assert.Contains(t, disco.TokenEndpointAuthMethodsSupported, oidc.ClientAuthMethodClientSecretBasic)
|
|
|
|
assert.Contains(t, disco.TokenEndpointAuthMethodsSupported, oidc.ClientAuthMethodClientSecretPost)
|
|
|
|
assert.Contains(t, disco.TokenEndpointAuthMethodsSupported, oidc.ClientAuthMethodClientSecretJWT)
|
|
|
|
assert.Contains(t, disco.TokenEndpointAuthMethodsSupported, oidc.ClientAuthMethodPrivateKeyJWT)
|
|
|
|
assert.Contains(t, disco.TokenEndpointAuthMethodsSupported, oidc.ClientAuthMethodNone)
|
|
|
|
|
|
|
|
assert.Len(t, disco.RevocationEndpointAuthMethodsSupported, 5)
|
|
|
|
assert.Contains(t, disco.RevocationEndpointAuthMethodsSupported, oidc.ClientAuthMethodClientSecretBasic)
|
|
|
|
assert.Contains(t, disco.RevocationEndpointAuthMethodsSupported, oidc.ClientAuthMethodClientSecretPost)
|
|
|
|
assert.Contains(t, disco.RevocationEndpointAuthMethodsSupported, oidc.ClientAuthMethodClientSecretJWT)
|
|
|
|
assert.Contains(t, disco.RevocationEndpointAuthMethodsSupported, oidc.ClientAuthMethodPrivateKeyJWT)
|
|
|
|
assert.Contains(t, disco.RevocationEndpointAuthMethodsSupported, oidc.ClientAuthMethodNone)
|
|
|
|
|
2023-05-22 11:14:32 +00:00
|
|
|
assert.Equal(t, []string{oidc.ClientAuthMethodClientSecretBasic, oidc.ClientAuthMethodNone}, disco.IntrospectionEndpointAuthMethodsSupported)
|
|
|
|
assert.Equal(t, []string{oidc.GrantTypeAuthorizationCode, oidc.GrantTypeImplicit, oidc.GrantTypeRefreshToken}, disco.GrantTypesSupported)
|
|
|
|
assert.Equal(t, []string{oidc.SigningAlgHMACUsingSHA256, oidc.SigningAlgHMACUsingSHA384, oidc.SigningAlgHMACUsingSHA512, oidc.SigningAlgRSAUsingSHA256, oidc.SigningAlgRSAUsingSHA384, oidc.SigningAlgRSAUsingSHA512, oidc.SigningAlgECDSAUsingP256AndSHA256, oidc.SigningAlgECDSAUsingP384AndSHA384, oidc.SigningAlgECDSAUsingP521AndSHA512, oidc.SigningAlgRSAPSSUsingSHA256, oidc.SigningAlgRSAPSSUsingSHA384, oidc.SigningAlgRSAPSSUsingSHA512}, disco.RevocationEndpointAuthSigningAlgValuesSupported)
|
|
|
|
assert.Equal(t, []string{oidc.SigningAlgHMACUsingSHA256, oidc.SigningAlgHMACUsingSHA384, oidc.SigningAlgHMACUsingSHA512, oidc.SigningAlgRSAUsingSHA256, oidc.SigningAlgRSAUsingSHA384, oidc.SigningAlgRSAUsingSHA512, oidc.SigningAlgECDSAUsingP256AndSHA256, oidc.SigningAlgECDSAUsingP384AndSHA384, oidc.SigningAlgECDSAUsingP521AndSHA512, oidc.SigningAlgRSAPSSUsingSHA256, oidc.SigningAlgRSAPSSUsingSHA384, oidc.SigningAlgRSAPSSUsingSHA512}, disco.TokenEndpointAuthSigningAlgValuesSupported)
|
|
|
|
assert.Equal(t, []string{oidc.SigningAlgRSAUsingSHA256, oidc.SigningAlgNone}, disco.IDTokenSigningAlgValuesSupported)
|
|
|
|
assert.Equal(t, []string{oidc.SigningAlgRSAUsingSHA256, oidc.SigningAlgNone}, disco.UserinfoSigningAlgValuesSupported)
|
|
|
|
assert.Equal(t, []string{oidc.SigningAlgRSAUsingSHA256, oidc.SigningAlgRSAUsingSHA384, oidc.SigningAlgRSAUsingSHA512, oidc.SigningAlgECDSAUsingP256AndSHA256, oidc.SigningAlgECDSAUsingP384AndSHA384, oidc.SigningAlgECDSAUsingP521AndSHA512, oidc.SigningAlgRSAPSSUsingSHA256, oidc.SigningAlgRSAPSSUsingSHA384, oidc.SigningAlgRSAPSSUsingSHA512, oidc.SigningAlgNone}, disco.RequestObjectSigningAlgValuesSupported)
|
2023-05-15 00:32:10 +00:00
|
|
|
|
|
|
|
assert.Len(t, disco.ClaimsSupported, 18)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimAuthenticationMethodsReference)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimAudience)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimAuthorizedParty)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimClientIdentifier)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimExpirationTime)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimIssuedAt)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimIssuer)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimJWTID)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimRequestedAt)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimSubject)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimAuthenticationTime)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimNonce)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimPreferredEmail)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimEmailVerified)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimEmailAlts)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimGroups)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimPreferredUsername)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimFullName)
|
|
|
|
|
|
|
|
assert.Len(t, disco.PromptValuesSupported, 2)
|
|
|
|
assert.Contains(t, disco.PromptValuesSupported, oidc.PromptConsent)
|
|
|
|
assert.Contains(t, disco.PromptValuesSupported, oidc.PromptNone)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewOpenIDConnectProvider_GetOAuth2WellKnownConfiguration(t *testing.T) {
|
2023-01-26 02:23:47 +00:00
|
|
|
provider := oidc.NewOpenIDConnectProvider(&schema.IdentityProvidersOpenIDConnect{
|
2023-05-15 00:32:10 +00:00
|
|
|
IssuerCertificateChain: schema.X509CertificateChain{},
|
|
|
|
IssuerPrivateKey: keyRSA2048,
|
|
|
|
HMACSecret: "asbdhaaskmdlkamdklasmdlkams",
|
2023-01-26 02:23:47 +00:00
|
|
|
Clients: []schema.IdentityProvidersOpenIDConnectClient{
|
2023-05-15 00:32:10 +00:00
|
|
|
{
|
|
|
|
ID: "a-client",
|
|
|
|
Secret: tOpenIDConnectPlainTextClientSecret,
|
|
|
|
Policy: onefactor,
|
|
|
|
RedirectURIs: []string{
|
|
|
|
"https://google.com",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, nil, nil)
|
|
|
|
|
|
|
|
require.NotNil(t, provider)
|
|
|
|
|
|
|
|
disco := provider.GetOAuth2WellKnownConfiguration(examplecom)
|
|
|
|
|
|
|
|
assert.Equal(t, examplecom, disco.Issuer)
|
|
|
|
assert.Equal(t, "https://example.com/jwks.json", disco.JWKSURI)
|
|
|
|
assert.Equal(t, "https://example.com/api/oidc/authorization", disco.AuthorizationEndpoint)
|
|
|
|
assert.Equal(t, "https://example.com/api/oidc/token", disco.TokenEndpoint)
|
|
|
|
assert.Equal(t, "https://example.com/api/oidc/introspection", disco.IntrospectionEndpoint)
|
|
|
|
assert.Equal(t, "https://example.com/api/oidc/revocation", disco.RevocationEndpoint)
|
|
|
|
assert.Equal(t, "", disco.RegistrationEndpoint)
|
|
|
|
|
|
|
|
require.Len(t, disco.CodeChallengeMethodsSupported, 1)
|
|
|
|
assert.Equal(t, "S256", disco.CodeChallengeMethodsSupported[0])
|
|
|
|
|
|
|
|
assert.Len(t, disco.ScopesSupported, 5)
|
|
|
|
assert.Contains(t, disco.ScopesSupported, oidc.ScopeOpenID)
|
|
|
|
assert.Contains(t, disco.ScopesSupported, oidc.ScopeOfflineAccess)
|
|
|
|
assert.Contains(t, disco.ScopesSupported, oidc.ScopeProfile)
|
|
|
|
assert.Contains(t, disco.ScopesSupported, oidc.ScopeGroups)
|
|
|
|
assert.Contains(t, disco.ScopesSupported, oidc.ScopeEmail)
|
|
|
|
|
|
|
|
assert.Len(t, disco.ResponseModesSupported, 3)
|
|
|
|
assert.Contains(t, disco.ResponseModesSupported, oidc.ResponseModeFormPost)
|
|
|
|
assert.Contains(t, disco.ResponseModesSupported, oidc.ResponseModeQuery)
|
|
|
|
assert.Contains(t, disco.ResponseModesSupported, oidc.ResponseModeFragment)
|
|
|
|
|
|
|
|
assert.Len(t, disco.SubjectTypesSupported, 2)
|
|
|
|
assert.Contains(t, disco.SubjectTypesSupported, oidc.SubjectTypePublic)
|
|
|
|
assert.Contains(t, disco.SubjectTypesSupported, oidc.SubjectTypePairwise)
|
|
|
|
|
|
|
|
assert.Len(t, disco.ResponseTypesSupported, 7)
|
|
|
|
assert.Contains(t, disco.ResponseTypesSupported, oidc.ResponseTypeAuthorizationCodeFlow)
|
|
|
|
assert.Contains(t, disco.ResponseTypesSupported, oidc.ResponseTypeImplicitFlowIDToken)
|
|
|
|
assert.Contains(t, disco.ResponseTypesSupported, oidc.ResponseTypeImplicitFlowToken)
|
|
|
|
assert.Contains(t, disco.ResponseTypesSupported, oidc.ResponseTypeImplicitFlowBoth)
|
|
|
|
assert.Contains(t, disco.ResponseTypesSupported, oidc.ResponseTypeHybridFlowIDToken)
|
|
|
|
assert.Contains(t, disco.ResponseTypesSupported, oidc.ResponseTypeHybridFlowToken)
|
|
|
|
assert.Contains(t, disco.ResponseTypesSupported, oidc.ResponseTypeHybridFlowBoth)
|
|
|
|
|
|
|
|
assert.Len(t, disco.TokenEndpointAuthMethodsSupported, 5)
|
|
|
|
assert.Contains(t, disco.TokenEndpointAuthMethodsSupported, oidc.ClientAuthMethodClientSecretBasic)
|
|
|
|
assert.Contains(t, disco.TokenEndpointAuthMethodsSupported, oidc.ClientAuthMethodClientSecretPost)
|
|
|
|
assert.Contains(t, disco.TokenEndpointAuthMethodsSupported, oidc.ClientAuthMethodClientSecretJWT)
|
|
|
|
assert.Contains(t, disco.TokenEndpointAuthMethodsSupported, oidc.ClientAuthMethodPrivateKeyJWT)
|
|
|
|
assert.Contains(t, disco.TokenEndpointAuthMethodsSupported, oidc.ClientAuthMethodNone)
|
|
|
|
|
|
|
|
assert.Len(t, disco.GrantTypesSupported, 3)
|
|
|
|
assert.Contains(t, disco.GrantTypesSupported, oidc.GrantTypeAuthorizationCode)
|
|
|
|
assert.Contains(t, disco.GrantTypesSupported, oidc.GrantTypeRefreshToken)
|
|
|
|
assert.Contains(t, disco.GrantTypesSupported, oidc.GrantTypeImplicit)
|
|
|
|
|
|
|
|
assert.Len(t, disco.ClaimsSupported, 18)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimAuthenticationMethodsReference)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimAudience)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimAuthorizedParty)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimClientIdentifier)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimExpirationTime)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimIssuedAt)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimIssuer)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimJWTID)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimRequestedAt)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimSubject)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimAuthenticationTime)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimNonce)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimPreferredEmail)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimEmailVerified)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimEmailAlts)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimGroups)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimPreferredUsername)
|
|
|
|
assert.Contains(t, disco.ClaimsSupported, oidc.ClaimFullName)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewOpenIDConnectProvider_GetOpenIDConnectWellKnownConfigurationWithPlainPKCE(t *testing.T) {
|
2023-01-26 02:23:47 +00:00
|
|
|
provider := oidc.NewOpenIDConnectProvider(&schema.IdentityProvidersOpenIDConnect{
|
2023-05-15 00:32:10 +00:00
|
|
|
IssuerCertificateChain: schema.X509CertificateChain{},
|
|
|
|
IssuerPrivateKey: keyRSA2048,
|
|
|
|
HMACSecret: "asbdhaaskmdlkamdklasmdlkams",
|
|
|
|
EnablePKCEPlainChallenge: true,
|
2023-01-26 02:23:47 +00:00
|
|
|
Clients: []schema.IdentityProvidersOpenIDConnectClient{
|
2023-05-15 00:32:10 +00:00
|
|
|
{
|
|
|
|
ID: "a-client",
|
|
|
|
Secret: tOpenIDConnectPlainTextClientSecret,
|
|
|
|
Policy: onefactor,
|
|
|
|
RedirectURIs: []string{
|
|
|
|
"https://google.com",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, nil, nil)
|
|
|
|
|
|
|
|
require.NotNil(t, provider)
|
|
|
|
|
|
|
|
disco := provider.GetOpenIDConnectWellKnownConfiguration(examplecom)
|
|
|
|
|
|
|
|
require.Len(t, disco.CodeChallengeMethodsSupported, 2)
|
|
|
|
assert.Equal(t, oidc.PKCEChallengeMethodSHA256, disco.CodeChallengeMethodsSupported[0])
|
|
|
|
assert.Equal(t, oidc.PKCEChallengeMethodPlain, disco.CodeChallengeMethodsSupported[1])
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewOpenIDConnectWellKnownConfiguration_Copy(t *testing.T) {
|
|
|
|
config := &oidc.OpenIDConnectWellKnownConfiguration{
|
|
|
|
OAuth2WellKnownConfiguration: oidc.OAuth2WellKnownConfiguration{
|
|
|
|
CommonDiscoveryOptions: oidc.CommonDiscoveryOptions{
|
|
|
|
Issuer: "https://example.com",
|
|
|
|
JWKSURI: "https://example.com/jwks.json",
|
|
|
|
AuthorizationEndpoint: "",
|
|
|
|
TokenEndpoint: "",
|
|
|
|
SubjectTypesSupported: nil,
|
|
|
|
ResponseTypesSupported: nil,
|
|
|
|
GrantTypesSupported: nil,
|
|
|
|
ResponseModesSupported: nil,
|
|
|
|
ScopesSupported: nil,
|
|
|
|
ClaimsSupported: nil,
|
|
|
|
UILocalesSupported: nil,
|
|
|
|
TokenEndpointAuthMethodsSupported: nil,
|
|
|
|
TokenEndpointAuthSigningAlgValuesSupported: nil,
|
|
|
|
ServiceDocumentation: "",
|
|
|
|
OPPolicyURI: "",
|
|
|
|
OPTOSURI: "",
|
|
|
|
SignedMetadata: "",
|
|
|
|
},
|
|
|
|
OAuth2DiscoveryOptions: oidc.OAuth2DiscoveryOptions{
|
|
|
|
IntrospectionEndpoint: "",
|
|
|
|
RevocationEndpoint: "",
|
|
|
|
RegistrationEndpoint: "",
|
|
|
|
IntrospectionEndpointAuthMethodsSupported: nil,
|
|
|
|
RevocationEndpointAuthMethodsSupported: nil,
|
|
|
|
RevocationEndpointAuthSigningAlgValuesSupported: nil,
|
|
|
|
IntrospectionEndpointAuthSigningAlgValuesSupported: nil,
|
|
|
|
CodeChallengeMethodsSupported: nil,
|
|
|
|
},
|
|
|
|
OAuth2DeviceAuthorizationGrantDiscoveryOptions: &oidc.OAuth2DeviceAuthorizationGrantDiscoveryOptions{
|
|
|
|
DeviceAuthorizationEndpoint: "",
|
|
|
|
},
|
|
|
|
OAuth2MutualTLSClientAuthenticationDiscoveryOptions: &oidc.OAuth2MutualTLSClientAuthenticationDiscoveryOptions{
|
|
|
|
TLSClientCertificateBoundAccessTokens: false,
|
|
|
|
MutualTLSEndpointAliases: oidc.OAuth2MutualTLSClientAuthenticationAliasesDiscoveryOptions{
|
|
|
|
AuthorizationEndpoint: "",
|
|
|
|
TokenEndpoint: "",
|
|
|
|
IntrospectionEndpoint: "",
|
|
|
|
RevocationEndpoint: "",
|
|
|
|
EndSessionEndpoint: "",
|
|
|
|
UserinfoEndpoint: "",
|
|
|
|
BackChannelAuthenticationEndpoint: "",
|
|
|
|
FederationRegistrationEndpoint: "",
|
|
|
|
PushedAuthorizationRequestEndpoint: "",
|
|
|
|
RegistrationEndpoint: "",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
OAuth2IssuerIdentificationDiscoveryOptions: &oidc.OAuth2IssuerIdentificationDiscoveryOptions{
|
|
|
|
AuthorizationResponseIssuerParameterSupported: false,
|
|
|
|
},
|
|
|
|
OAuth2JWTIntrospectionResponseDiscoveryOptions: &oidc.OAuth2JWTIntrospectionResponseDiscoveryOptions{
|
|
|
|
IntrospectionSigningAlgValuesSupported: nil,
|
|
|
|
IntrospectionEncryptionAlgValuesSupported: nil,
|
|
|
|
IntrospectionEncryptionEncValuesSupported: nil,
|
|
|
|
},
|
|
|
|
OAuth2JWTSecuredAuthorizationRequestDiscoveryOptions: &oidc.OAuth2JWTSecuredAuthorizationRequestDiscoveryOptions{
|
|
|
|
RequireSignedRequestObject: false,
|
|
|
|
},
|
|
|
|
OAuth2PushedAuthorizationDiscoveryOptions: &oidc.OAuth2PushedAuthorizationDiscoveryOptions{
|
|
|
|
PushedAuthorizationRequestEndpoint: "",
|
|
|
|
RequirePushedAuthorizationRequests: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
OpenIDConnectDiscoveryOptions: oidc.OpenIDConnectDiscoveryOptions{
|
|
|
|
UserinfoEndpoint: "",
|
|
|
|
IDTokenSigningAlgValuesSupported: nil,
|
|
|
|
UserinfoSigningAlgValuesSupported: nil,
|
|
|
|
RequestObjectSigningAlgValuesSupported: nil,
|
|
|
|
IDTokenEncryptionAlgValuesSupported: nil,
|
|
|
|
UserinfoEncryptionAlgValuesSupported: nil,
|
|
|
|
RequestObjectEncryptionAlgValuesSupported: nil,
|
|
|
|
IDTokenEncryptionEncValuesSupported: nil,
|
|
|
|
UserinfoEncryptionEncValuesSupported: nil,
|
|
|
|
RequestObjectEncryptionEncValuesSupported: nil,
|
|
|
|
ACRValuesSupported: nil,
|
|
|
|
DisplayValuesSupported: nil,
|
|
|
|
ClaimTypesSupported: nil,
|
|
|
|
ClaimLocalesSupported: nil,
|
|
|
|
RequestParameterSupported: false,
|
|
|
|
RequestURIParameterSupported: false,
|
|
|
|
RequireRequestURIRegistration: false,
|
|
|
|
ClaimsParameterSupported: false,
|
|
|
|
},
|
|
|
|
OpenIDConnectFrontChannelLogoutDiscoveryOptions: &oidc.OpenIDConnectFrontChannelLogoutDiscoveryOptions{
|
|
|
|
FrontChannelLogoutSupported: false,
|
|
|
|
FrontChannelLogoutSessionSupported: false,
|
|
|
|
},
|
|
|
|
OpenIDConnectBackChannelLogoutDiscoveryOptions: &oidc.OpenIDConnectBackChannelLogoutDiscoveryOptions{
|
|
|
|
BackChannelLogoutSupported: false,
|
|
|
|
BackChannelLogoutSessionSupported: false,
|
|
|
|
},
|
|
|
|
OpenIDConnectSessionManagementDiscoveryOptions: &oidc.OpenIDConnectSessionManagementDiscoveryOptions{
|
|
|
|
CheckSessionIFrame: "",
|
|
|
|
},
|
|
|
|
OpenIDConnectRPInitiatedLogoutDiscoveryOptions: &oidc.OpenIDConnectRPInitiatedLogoutDiscoveryOptions{
|
|
|
|
EndSessionEndpoint: "",
|
|
|
|
},
|
|
|
|
OpenIDConnectPromptCreateDiscoveryOptions: &oidc.OpenIDConnectPromptCreateDiscoveryOptions{
|
|
|
|
PromptValuesSupported: nil,
|
|
|
|
},
|
|
|
|
OpenIDConnectClientInitiatedBackChannelAuthFlowDiscoveryOptions: &oidc.OpenIDConnectClientInitiatedBackChannelAuthFlowDiscoveryOptions{
|
|
|
|
BackChannelAuthenticationEndpoint: "",
|
|
|
|
BackChannelTokenDeliveryModesSupported: nil,
|
|
|
|
BackChannelAuthRequestSigningAlgValuesSupported: nil,
|
|
|
|
BackChannelUserCodeParameterSupported: false,
|
|
|
|
},
|
|
|
|
OpenIDConnectJWTSecuredAuthorizationResponseModeDiscoveryOptions: &oidc.OpenIDConnectJWTSecuredAuthorizationResponseModeDiscoveryOptions{
|
|
|
|
AuthorizationSigningAlgValuesSupported: nil,
|
|
|
|
AuthorizationEncryptionAlgValuesSupported: nil,
|
|
|
|
AuthorizationEncryptionEncValuesSupported: nil,
|
|
|
|
},
|
|
|
|
OpenIDFederationDiscoveryOptions: &oidc.OpenIDFederationDiscoveryOptions{
|
|
|
|
FederationRegistrationEndpoint: "",
|
|
|
|
ClientRegistrationTypesSupported: nil,
|
|
|
|
RequestAuthenticationMethodsSupported: nil,
|
|
|
|
RequestAuthenticationSigningAlgValuesSupproted: nil,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
x := config.Copy()
|
|
|
|
|
|
|
|
assert.Equal(t, config, &x)
|
|
|
|
|
|
|
|
y := config.OAuth2WellKnownConfiguration.Copy()
|
|
|
|
|
|
|
|
assert.Equal(t, config.OAuth2WellKnownConfiguration, y)
|
|
|
|
}
|