-
Notifications
You must be signed in to change notification settings - Fork 28
/
hook_response.go
97 lines (92 loc) · 2 KB
/
hook_response.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package accountmigration
import (
"io"
"github.com/authgear/authgear-server/pkg/lib/authn/authenticator"
"github.com/authgear/authgear-server/pkg/lib/authn/identity"
"github.com/authgear/authgear-server/pkg/util/validation"
)
var HookResponseSchema = validation.NewSimpleSchema(`
{
"type": "object",
"additionalProperties": false,
"properties": {
"identities": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"type" : {
"type": "string",
"enum" : ["login_id"]
},
"login_id": {
"type": "object",
"properties": {
"key": { "type": "string" },
"type": { "type": "string" },
"value": { "type": "string" }
},
"required": ["key", "type", "value"]
}
},
"required": ["type", "login_id"]
}
},
"authenticators": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"type" : {
"type": "string",
"enum" : ["oob_otp_email", "oob_otp_sms"]
},
"oobotp": {
"email": { "type": "string" },
"phone": { "type": "string" }
}
},
"allOf": [
{
"if": { "properties": { "type": { "const": "oob_otp_email" } } },
"then": {
"properties": {
"oobotp": {
"required": ["email"]
}
},
"required": ["oobotp"]
}
},
{
"if": { "properties": { "type": { "const": "oob_otp_sms" } } },
"then": {
"properties": {
"oobotp": {
"required": ["phone"]
}
},
"required": ["oobotp"]
}
}
]
}
}
},
"required": ["identities"]
}
`)
type HookResponse struct {
Identities []*identity.MigrateSpec
Authenticators []*authenticator.MigrateSpec
}
func ParseHookResponse(r io.Reader) (*HookResponse, error) {
var resp HookResponse
if err := HookResponseSchema.Validator().Parse(r, &resp); err != nil {
return nil, err
}
return &resp, nil
}