From 8a35b89815484e96e16338cae4e080e30fb81361 Mon Sep 17 00:00:00 2001 From: Livio Amstutz Date: Fri, 9 Jul 2021 09:20:03 +0200 Subject: [PATCH] fix: supported ui locales from config (#107) --- pkg/op/config.go | 4 ++++ pkg/op/discovery.go | 11 +---------- pkg/op/mock/configuration.mock.go | 15 +++++++++++++++ pkg/op/op.go | 6 ++++++ 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/pkg/op/config.go b/pkg/op/config.go index 0e5216b..704cc20 100644 --- a/pkg/op/config.go +++ b/pkg/op/config.go @@ -5,6 +5,8 @@ import ( "net/url" "os" "strings" + + "golang.org/x/text/language" ) const OidcDevMode = "CAOS_OIDC_DEV" @@ -24,6 +26,8 @@ type Configuration interface { GrantTypeRefreshTokenSupported() bool GrantTypeTokenExchangeSupported() bool GrantTypeJWTAuthorizationSupported() bool + + SupportedUILocales() []language.Tag } func ValidateIssuer(issuer string) error { diff --git a/pkg/op/discovery.go b/pkg/op/discovery.go index d057042..807aa20 100644 --- a/pkg/op/discovery.go +++ b/pkg/op/discovery.go @@ -3,8 +3,6 @@ package op import ( "net/http" - "golang.org/x/text/language" - "github.com/caos/oidc/pkg/oidc" "github.com/caos/oidc/pkg/utils" ) @@ -37,7 +35,7 @@ func CreateDiscoveryConfig(c Configuration, s Signer) *oidc.DiscoveryConfigurati IntrospectionEndpointAuthMethodsSupported: AuthMethodsIntrospectionEndpoint(c), ClaimsSupported: SupportedClaims(c), CodeChallengeMethodsSupported: CodeChallengeMethods(c), - UILocalesSupported: UILocales(c), + UILocalesSupported: c.SupportedUILocales(), } } @@ -146,10 +144,3 @@ func CodeChallengeMethods(c Configuration) []oidc.CodeChallengeMethod { } return codeMethods } - -func UILocales(c Configuration) []language.Tag { - return []language.Tag{ - language.English, - language.German, - } -} diff --git a/pkg/op/mock/configuration.mock.go b/pkg/op/mock/configuration.mock.go index da21751..01c2c8d 100644 --- a/pkg/op/mock/configuration.mock.go +++ b/pkg/op/mock/configuration.mock.go @@ -9,6 +9,7 @@ import ( op "github.com/caos/oidc/pkg/op" gomock "github.com/golang/mock/gomock" + language "golang.org/x/text/language" ) // MockConfiguration is a mock of Configuration interface. @@ -188,6 +189,20 @@ func (mr *MockConfigurationMockRecorder) KeysEndpoint() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "KeysEndpoint", reflect.TypeOf((*MockConfiguration)(nil).KeysEndpoint)) } +// SupportedUILocales mocks base method. +func (m *MockConfiguration) SupportedUILocales() []language.Tag { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SupportedUILocales") + ret0, _ := ret[0].([]language.Tag) + return ret0 +} + +// SupportedUILocales indicates an expected call of SupportedUILocales. +func (mr *MockConfigurationMockRecorder) SupportedUILocales() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SupportedUILocales", reflect.TypeOf((*MockConfiguration)(nil).SupportedUILocales)) +} + // TokenEndpoint mocks base method. func (m *MockConfiguration) TokenEndpoint() op.Endpoint { m.ctrl.T.Helper() diff --git a/pkg/op/op.go b/pkg/op/op.go index 241f0ce..772b5f7 100644 --- a/pkg/op/op.go +++ b/pkg/op/op.go @@ -9,6 +9,7 @@ import ( "github.com/gorilla/handlers" "github.com/gorilla/mux" "github.com/gorilla/schema" + "golang.org/x/text/language" "gopkg.in/square/go-jose.v2" "github.com/caos/oidc/pkg/oidc" @@ -85,6 +86,7 @@ type Config struct { CodeMethodS256 bool AuthMethodPrivateKeyJWT bool GrantTypeRefreshToken bool + SupportedUILocales []language.Tag } type endpoints struct { @@ -202,6 +204,10 @@ func (o *openidProvider) GrantTypeJWTAuthorizationSupported() bool { return true } +func (o *openidProvider) SupportedUILocales() []language.Tag { + return o.config.SupportedUILocales +} + func (o *openidProvider) Storage() Storage { return o.storage }