-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthenticator-configurations.go
More file actions
153 lines (122 loc) · 3.66 KB
/
Copy pathauthenticator-configurations.go
File metadata and controls
153 lines (122 loc) · 3.66 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package authsignal
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
const (
smsAuthenticatorConfigurationSlug = "sms"
emailOtpAuthenticatorConfigurationSlug = "email-otp"
passkeyAuthenticatorConfigurationSlug = "passkey"
pushAuthenticatorConfigurationSlug = "push"
)
const (
SmsOtpProviderBird = "BIRD"
SmsOtpProviderTwilio = "TWILIO"
SmsOtpProviderMessageMedia = "MESSAGE_MEDIA"
SmsOtpProviderModicaGroup = "MODICA_GROUP"
SmsOtpProviderTnz = "TNZ"
)
const (
EmailOtpProviderBird = "BIRD"
EmailOtpProviderMailjet = "MAILJET"
EmailOtpProviderMailgun = "MAILGUN"
EmailOtpProviderMandrill = "MANDRILL"
EmailOtpProviderSendgrid = "SENDGRID"
EmailOtpProviderSmtp = "SMTP"
)
const (
PushConfigurationProviderDefault = "DEFAULT"
PushConfigurationProviderFirebase = "FIREBASE"
PushConfigurationProviderWebhook = "WEBHOOK"
)
const (
AppAttestationFailureModeBlock = "BLOCK"
AppAttestationFailureModeAllowWithWarning = "ALLOW_WITH_WARNING"
)
const (
UserVerificationRequirementPreferred = "preferred"
UserVerificationRequirementRequired = "required"
)
const (
AuthenticatorAttachmentCrossPlatform = "cross-platform"
AuthenticatorAttachmentPlatform = "platform"
AuthenticatorAttachmentAllSupported = "all-supported"
)
const (
PasskeyRegistrationHintSecurityKey = "security-key"
PasskeyRegistrationHintClientDevice = "client-device"
PasskeyRegistrationHintHybrid = "hybrid"
)
type RateLimitConfiguration struct {
RateLimit int64 `json:"rateLimit"`
WindowInMinutes float64 `json:"windowInMinutes"`
}
type BlockSize struct {
Country bool
Numeric int64
}
func (b BlockSize) MarshalJSON() ([]byte, error) {
if b.Country {
return json.Marshal("country")
}
if b.Numeric <= 0 {
return nil, fmt.Errorf("block size must be the string country or a positive number, got %d", b.Numeric)
}
return json.Marshal(b.Numeric)
}
func (b *BlockSize) UnmarshalJSON(data []byte) error {
var asString string
if err := json.Unmarshal(data, &asString); err == nil {
if asString != "country" {
return fmt.Errorf("block size must be the string country or a positive number, got %s", data)
}
*b = BlockSize{Country: true}
return nil
}
var asNumber int64
if err := json.Unmarshal(data, &asNumber); err != nil {
return fmt.Errorf("block size must be the string country or a positive number, got %s", data)
}
if asNumber <= 0 {
return fmt.Errorf("block size must be the string country or a positive number, got %s", data)
}
*b = BlockSize{Numeric: asNumber}
return nil
}
type PrefixRateLimitConfiguration struct {
Enabled *bool `json:"enabled,omitempty"`
BlockSize *BlockSize `json:"blockSize,omitempty"`
RateLimit *int64 `json:"rateLimit,omitempty"`
WindowInMinutes *float64 `json:"windowInMinutes,omitempty"`
CountryCodes *[]string `json:"countryCodes,omitempty"`
}
func requestAuthenticatorConfiguration[T any](c Client, method string, slug string, requestBody any) (*T, int, error) {
var reader io.Reader
if requestBody != nil {
encodedBody, err := json.Marshal(requestBody)
if err != nil {
return nil, 0, err
}
reader = bytes.NewReader(encodedBody)
}
request, err := http.NewRequest(method, fmt.Sprintf("%s/authenticator-configurations/%s", c.Host, slug), reader)
if err != nil {
return nil, 0, err
}
if requestBody != nil {
request.Header.Set("Content-Type", "application/json")
}
body, statusCode, err := c.makeRequest(request, c.ApiSecret)
if err != nil {
return nil, statusCode, err
}
var decoded T
err = json.Unmarshal(body, &decoded)
if err != nil {
return nil, statusCode, err
}
return &decoded, statusCode, nil
}