Skip to content

Commit

Permalink
Fix accept-language is ignored in authflow #4171
Browse files Browse the repository at this point in the history
ref #4131
  • Loading branch information
tung2744 committed Apr 26, 2024
2 parents 6b1fed1 + 49d4e5c commit c9fa57e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 8 additions & 2 deletions pkg/lib/authenticationflow/service_test.go
Expand Up @@ -31,8 +31,11 @@ func TestService(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

httpReq, _ := http.NewRequest("POST", "", nil)
ctx := context.TODO()
deps := &Dependencies{}
deps := &Dependencies{
HTTPRequest: httpReq,
}
logger := ServiceLogger{log.Null}
database := &db.MockHandle{}
store := NewMockStore(ctrl)
Expand Down Expand Up @@ -360,7 +363,10 @@ func TestServiceContext(t *testing.T) {
defer ctrl.Finish()

ctx := context.TODO()
deps := &Dependencies{}
httpReq, _ := http.NewRequest("POST", "", nil)
deps := &Dependencies{
HTTPRequest: httpReq,
}
logger := ServiceLogger{log.Null}
database := &db.MockHandle{}
uiConfig := &config.UIConfig{AuthenticationFlow: &config.UIAuthenticationFlowConfig{}}
Expand Down
9 changes: 8 additions & 1 deletion pkg/lib/authenticationflow/session.go
Expand Up @@ -122,7 +122,14 @@ func (s *Session) MakeContext(ctx context.Context, deps *Dependencies, publicFlo
XState: s.XState,
})

ctx = intl.WithPreferredLanguageTags(ctx, intl.ParseUILocales(s.UILocales))
if s.UILocales != "" {
tags := intl.ParseUILocales(s.UILocales)
ctx = intl.WithPreferredLanguageTags(ctx, tags)
} else {
acceptLanguage := deps.HTTPRequest.Header.Get("Accept-Language")
tags := intl.ParseAcceptLanguage(acceptLanguage)
ctx = intl.WithPreferredLanguageTags(ctx, tags)
}

ctx = context.WithValue(ctx, contextKeyIDToken, s.IDToken)
ctx = context.WithValue(ctx, contextKeySuppressIDPSessionCookie, s.SuppressIDPSessionCookie)
Expand Down

0 comments on commit c9fa57e

Please sign in to comment.