fix: supported ui locales from config (#107)

This commit is contained in:
Livio Amstutz 2021-07-09 09:20:03 +02:00 committed by GitHub
parent 1392c0ee9a
commit 8a35b89815
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 10 deletions

View file

@ -5,6 +5,8 @@ import (
"net/url" "net/url"
"os" "os"
"strings" "strings"
"golang.org/x/text/language"
) )
const OidcDevMode = "CAOS_OIDC_DEV" const OidcDevMode = "CAOS_OIDC_DEV"
@ -24,6 +26,8 @@ type Configuration interface {
GrantTypeRefreshTokenSupported() bool GrantTypeRefreshTokenSupported() bool
GrantTypeTokenExchangeSupported() bool GrantTypeTokenExchangeSupported() bool
GrantTypeJWTAuthorizationSupported() bool GrantTypeJWTAuthorizationSupported() bool
SupportedUILocales() []language.Tag
} }
func ValidateIssuer(issuer string) error { func ValidateIssuer(issuer string) error {

View file

@ -3,8 +3,6 @@ package op
import ( import (
"net/http" "net/http"
"golang.org/x/text/language"
"github.com/caos/oidc/pkg/oidc" "github.com/caos/oidc/pkg/oidc"
"github.com/caos/oidc/pkg/utils" "github.com/caos/oidc/pkg/utils"
) )
@ -37,7 +35,7 @@ func CreateDiscoveryConfig(c Configuration, s Signer) *oidc.DiscoveryConfigurati
IntrospectionEndpointAuthMethodsSupported: AuthMethodsIntrospectionEndpoint(c), IntrospectionEndpointAuthMethodsSupported: AuthMethodsIntrospectionEndpoint(c),
ClaimsSupported: SupportedClaims(c), ClaimsSupported: SupportedClaims(c),
CodeChallengeMethodsSupported: CodeChallengeMethods(c), CodeChallengeMethodsSupported: CodeChallengeMethods(c),
UILocalesSupported: UILocales(c), UILocalesSupported: c.SupportedUILocales(),
} }
} }
@ -146,10 +144,3 @@ func CodeChallengeMethods(c Configuration) []oidc.CodeChallengeMethod {
} }
return codeMethods return codeMethods
} }
func UILocales(c Configuration) []language.Tag {
return []language.Tag{
language.English,
language.German,
}
}

View file

@ -9,6 +9,7 @@ import (
op "github.com/caos/oidc/pkg/op" op "github.com/caos/oidc/pkg/op"
gomock "github.com/golang/mock/gomock" gomock "github.com/golang/mock/gomock"
language "golang.org/x/text/language"
) )
// MockConfiguration is a mock of Configuration interface. // 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)) 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. // TokenEndpoint mocks base method.
func (m *MockConfiguration) TokenEndpoint() op.Endpoint { func (m *MockConfiguration) TokenEndpoint() op.Endpoint {
m.ctrl.T.Helper() m.ctrl.T.Helper()

View file

@ -9,6 +9,7 @@ import (
"github.com/gorilla/handlers" "github.com/gorilla/handlers"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/gorilla/schema" "github.com/gorilla/schema"
"golang.org/x/text/language"
"gopkg.in/square/go-jose.v2" "gopkg.in/square/go-jose.v2"
"github.com/caos/oidc/pkg/oidc" "github.com/caos/oidc/pkg/oidc"
@ -85,6 +86,7 @@ type Config struct {
CodeMethodS256 bool CodeMethodS256 bool
AuthMethodPrivateKeyJWT bool AuthMethodPrivateKeyJWT bool
GrantTypeRefreshToken bool GrantTypeRefreshToken bool
SupportedUILocales []language.Tag
} }
type endpoints struct { type endpoints struct {
@ -202,6 +204,10 @@ func (o *openidProvider) GrantTypeJWTAuthorizationSupported() bool {
return true return true
} }
func (o *openidProvider) SupportedUILocales() []language.Tag {
return o.config.SupportedUILocales
}
func (o *openidProvider) Storage() Storage { func (o *openidProvider) Storage() Storage {
return o.storage return o.storage
} }