-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.go
More file actions
113 lines (92 loc) · 2.28 KB
/
client.go
File metadata and controls
113 lines (92 loc) · 2.28 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package mobileid
import (
"context"
"crypto/tls"
"time"
"github.com/tab/mobileid/internal/config"
"github.com/tab/mobileid/internal/errors"
"github.com/tab/mobileid/internal/requests"
"github.com/tab/mobileid/internal/utils"
)
const (
Text = "Enter PIN1"
TextFormat = "GSM-7"
Language = "ENG"
Timeout = requests.Timeout
URL = "https://tsp.demo.sk.ee/mid-api"
)
type Client interface {
CreateSession(ctx context.Context, phoneNumber, nationalIdentityNumber string) (*Session, error)
FetchSession(ctx context.Context, sessionId string) (*Person, error)
WithRelyingPartyName(name string) Client
WithRelyingPartyUUID(id string) Client
WithHashType(hashType string) Client
WithText(text string) Client
WithTextFormat(format string) Client
WithLanguage(language string) Client
WithURL(url string) Client
WithTimeout(timeout time.Duration) Client
WithTLSConfig(tlsConfig *tls.Config) Client
Validate() error
}
type client struct {
config *config.Config
}
func NewClient() Client {
cfg := &config.Config{
HashType: utils.HashTypeSHA512,
Text: Text,
TextFormat: TextFormat,
Language: Language,
URL: URL,
Timeout: Timeout,
}
return &client{
config: cfg,
}
}
func (c *client) WithRelyingPartyName(name string) Client {
c.config.RelyingPartyName = name
return c
}
func (c *client) WithRelyingPartyUUID(id string) Client {
c.config.RelyingPartyUUID = id
return c
}
func (c *client) WithHashType(hashType string) Client {
c.config.HashType = hashType
return c
}
func (c *client) WithText(text string) Client {
c.config.Text = text
return c
}
func (c *client) WithTextFormat(format string) Client {
c.config.TextFormat = format
return c
}
func (c *client) WithLanguage(language string) Client {
c.config.Language = language
return c
}
func (c *client) WithURL(url string) Client {
c.config.URL = url
return c
}
func (c *client) WithTimeout(timeout time.Duration) Client {
c.config.Timeout = timeout
return c
}
func (c *client) WithTLSConfig(tlsConfig *tls.Config) Client {
c.config.TLSConfig = tlsConfig
return c
}
func (c *client) Validate() error {
if c.config.RelyingPartyName == "" {
return errors.ErrMissingRelyingPartyName
}
if c.config.RelyingPartyUUID == "" {
return errors.ErrMissingRelyingPartyUUID
}
return nil
}