2021-05-04 22:06:05 +00:00
|
|
|
package validator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/url"
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
"strings"
|
|
|
|
"time"
|
2021-05-04 22:06:05 +00:00
|
|
|
|
2021-08-11 01:04:35 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/configuration/schema"
|
2022-10-20 02:16:36 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/oidc"
|
2021-08-11 01:04:35 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/utils"
|
2021-05-04 22:06:05 +00:00
|
|
|
)
|
|
|
|
|
2022-04-17 23:58:24 +00:00
|
|
|
// ValidateIdentityProviders validates and updates the IdentityProviders configuration.
|
2022-11-23 23:16:23 +00:00
|
|
|
func ValidateIdentityProviders(config *schema.IdentityProvidersConfiguration, val *schema.StructValidator) {
|
|
|
|
validateOIDC(config.OIDC, val)
|
2021-05-04 22:06:05 +00:00
|
|
|
}
|
|
|
|
|
2022-11-23 23:16:23 +00:00
|
|
|
func validateOIDC(config *schema.OpenIDConnectConfiguration, val *schema.StructValidator) {
|
2022-10-02 02:07:40 +00:00
|
|
|
if config == nil {
|
|
|
|
return
|
|
|
|
}
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
|
2022-10-02 02:07:40 +00:00
|
|
|
setOIDCDefaults(config)
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
|
2022-10-20 02:16:36 +00:00
|
|
|
switch {
|
|
|
|
case config.IssuerPrivateKey == nil:
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(errFmtOIDCNoPrivateKey))
|
2022-10-20 02:16:36 +00:00
|
|
|
default:
|
|
|
|
if config.IssuerCertificateChain.HasCertificates() {
|
|
|
|
if !config.IssuerCertificateChain.EqualKey(config.IssuerPrivateKey) {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(errFmtOIDCCertificateMismatch))
|
2022-10-20 02:16:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := config.IssuerCertificateChain.Validate(); err != nil {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(errFmtOIDCCertificateChain, err))
|
2022-10-20 02:16:36 +00:00
|
|
|
}
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|
|
|
|
|
2023-04-08 06:02:34 +00:00
|
|
|
if config.IssuerPrivateKey.PublicKey.N == nil {
|
|
|
|
val.Push(fmt.Errorf(errFmtOIDCInvalidPrivateKeyMalformedMissingPublicKey))
|
|
|
|
} else if config.IssuerPrivateKey.Size()*8 < 2048 {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(errFmtOIDCInvalidPrivateKeyBitSize, 2048, config.IssuerPrivateKey.Size()*8))
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|
2022-10-02 02:07:40 +00:00
|
|
|
}
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
|
2022-10-02 02:07:40 +00:00
|
|
|
if config.MinimumParameterEntropy != 0 && config.MinimumParameterEntropy < 8 {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.PushWarning(fmt.Errorf(errFmtOIDCServerInsecureParameterEntropy, config.MinimumParameterEntropy))
|
2022-10-02 02:07:40 +00:00
|
|
|
}
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
|
2022-10-02 02:07:40 +00:00
|
|
|
if config.EnforcePKCE != "never" && config.EnforcePKCE != "public_clients_only" && config.EnforcePKCE != "always" {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(errFmtOIDCEnforcePKCEInvalidValue, config.EnforcePKCE))
|
2022-10-02 02:07:40 +00:00
|
|
|
}
|
2022-03-02 04:44:05 +00:00
|
|
|
|
2022-11-23 23:16:23 +00:00
|
|
|
validateOIDCOptionsCORS(config, val)
|
2022-03-02 04:44:05 +00:00
|
|
|
|
2022-10-02 02:07:40 +00:00
|
|
|
if len(config.Clients) == 0 {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(errFmtOIDCNoClientsConfigured))
|
2022-10-02 02:07:40 +00:00
|
|
|
} else {
|
2022-11-23 23:16:23 +00:00
|
|
|
validateOIDCClients(config, val)
|
2022-10-02 02:07:40 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-04 22:06:05 +00:00
|
|
|
|
2022-10-02 02:07:40 +00:00
|
|
|
func setOIDCDefaults(config *schema.OpenIDConnectConfiguration) {
|
|
|
|
if config.AccessTokenLifespan == time.Duration(0) {
|
|
|
|
config.AccessTokenLifespan = schema.DefaultOpenIDConnectConfiguration.AccessTokenLifespan
|
|
|
|
}
|
|
|
|
|
|
|
|
if config.AuthorizeCodeLifespan == time.Duration(0) {
|
|
|
|
config.AuthorizeCodeLifespan = schema.DefaultOpenIDConnectConfiguration.AuthorizeCodeLifespan
|
|
|
|
}
|
|
|
|
|
|
|
|
if config.IDTokenLifespan == time.Duration(0) {
|
|
|
|
config.IDTokenLifespan = schema.DefaultOpenIDConnectConfiguration.IDTokenLifespan
|
|
|
|
}
|
|
|
|
|
|
|
|
if config.RefreshTokenLifespan == time.Duration(0) {
|
|
|
|
config.RefreshTokenLifespan = schema.DefaultOpenIDConnectConfiguration.RefreshTokenLifespan
|
|
|
|
}
|
|
|
|
|
|
|
|
if config.EnforcePKCE == "" {
|
|
|
|
config.EnforcePKCE = schema.DefaultOpenIDConnectConfiguration.EnforcePKCE
|
2021-05-04 22:06:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-07 00:58:51 +00:00
|
|
|
func validateOIDCOptionsCORS(config *schema.OpenIDConnectConfiguration, validator *schema.StructValidator) {
|
|
|
|
validateOIDCOptionsCORSAllowedOrigins(config, validator)
|
|
|
|
|
|
|
|
if config.CORS.AllowedOriginsFromClientRedirectURIs {
|
|
|
|
validateOIDCOptionsCORSAllowedOriginsFromClientRedirectURIs(config)
|
|
|
|
}
|
|
|
|
|
|
|
|
validateOIDCOptionsCORSEndpoints(config, validator)
|
|
|
|
}
|
|
|
|
|
2022-11-23 23:16:23 +00:00
|
|
|
func validateOIDCOptionsCORSAllowedOrigins(config *schema.OpenIDConnectConfiguration, val *schema.StructValidator) {
|
2022-04-07 00:58:51 +00:00
|
|
|
for _, origin := range config.CORS.AllowedOrigins {
|
|
|
|
if origin.String() == "*" {
|
|
|
|
if len(config.CORS.AllowedOrigins) != 1 {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(errFmtOIDCCORSInvalidOriginWildcard))
|
2022-04-07 00:58:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if config.CORS.AllowedOriginsFromClientRedirectURIs {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(errFmtOIDCCORSInvalidOriginWildcardWithClients))
|
2022-04-07 00:58:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if origin.Path != "" {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(errFmtOIDCCORSInvalidOrigin, origin.String(), "path"))
|
2022-04-07 00:58:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if origin.RawQuery != "" {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(errFmtOIDCCORSInvalidOrigin, origin.String(), "query string"))
|
2022-04-07 00:58:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func validateOIDCOptionsCORSAllowedOriginsFromClientRedirectURIs(config *schema.OpenIDConnectConfiguration) {
|
|
|
|
for _, client := range config.Clients {
|
|
|
|
for _, redirectURI := range client.RedirectURIs {
|
2022-09-03 01:51:02 +00:00
|
|
|
uri, err := url.ParseRequestURI(redirectURI)
|
2022-04-07 00:58:51 +00:00
|
|
|
if err != nil || (uri.Scheme != schemeHTTP && uri.Scheme != schemeHTTPS) || uri.Hostname() == "localhost" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
origin := utils.OriginFromURL(*uri)
|
|
|
|
|
|
|
|
if !utils.IsURLInSlice(origin, config.CORS.AllowedOrigins) {
|
|
|
|
config.CORS.AllowedOrigins = append(config.CORS.AllowedOrigins, origin)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-23 23:16:23 +00:00
|
|
|
func validateOIDCOptionsCORSEndpoints(config *schema.OpenIDConnectConfiguration, val *schema.StructValidator) {
|
2022-04-07 00:58:51 +00:00
|
|
|
for _, endpoint := range config.CORS.Endpoints {
|
|
|
|
if !utils.IsStringInSlice(endpoint, validOIDCCORSEndpoints) {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(errFmtOIDCCORSInvalidEndpoint, endpoint, strings.Join(validOIDCCORSEndpoints, "', '")))
|
2022-04-07 00:58:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-03 01:51:02 +00:00
|
|
|
|
2022-11-23 23:16:23 +00:00
|
|
|
func validateOIDCClients(config *schema.OpenIDConnectConfiguration, val *schema.StructValidator) {
|
2021-05-04 22:06:05 +00:00
|
|
|
invalidID, duplicateIDs := false, false
|
|
|
|
|
|
|
|
var ids []string
|
|
|
|
|
2022-02-28 03:15:01 +00:00
|
|
|
for c, client := range config.Clients {
|
2021-05-04 22:06:05 +00:00
|
|
|
if client.ID == "" {
|
|
|
|
invalidID = true
|
|
|
|
} else {
|
|
|
|
if client.Description == "" {
|
2022-02-28 03:15:01 +00:00
|
|
|
config.Clients[c].Description = client.ID
|
2021-05-04 22:06:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if utils.IsStringInSliceFold(client.ID, ids) {
|
|
|
|
duplicateIDs = true
|
|
|
|
}
|
|
|
|
ids = append(ids, client.ID)
|
|
|
|
}
|
|
|
|
|
2021-07-15 11:02:03 +00:00
|
|
|
if client.Public {
|
2022-10-20 03:21:45 +00:00
|
|
|
if client.Secret != nil {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(errFmtOIDCClientPublicInvalidSecret, client.ID))
|
2021-07-15 11:02:03 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-10-20 03:21:45 +00:00
|
|
|
if client.Secret == nil {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(errFmtOIDCClientInvalidSecret, client.ID))
|
2023-03-09 07:26:52 +00:00
|
|
|
} else if client.Secret.IsPlainText() {
|
|
|
|
val.PushWarning(fmt.Errorf(errFmtOIDCClientInvalidSecretPlainText, client.ID))
|
2021-07-15 11:02:03 +00:00
|
|
|
}
|
2021-05-04 22:06:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if client.Policy == "" {
|
2022-02-28 03:15:01 +00:00
|
|
|
config.Clients[c].Policy = schema.DefaultOpenIDConnectClientConfiguration.Policy
|
2021-08-03 09:55:21 +00:00
|
|
|
} else if client.Policy != policyOneFactor && client.Policy != policyTwoFactor {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(errFmtOIDCClientInvalidPolicy, client.ID, client.Policy))
|
2021-05-04 22:06:05 +00:00
|
|
|
}
|
|
|
|
|
2023-01-03 15:03:23 +00:00
|
|
|
switch client.PKCEChallengeMethod {
|
|
|
|
case "", "plain", "S256":
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
val.Push(fmt.Errorf(errFmtOIDCClientInvalidPKCEChallengeMethod, client.ID, client.PKCEChallengeMethod))
|
|
|
|
}
|
|
|
|
|
2022-11-23 23:16:23 +00:00
|
|
|
validateOIDCClientConsentMode(c, config, val)
|
|
|
|
validateOIDCClientSectorIdentifier(client, val)
|
|
|
|
validateOIDCClientScopes(c, config, val)
|
|
|
|
validateOIDCClientGrantTypes(c, config, val)
|
|
|
|
validateOIDCClientResponseTypes(c, config, val)
|
|
|
|
validateOIDCClientResponseModes(c, config, val)
|
|
|
|
validateOIDDClientUserinfoAlgorithm(c, config, val)
|
|
|
|
validateOIDCClientRedirectURIs(client, val)
|
2021-05-04 22:06:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if invalidID {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(errFmtOIDCClientsWithEmptyID))
|
2021-05-04 22:06:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if duplicateIDs {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(errFmtOIDCClientsDuplicateID))
|
2021-05-04 22:06:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-23 23:16:23 +00:00
|
|
|
func validateOIDCClientSectorIdentifier(client schema.OpenIDConnectClientConfiguration, val *schema.StructValidator) {
|
2022-04-07 06:13:01 +00:00
|
|
|
if client.SectorIdentifier.String() != "" {
|
2022-04-08 07:38:38 +00:00
|
|
|
if utils.IsURLHostComponent(client.SectorIdentifier) || utils.IsURLHostComponentWithPort(client.SectorIdentifier) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-04-07 06:13:01 +00:00
|
|
|
if client.SectorIdentifier.Scheme != "" {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(errFmtOIDCClientInvalidSectorIdentifier, client.ID, client.SectorIdentifier.String(), client.SectorIdentifier.Host, "scheme", client.SectorIdentifier.Scheme))
|
2022-04-07 06:13:01 +00:00
|
|
|
|
|
|
|
if client.SectorIdentifier.Path != "" {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(errFmtOIDCClientInvalidSectorIdentifier, client.ID, client.SectorIdentifier.String(), client.SectorIdentifier.Host, "path", client.SectorIdentifier.Path))
|
2022-04-07 06:13:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if client.SectorIdentifier.RawQuery != "" {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(errFmtOIDCClientInvalidSectorIdentifier, client.ID, client.SectorIdentifier.String(), client.SectorIdentifier.Host, "query", client.SectorIdentifier.RawQuery))
|
2022-04-07 06:13:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if client.SectorIdentifier.Fragment != "" {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(errFmtOIDCClientInvalidSectorIdentifier, client.ID, client.SectorIdentifier.String(), client.SectorIdentifier.Host, "fragment", client.SectorIdentifier.Fragment))
|
2022-04-07 06:13:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if client.SectorIdentifier.User != nil {
|
|
|
|
if client.SectorIdentifier.User.Username() != "" {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(errFmtOIDCClientInvalidSectorIdentifier, client.ID, client.SectorIdentifier.String(), client.SectorIdentifier.Host, "username", client.SectorIdentifier.User.Username()))
|
2022-04-07 06:13:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if _, set := client.SectorIdentifier.User.Password(); set {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(errFmtOIDCClientInvalidSectorIdentifierWithoutValue, client.ID, client.SectorIdentifier.String(), client.SectorIdentifier.Host, "password"))
|
2022-04-07 06:13:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if client.SectorIdentifier.Host == "" {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(errFmtOIDCClientInvalidSectorIdentifierHost, client.ID, client.SectorIdentifier.String()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func validateOIDCClientConsentMode(c int, config *schema.OpenIDConnectConfiguration, val *schema.StructValidator) {
|
|
|
|
switch {
|
|
|
|
case utils.IsStringInSlice(config.Clients[c].ConsentMode, []string{"", "auto"}):
|
|
|
|
if config.Clients[c].ConsentPreConfiguredDuration != nil {
|
|
|
|
config.Clients[c].ConsentMode = oidc.ClientConsentModePreConfigured.String()
|
|
|
|
} else {
|
|
|
|
config.Clients[c].ConsentMode = oidc.ClientConsentModeExplicit.String()
|
2022-04-07 06:13:01 +00:00
|
|
|
}
|
2022-11-23 23:16:23 +00:00
|
|
|
case utils.IsStringInSlice(config.Clients[c].ConsentMode, validOIDCClientConsentModes):
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
val.Push(fmt.Errorf(errFmtOIDCClientInvalidConsentMode, config.Clients[c].ID, strings.Join(append(validOIDCClientConsentModes, "auto"), "', '"), config.Clients[c].ConsentMode))
|
|
|
|
}
|
|
|
|
|
|
|
|
if config.Clients[c].ConsentMode == oidc.ClientConsentModePreConfigured.String() && config.Clients[c].ConsentPreConfiguredDuration == nil {
|
|
|
|
config.Clients[c].ConsentPreConfiguredDuration = schema.DefaultOpenIDConnectClientConfiguration.ConsentPreConfiguredDuration
|
2022-04-07 06:13:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-23 23:16:23 +00:00
|
|
|
func validateOIDCClientScopes(c int, config *schema.OpenIDConnectConfiguration, val *schema.StructValidator) {
|
|
|
|
if len(config.Clients[c].Scopes) == 0 {
|
|
|
|
config.Clients[c].Scopes = schema.DefaultOpenIDConnectClientConfiguration.Scopes
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-11-23 23:16:23 +00:00
|
|
|
if !utils.IsStringInSlice(oidc.ScopeOpenID, config.Clients[c].Scopes) {
|
|
|
|
config.Clients[c].Scopes = append(config.Clients[c].Scopes, oidc.ScopeOpenID)
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|
|
|
|
|
2022-11-23 23:16:23 +00:00
|
|
|
for _, scope := range config.Clients[c].Scopes {
|
2021-07-10 04:56:33 +00:00
|
|
|
if !utils.IsStringInSlice(scope, validOIDCScopes) {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(
|
2022-02-28 03:15:01 +00:00
|
|
|
errFmtOIDCClientInvalidEntry,
|
2022-11-23 23:16:23 +00:00
|
|
|
config.Clients[c].ID, "scopes", strings.Join(validOIDCScopes, "', '"), scope))
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-23 23:16:23 +00:00
|
|
|
func validateOIDCClientGrantTypes(c int, config *schema.OpenIDConnectConfiguration, val *schema.StructValidator) {
|
|
|
|
if len(config.Clients[c].GrantTypes) == 0 {
|
|
|
|
config.Clients[c].GrantTypes = schema.DefaultOpenIDConnectClientConfiguration.GrantTypes
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-11-23 23:16:23 +00:00
|
|
|
for _, grantType := range config.Clients[c].GrantTypes {
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
if !utils.IsStringInSlice(grantType, validOIDCGrantTypes) {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(
|
2022-02-28 03:15:01 +00:00
|
|
|
errFmtOIDCClientInvalidEntry,
|
2022-11-23 23:16:23 +00:00
|
|
|
config.Clients[c].ID, "grant_types", strings.Join(validOIDCGrantTypes, "', '"), grantType))
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-23 23:16:23 +00:00
|
|
|
func validateOIDCClientResponseTypes(c int, config *schema.OpenIDConnectConfiguration, _ *schema.StructValidator) {
|
|
|
|
if len(config.Clients[c].ResponseTypes) == 0 {
|
|
|
|
config.Clients[c].ResponseTypes = schema.DefaultOpenIDConnectClientConfiguration.ResponseTypes
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-23 23:16:23 +00:00
|
|
|
func validateOIDCClientResponseModes(c int, config *schema.OpenIDConnectConfiguration, validator *schema.StructValidator) {
|
|
|
|
if len(config.Clients[c].ResponseModes) == 0 {
|
|
|
|
config.Clients[c].ResponseModes = schema.DefaultOpenIDConnectClientConfiguration.ResponseModes
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-11-23 23:16:23 +00:00
|
|
|
for _, responseMode := range config.Clients[c].ResponseModes {
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
if !utils.IsStringInSlice(responseMode, validOIDCResponseModes) {
|
|
|
|
validator.Push(fmt.Errorf(
|
2022-02-28 03:15:01 +00:00
|
|
|
errFmtOIDCClientInvalidEntry,
|
2022-11-23 23:16:23 +00:00
|
|
|
config.Clients[c].ID, "response_modes", strings.Join(validOIDCResponseModes, "', '"), responseMode))
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-23 23:16:23 +00:00
|
|
|
func validateOIDDClientUserinfoAlgorithm(c int, config *schema.OpenIDConnectConfiguration, val *schema.StructValidator) {
|
|
|
|
if config.Clients[c].UserinfoSigningAlgorithm == "" {
|
|
|
|
config.Clients[c].UserinfoSigningAlgorithm = schema.DefaultOpenIDConnectClientConfiguration.UserinfoSigningAlgorithm
|
|
|
|
} else if !utils.IsStringInSlice(config.Clients[c].UserinfoSigningAlgorithm, validOIDCUserinfoAlgorithms) {
|
|
|
|
val.Push(fmt.Errorf(errFmtOIDCClientInvalidUserinfoAlgorithm,
|
|
|
|
config.Clients[c].ID, strings.Join(validOIDCUserinfoAlgorithms, ", "), config.Clients[c].UserinfoSigningAlgorithm))
|
2021-07-10 04:56:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-23 23:16:23 +00:00
|
|
|
func validateOIDCClientRedirectURIs(client schema.OpenIDConnectClientConfiguration, val *schema.StructValidator) {
|
2021-05-04 22:06:05 +00:00
|
|
|
for _, redirectURI := range client.RedirectURIs {
|
2021-07-15 11:02:03 +00:00
|
|
|
if redirectURI == oauth2InstalledApp {
|
|
|
|
if client.Public {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(errFmtOIDCClientRedirectURIPublic, client.ID, oauth2InstalledApp))
|
2021-05-04 22:06:05 +00:00
|
|
|
|
2021-07-15 11:02:03 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
parsedURL, err := url.Parse(redirectURI)
|
2021-05-04 22:06:05 +00:00
|
|
|
if err != nil {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(errFmtOIDCClientRedirectURICantBeParsed, client.ID, redirectURI, err))
|
2021-07-15 11:02:03 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-11-21 00:52:27 +00:00
|
|
|
if !parsedURL.IsAbs() || (!client.Public && parsedURL.Scheme == "") {
|
2022-11-23 23:16:23 +00:00
|
|
|
val.Push(fmt.Errorf(errFmtOIDCClientRedirectURIAbsolute, client.ID, redirectURI))
|
2021-07-15 11:02:03 +00:00
|
|
|
return
|
2021-05-04 22:06:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|