-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathmulti_factor_auth.go
More file actions
125 lines (110 loc) · 5.8 KB
/
multi_factor_auth.go
File metadata and controls
125 lines (110 loc) · 5.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
122
123
124
125
// Code generated by oagen. DO NOT EDIT.
package workos
import (
"context"
"fmt"
"net/url"
)
// MultiFactorAuthService handles MultiFactorAuth operations.
type MultiFactorAuthService struct {
client *Client
}
// MultiFactorAuthVerifyChallengeParams contains the parameters for VerifyChallenge.
type MultiFactorAuthVerifyChallengeParams struct {
// Code is the one-time code to verify.
Code string `json:"code"`
}
// VerifyChallenge
// Verifies an Authentication Challenge.
func (s *MultiFactorAuthService) VerifyChallenge(ctx context.Context, id string, params *MultiFactorAuthVerifyChallengeParams, opts ...RequestOption) (*AuthenticationChallengeVerifyResponse, error) {
var result AuthenticationChallengeVerifyResponse
_, err := s.client.request(ctx, "POST", fmt.Sprintf("/auth/challenges/%s/verify", url.PathEscape(id)), nil, params, &result, opts)
if err != nil {
return nil, err
}
return &result, nil
}
// MultiFactorAuthEnrollFactorParams contains the parameters for EnrollFactor.
type MultiFactorAuthEnrollFactorParams struct {
// Type is the type of factor to enroll.
Type AuthenticationFactorsCreateRequestType `json:"type"`
// PhoneNumber is required when type is 'sms'.
PhoneNumber *string `json:"phone_number,omitempty"`
// TOTPIssuer is required when type is 'totp'.
TOTPIssuer *string `json:"totp_issuer,omitempty"`
// TOTPUser is required when type is 'totp'.
TOTPUser *string `json:"totp_user,omitempty"`
// UserID is the ID of the user to associate the factor with.
UserID *string `json:"user_id,omitempty"`
}
// EnrollFactor
// Enrolls an Authentication Factor to be used as an additional factor of authentication. The returned ID should be used to create an authentication Challenge.
func (s *MultiFactorAuthService) EnrollFactor(ctx context.Context, params *MultiFactorAuthEnrollFactorParams, opts ...RequestOption) (*AuthenticationFactorEnrolled, error) {
var result AuthenticationFactorEnrolled
_, err := s.client.request(ctx, "POST", "/auth/factors/enroll", nil, params, &result, opts)
if err != nil {
return nil, err
}
return &result, nil
}
// GetFactor
// Gets an Authentication Factor.
func (s *MultiFactorAuthService) GetFactor(ctx context.Context, id string, opts ...RequestOption) (*AuthenticationFactor, error) {
var result AuthenticationFactor
_, err := s.client.request(ctx, "GET", fmt.Sprintf("/auth/factors/%s", url.PathEscape(id)), nil, nil, &result, opts)
if err != nil {
return nil, err
}
return &result, nil
}
// DeleteFactor
// Permanently deletes an Authentication Factor. It cannot be undone.
func (s *MultiFactorAuthService) DeleteFactor(ctx context.Context, id string, opts ...RequestOption) error {
_, err := s.client.request(ctx, "DELETE", fmt.Sprintf("/auth/factors/%s", url.PathEscape(id)), nil, nil, nil, opts)
return err
}
// MultiFactorAuthChallengeFactorParams contains the parameters for ChallengeFactor.
type MultiFactorAuthChallengeFactorParams struct {
// SmsTemplate is a custom template for the SMS message. Use the {{code}} placeholder to include the verification code.
SmsTemplate *string `json:"sms_template,omitempty"`
}
// ChallengeFactor
// Creates a Challenge for an Authentication Factor.
func (s *MultiFactorAuthService) ChallengeFactor(ctx context.Context, id string, params *MultiFactorAuthChallengeFactorParams, opts ...RequestOption) (*AuthenticationChallenge, error) {
var result AuthenticationChallenge
_, err := s.client.request(ctx, "POST", fmt.Sprintf("/auth/factors/%s/challenge", url.PathEscape(id)), nil, params, &result, opts)
if err != nil {
return nil, err
}
return &result, nil
}
// MultiFactorAuthListUserAuthFactorsParams contains the parameters for ListUserAuthFactors.
type MultiFactorAuthListUserAuthFactorsParams struct {
PaginationParams
}
// ListUserAuthFactors list authentication factors
// Lists the [authentication factors](https://workos.com/docs/reference/authkit/mfa/authentication-factor) for a user.
func (s *MultiFactorAuthService) ListUserAuthFactors(ctx context.Context, userlandUserID string, params *MultiFactorAuthListUserAuthFactorsParams, opts ...RequestOption) *Iterator[AuthenticationFactor] {
return newIterator[AuthenticationFactor](ctx, s.client, "GET", fmt.Sprintf("/user_management/users/%s/auth_factors", url.PathEscape(userlandUserID)), params, "after", "data", opts, map[string]string{"limit": "10", "order": "desc"})
}
// MultiFactorAuthCreateUserAuthFactorParams contains the parameters for CreateUserAuthFactor.
type MultiFactorAuthCreateUserAuthFactorParams struct {
// Type is the type of the factor to enroll.
Type string `json:"type"`
// TOTPIssuer is your application or company name displayed in the user's authenticator app.
TOTPIssuer *string `json:"totp_issuer,omitempty"`
// TOTPUser is the user's account name displayed in their authenticator app.
TOTPUser *string `json:"totp_user,omitempty"`
// TOTPSecret is the Base32-encoded shared secret for TOTP factors. This can be provided when creating the auth factor, otherwise it will be generated. The algorithm used to derive TOTP codes is SHA-1, the code length is 6 digits, and the timestep is 30 seconds – the secret must be compatible with these parameters.
TOTPSecret *string `json:"totp_secret,omitempty"`
}
// CreateUserAuthFactor enroll an authentication factor
// Enrolls a user in a new [authentication factor](https://workos.com/docs/reference/authkit/mfa/authentication-factor).
func (s *MultiFactorAuthService) CreateUserAuthFactor(ctx context.Context, userlandUserID string, params *MultiFactorAuthCreateUserAuthFactorParams, opts ...RequestOption) (*UserAuthenticationFactorEnrollResponse, error) {
var result UserAuthenticationFactorEnrollResponse
_, err := s.client.request(ctx, "POST", fmt.Sprintf("/user_management/users/%s/auth_factors", url.PathEscape(userlandUserID)), nil, params, &result, opts)
if err != nil {
return nil, err
}
return &result, nil
}