-
Notifications
You must be signed in to change notification settings - Fork 3
/
action_validating_identifier.go
41 lines (33 loc) · 1.12 KB
/
action_validating_identifier.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 login
import (
"context"
"github.com/looplab/fsm"
"github.com/nrc-no/core/pkg/logging"
"github.com/nrc-no/core/pkg/server/login/authrequest"
"go.uber.org/zap"
"net/http"
)
func handleValidatingIdentifier(ctx context.Context, req *http.Request, dispatch func(evt string)) func(authRequest *authrequest.AuthRequest, evt *fsm.Event) error {
return func(authRequest *authrequest.AuthRequest, evt *fsm.Event) error {
l := logging.NewLogger(ctx).With(zap.String("event", authrequest.EventUseIdentityProvider))
l.Debug("parsing form data")
if err := req.ParseForm(); err != nil {
l.Error("failed to parse form data", zap.Error(err))
dispatch(authrequest.EventProvideInvalidIdentifier)
return nil
}
q := req.Form
l.Debug("getting email domain")
email := q.Get("email")
emailDomain, err := getEmailDomain(email)
if err != nil {
l.Error("failed to get email domain", zap.Error(err))
dispatch(authrequest.EventProvideInvalidIdentifier)
return nil
}
authRequest.Identifier = email
authRequest.EmailDomain = emailDomain
dispatch(authrequest.EventProvideValidIdentifier)
return nil
}
}