-
Notifications
You must be signed in to change notification settings - Fork 28
/
ui_param.go
45 lines (34 loc) · 952 Bytes
/
ui_param.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package transport
import (
"net/http"
"github.com/authgear/authgear-server/pkg/lib/uiparam"
"github.com/authgear/authgear-server/pkg/util/intl"
)
type UIParamMiddleware struct{}
func (m *UIParamMiddleware) Handle(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var uiParam uiparam.T
q := r.URL.Query()
// client_id
clientID := q.Get("client_id")
uiParam.ClientID = clientID
// ui_locales
uiLocales := q.Get("ui_locales")
uiParam.UILocales = uiLocales
// state
state := q.Get("state")
uiParam.State = state
// x_state
xState := q.Get("x_state")
uiParam.XState = xState
// Put uiParam into context
ctx := r.Context()
ctx = uiparam.WithUIParam(ctx, &uiParam)
if uiParam.UILocales != "" {
tags := intl.ParseUILocales(uiParam.UILocales)
ctx = intl.WithPreferredLanguageTags(ctx, tags)
}
r = r.WithContext(ctx)
next.ServeHTTP(w, r)
})
}