-
Notifications
You must be signed in to change notification settings - Fork 2
/
identity_with_one_login.go
40 lines (33 loc) · 1.24 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 certificateproviderpage
import (
"net/http"
"github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext"
"github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider"
"github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/localize"
"github.com/ministryofjustice/opg-modernising-lpa/internal/sesh"
)
func IdentityWithOneLogin(oneLoginClient OneLoginClient, sessionStore SessionStore, randomString func(int) string) Handler {
return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, _ *certificateproviderdata.Provided) 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,
Redirect: certificateprovider.PathIdentityWithOneLoginCallback.Format(appData.LpaID),
}); err != nil {
return err
}
http.Redirect(w, r, authCodeURL, http.StatusFound)
return nil
}
}