-
Notifications
You must be signed in to change notification settings - Fork 27
/
use_identity_siwe.go
63 lines (51 loc) · 1.64 KB
/
use_identity_siwe.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
package nodes
import (
"github.com/authgear/authgear-server/pkg/api/model"
"github.com/authgear/authgear-server/pkg/lib/authn/identity"
"github.com/authgear/authgear-server/pkg/lib/interaction"
)
func init() {
interaction.RegisterNode(&NodeUseIdentitySIWE{})
}
type InputUseIdentitySIWE interface {
GetMessage() string
GetSignature() string
}
type EdgeUseIdentitySIWE struct {
IsAuthentication bool
}
func (e *EdgeUseIdentitySIWE) GetIdentityCandidates() []identity.Candidate {
return []identity.Candidate{
identity.NewSIWECandidate(),
}
}
func (e *EdgeUseIdentitySIWE) Instantiate(ctx *interaction.Context, graph *interaction.Graph, rawInput interface{}) (interaction.Node, error) {
var input InputUseIdentitySIWE
if !interaction.Input(rawInput, &input) {
return nil, interaction.ErrIncompatibleInput
}
spec := &identity.Spec{
Type: model.IdentityTypeSIWE,
SIWE: &identity.SIWESpec{
Message: input.GetMessage(),
Signature: input.GetSignature(),
},
}
return &NodeUseIdentitySIWE{
IsAuthentication: e.IsAuthentication,
IdentitySpec: spec,
}, nil
}
type NodeUseIdentitySIWE struct {
IsAuthentication bool `json:"is_authentication"`
IdentitySpec *identity.Spec `json:"identity_spec"`
}
func (n *NodeUseIdentitySIWE) Prepare(ctx *interaction.Context, graph *interaction.Graph) error {
return nil
}
func (n *NodeUseIdentitySIWE) GetEffects() ([]interaction.Effect, error) {
return nil, nil
}
func (n *NodeUseIdentitySIWE) DeriveEdges(graph *interaction.Graph) ([]interaction.Edge, error) {
return []interaction.Edge{&EdgeSelectIdentityEnd{IdentitySpec: n.IdentitySpec, IsAuthentication: n.IsAuthentication}}, nil
}