-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathpasswordless.go
More file actions
54 lines (45 loc) · 1.89 KB
/
passwordless.go
File metadata and controls
54 lines (45 loc) · 1.89 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
// @oagen-ignore-file
package workos
import (
"context"
"fmt"
"net/url"
)
// PasswordlessService handles Passwordless session operations.
type PasswordlessService struct {
client *Client
}
// PasswordlessSession represents a passwordless session.
type PasswordlessSession struct {
ID string `json:"id"`
Email string `json:"email"`
ExpiresAt string `json:"expires_at"`
Link string `json:"link"`
Object string `json:"object"`
}
// PasswordlessSessionType is the type of passwordless session.
type PasswordlessSessionType string
// PasswordlessSessionTypeMagicLink is the MagicLink session type.
const PasswordlessSessionTypeMagicLink PasswordlessSessionType = "MagicLink"
// PasswordlessCreateSessionParams are the parameters for creating a passwordless session.
type PasswordlessCreateSessionParams struct {
Email string `json:"email"`
Type PasswordlessSessionType `json:"type"`
RedirectURI *string `json:"redirect_uri,omitempty"`
State *string `json:"state,omitempty"`
ExpiresIn *int `json:"expires_in,omitempty"`
}
// CreateSession creates a new passwordless session (POST /passwordless/sessions).
func (s *PasswordlessService) CreateSession(ctx context.Context, params *PasswordlessCreateSessionParams, opts ...RequestOption) (*PasswordlessSession, error) {
var result PasswordlessSession
_, err := s.client.request(ctx, "POST", "/passwordless/sessions", nil, params, &result, opts)
if err != nil {
return nil, err
}
return &result, nil
}
// SendSession sends the magic-link email for a session (POST /passwordless/sessions/{id}/send).
func (s *PasswordlessService) SendSession(ctx context.Context, sessionID string, opts ...RequestOption) error {
_, err := s.client.request(ctx, "POST", fmt.Sprintf("/passwordless/sessions/%s/send", url.PathEscape(sessionID)), nil, nil, nil, opts)
return err
}