forked from tab/smartid
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.go
More file actions
121 lines (99 loc) · 2.8 KB
/
client.go
File metadata and controls
121 lines (99 loc) · 2.8 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
114
115
116
117
118
119
120
121
package smartid
import (
"context"
"crypto/tls"
"time"
"github.com/proDeveloperGuru/smartid/internal/config"
"github.com/proDeveloperGuru/smartid/internal/errors"
"github.com/proDeveloperGuru/smartid/internal/requests"
"github.com/proDeveloperGuru/smartid/internal/utils"
)
const (
CertificateLevel = requests.CertificateLevelQUALIFIED
InteractionType = requests.InteractionTypeDisplayTextAndPIN
DisplayText60 = "Enter PIN1"
DisplayText200 = "Confirm the authentication request and enter PIN1"
Timeout = requests.Timeout
URL = "https://sid.demo.sk.ee/smart-id-rp/v2"
)
type Client interface {
CreateSession(ctx context.Context, nationalIdentityNumber string) (*Session, error)
FetchSession(ctx context.Context, sessionId string) (*Person, error)
WithRelyingPartyName(name string) Client
WithRelyingPartyUUID(id string) Client
WithCertificateLevel(level string) Client
WithHashType(hashType string) Client
WithInteractionType(interactionType string) Client
WithDisplayText60(text string) Client
WithDisplayText200(text 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{
CertificateLevel: CertificateLevel,
HashType: utils.HashTypeSHA512,
InteractionType: InteractionType,
DisplayText60: DisplayText60,
DisplayText200: DisplayText200,
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) WithCertificateLevel(level string) Client {
c.config.CertificateLevel = level
return c
}
func (c *client) WithHashType(hashType string) Client {
c.config.HashType = hashType
return c
}
func (c *client) WithInteractionType(interactionType string) Client {
c.config.InteractionType = interactionType
return c
}
func (c *client) WithDisplayText60(text string) Client {
c.config.DisplayText60 = text
return c
}
func (c *client) WithDisplayText200(text string) Client {
c.config.DisplayText200 = text
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
}