-
Notifications
You must be signed in to change notification settings - Fork 2
/
identity_with_one_login.go
40 lines (33 loc) · 1.1 KB
/
identity_with_one_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
package donor
import (
"net/http"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/localize"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/sesh"
)
func IdentityWithOneLogin(oneLoginClient OneLoginClient, sessionStore SessionStore, randomString func(int) string) Handler {
return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *actor.DonorProvidedDetails) error {
locale := ""
if appData.Lang == localize.Cy {
locale = "cy"
}
state := randomString(12)
nonce := randomString(12)
authCodeURL, err := oneLoginClient.AuthCodeURL(state, nonce, locale, true)
if err != nil {
return err
}
if err := sessionStore.SetOneLogin(r, w, &sesh.OneLoginSession{
State: state,
Nonce: nonce,
Locale: locale,
LpaID: donor.LpaID,
Redirect: page.Paths.IdentityWithOneLoginCallback.Format(donor.LpaID),
}); err != nil {
return err
}
http.Redirect(w, r, authCodeURL, http.StatusFound)
return nil
}
}