feat(api): return allowed_languages (#11553)

# Which Problems Are Solved

While Zitadel provides a possibility to restrict certain languages to be
used, the corresponding list could not be retrieved in the settings
service (v2). This blocked login v2 implementations from respecting the
list and they would always use all available languages.

# How the Problems Are Solved

- Retrieve the list when checking the instance and pass it into the
context.
- Return it as part of the existing `GetGeneralSettingsResponse`
- This allows us to remove an additional query in some other cases /
endpoints.

# Additional Changes

none

# Additional Context

- required for https://github.com/zitadel/zitadel/pull/11372
- backport to v4.x

---------

Co-authored-by: Copilot <[email protected]>
Co-authored-by: Marco A. <[email protected]>
This commit is contained in:
Livio Spring
2026-02-12 08:44:34 +00:00
committed by GitHub
co-authored by Copilot Marco A.
parent ceffb9c536
commit b0609aa861
14 changed files with 65 additions and 20 deletions
+10 -1
View File
@@ -11,7 +11,10 @@ import (
"github.com/zitadel/zitadel/internal/feature"
)
var emptyInstance = &instance{}
var (
emptyInstance = &instance{}
_ Instance = (*instance)(nil)
)
type Instance interface {
InstanceID() string
@@ -19,6 +22,7 @@ type Instance interface {
ManagementConsoleClientID() string
ManagementConsoleApplicationID() string
DefaultLanguage() language.Tag
AllowedLanguages() []language.Tag
DefaultOrganisationID() string
SecurityPolicyAllowedOrigins() []string
EnableImpersonation() bool
@@ -43,6 +47,7 @@ type instance struct {
clientID string
orgID string
defaultLanguage language.Tag
allowedLanguages []language.Tag
features feature.Features
executionTargets target.Router
}
@@ -75,6 +80,10 @@ func (i *instance) DefaultLanguage() language.Tag {
return i.defaultLanguage
}
func (i *instance) AllowedLanguages() []language.Tag {
return i.allowedLanguages
}
func (i *instance) DefaultOrganisationID() string {
return i.orgID
}
+4
View File
@@ -115,6 +115,10 @@ func (m *mockInstance) DefaultLanguage() language.Tag {
return language.English
}
func (m *mockInstance) AllowedLanguages() []language.Tag {
return []language.Tag{language.English}
}
func (m *mockInstance) DefaultOrganisationID() string {
return "orgID"
}
@@ -1112,7 +1112,9 @@ func TestServer_ListPublicKeys(t *testing.T) {
func assertPublicKeys(ttt *assert.CollectT, want *action.ListPublicKeysResponse, got *action.ListPublicKeysResponse) {
assert.EqualExportedValues(ttt, want.Pagination, got.Pagination)
assert.Len(ttt, got.PublicKeys, len(want.PublicKeys))
if !assert.Len(ttt, got.PublicKeys, len(want.PublicKeys)) {
return
}
for i := range want.PublicKeys {
assert.Equal(ttt, want.PublicKeys[i].GetKeyId(), got.PublicKeys[i].GetKeyId())
assert.Equal(ttt, want.PublicKeys[i].GetActive(), got.PublicKeys[i].GetActive())
+1 -5
View File
@@ -33,11 +33,7 @@ func (s *Server) GetDefaultLanguage(ctx context.Context, _ *admin_pb.GetDefaultL
}
func (s *Server) GetAllowedLanguages(ctx context.Context, _ *admin_pb.GetAllowedLanguagesRequest) (*admin_pb.GetAllowedLanguagesResponse, error) {
restrictions, err := s.query.GetInstanceRestrictions(ctx)
if err != nil {
return nil, err
}
allowed := restrictions.AllowedLanguages
allowed := authz.GetInstance(ctx).AllowedLanguages()
if len(allowed) == 0 {
allowed = i18n.SupportedLanguages()
}
@@ -281,6 +281,10 @@ func (m *mockInstance) DefaultLanguage() language.Tag {
return language.English
}
func (m *mockInstance) AllowedLanguages() []language.Tag {
return []language.Tag{language.English}
}
func (m *mockInstance) DefaultOrganisationID() string {
return "orgID"
}
+5
View File
@@ -186,10 +186,15 @@ func activeIdentityProvidersToQuery(req *settings.GetActiveIdentityProvidersRequ
func (s *Server) GetGeneralSettings(ctx context.Context, _ *connect.Request[settings.GetGeneralSettingsRequest]) (*connect.Response[settings.GetGeneralSettingsResponse], error) {
instance := authz.GetInstance(ctx)
allowedLanguages := instance.AllowedLanguages()
if len(allowedLanguages) == 0 {
allowedLanguages = i18n.SupportedLanguages()
}
return connect.NewResponse(&settings.GetGeneralSettingsResponse{
SupportedLanguages: domain.LanguagesToStrings(i18n.SupportedLanguages()),
DefaultOrgId: instance.DefaultOrganisationID(),
DefaultLanguage: instance.DefaultLanguage().String(),
AllowedLanguages: domain.LanguagesToStrings(allowedLanguages),
}), nil
}
@@ -338,6 +338,10 @@ func (m *mockInstance) DefaultLanguage() language.Tag {
return language.English
}
func (m *mockInstance) AllowedLanguages() []language.Tag {
return []language.Tag{language.English}
}
func (m *mockInstance) DefaultOrganisationID() string {
return "orgID"
}
+1 -5
View File
@@ -120,11 +120,7 @@ func (s *Server) Discovery(ctx context.Context, r *op.Request[struct{}]) (_ *op.
err = oidcError(ctx, err)
span.EndWithError(err)
}()
restrictions, err := s.query.GetInstanceRestrictions(ctx)
if err != nil {
return nil, op.NewStatusError(oidc.ErrServerError().WithParent(err).WithReturnParentToClient(authz.GetFeatures(ctx).DebugOIDCParentError).WithDescription("internal server error"), http.StatusInternalServerError)
}
allowedLanguages := restrictions.AllowedLanguages
allowedLanguages := authz.GetInstance(ctx).AllowedLanguages()
if len(allowedLanguages) == 0 {
allowedLanguages = i18n.SupportedLanguages()
}
+1 -5
View File
@@ -433,11 +433,7 @@ func (l *Login) getBaseData(r *http.Request, authReq *domain.AuthRequest, transl
}
func (l *Login) getTranslator(ctx context.Context, authReq *domain.AuthRequest) *i18n.Translator {
restrictions, err := l.query.GetInstanceRestrictions(ctx)
if err != nil {
logging.OnError(err).Warn("cannot load instance restrictions to retrieve allowed languages for creating the translator")
}
translator := l.renderer.NewTranslator(ctx, restrictions.AllowedLanguages)
translator := l.renderer.NewTranslator(ctx, authz.GetInstance(ctx).AllowedLanguages())
if authReq != nil {
l.addLoginTranslations(translator, authReq.DefaultTranslations)
l.addLoginTranslations(translator, authReq.OrgTranslations)