-
Notifications
You must be signed in to change notification settings - Fork 27
/
remove_authenticator.go
68 lines (55 loc) · 1.92 KB
/
remove_authenticator.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package nodes
import (
"github.com/authgear/authgear-server/pkg/api"
"github.com/authgear/authgear-server/pkg/api/model"
"github.com/authgear/authgear-server/pkg/lib/authn/authenticator"
"github.com/authgear/authgear-server/pkg/lib/interaction"
)
func init() {
interaction.RegisterNode(&NodeRemoveAuthenticator{})
}
type InputRemoveAuthenticator interface {
GetAuthenticatorType() model.AuthenticatorType
GetAuthenticatorID() string
}
type EdgeRemoveAuthenticator struct{}
func (e *EdgeRemoveAuthenticator) Instantiate(ctx *interaction.Context, graph *interaction.Graph, rawInput interface{}) (interaction.Node, error) {
var input InputRemoveAuthenticator
if !interaction.Input(rawInput, &input) {
return nil, interaction.ErrIncompatibleInput
}
authenticatorID := input.GetAuthenticatorID()
bypassMFARequirement := false
var bypassInput interface{ BypassMFARequirement() bool }
if interaction.Input(rawInput, &bypassInput) {
bypassMFARequirement = bypassInput.BypassMFARequirement()
}
info, err := ctx.Authenticators.Get(authenticatorID)
if err != nil {
return nil, err
}
if info.UserID != graph.MustGetUserID() {
return nil, api.NewInvariantViolated(
"AuthenticatorNotBelongToUser",
"authenticator does not belong to the user",
nil,
)
}
return &NodeRemoveAuthenticator{
AuthenticatorInfo: info,
BypassMFARequirement: bypassMFARequirement,
}, nil
}
type NodeRemoveAuthenticator struct {
AuthenticatorInfo *authenticator.Info `json:"authenticator_info"`
BypassMFARequirement bool `json:"bypass_mfa_requirement"`
}
func (n *NodeRemoveAuthenticator) Prepare(ctx *interaction.Context, graph *interaction.Graph) error {
return nil
}
func (n *NodeRemoveAuthenticator) GetEffects() ([]interaction.Effect, error) {
return nil, nil
}
func (n *NodeRemoveAuthenticator) DeriveEdges(graph *interaction.Graph) ([]interaction.Edge, error) {
return graph.Intent.DeriveEdgesForNode(graph, n)
}