-
Notifications
You must be signed in to change notification settings - Fork 2
/
login.go
41 lines (33 loc) · 1000 Bytes
/
login.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
package page
import (
"net/http"
"github.com/ministryofjustice/opg-modernising-lpa/internal/localize"
"github.com/ministryofjustice/opg-modernising-lpa/internal/sesh"
)
type LoginOneLoginClient interface {
AuthCodeURL(state, nonce, locale string, identity bool) (string, error)
}
func Login(oneLoginClient LoginOneLoginClient, store sesh.Store, randomString func(int) string, redirect Path) Handler {
return func(appData AppData, w http.ResponseWriter, r *http.Request) error {
locale := "en"
if appData.Lang == localize.Cy {
locale = "cy"
}
state := randomString(12)
nonce := randomString(12)
authCodeURL, err := oneLoginClient.AuthCodeURL(state, nonce, locale, false)
if err != nil {
return err
}
if err := sesh.SetOneLogin(store, r, w, &sesh.OneLoginSession{
State: state,
Nonce: nonce,
Locale: locale,
Redirect: redirect.Format(),
}); err != nil {
return err
}
http.Redirect(w, r, authCodeURL, http.StatusFound)
return nil
}
}