-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathkba.go
76 lines (62 loc) · 1.86 KB
/
kba.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
package dwolla
import (
"context"
"errors"
"fmt"
)
// KBAService is the kba service interface
//
// see: https://docs.dwolla.com/#knowledge-based-authentication-kba
type KBAService interface {
Retrieve(context.Context, string) (*KBA, error)
}
// KBAServiceOp is an implementation of the kba service interface
type KBAServiceOp struct {
client *Client
}
// KBA is a knowledge based authentication resource
type KBA struct {
Resource
ID string `json:"id"`
Questions []KBAQuestion `json:"questions"`
}
// KBAQuestion is a knowledge based authentication question
type KBAQuestion struct {
ID string `json:"id"`
Text string `json:"text"`
Answers []KBAAnswer `json:"answers"`
}
// KBAAnswer is a knowledge based authentication answer
type KBAAnswer struct {
ID string `json:"id"`
Text string `json:"text"`
}
// KBARequest is a knowledge based authentication verification request
type KBARequest struct {
Answers []KBAQuestionAnswer `json:"answers"`
}
// KBAQuestionAnswer is a knowledge based authentication question and answer
type KBAQuestionAnswer struct {
QuestionID string `json:"questionId"`
AnswerID string `json:"answerId"`
}
// Retrieve retrieves a knowledge based authentication session
//
// see: https://docs.dwolla.com/#retrieve-kba-questions
func (k *KBAServiceOp) Retrieve(ctx context.Context, id string) (*KBA, error) {
var kba KBA
if err := k.client.Get(ctx, fmt.Sprintf("kba/%s", id), nil, nil, &kba); err != nil {
return nil, err
}
kba.client = k.client
return &kba, nil
}
// Verify attempts a knowledge based authentication verification
//
// see: https://docs.dwolla.com/#verify-kba-questions
func (k *KBA) Verify(ctx context.Context, body *KBARequest) error {
if _, ok := k.Links["self"]; !ok {
return errors.New("No self resource link")
}
return k.client.Post(ctx, k.Links["self"].Href, body, nil, nil)
}