-
Notifications
You must be signed in to change notification settings - Fork 0
/
passkey.go
84 lines (75 loc) · 1.71 KB
/
passkey.go
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
package passkey
import (
"context"
"fmt"
"net/http"
"github.com/go-webauthn/webauthn/protocol"
)
type InitRegistrationRequest struct {
UserId string `json:"user_id"`
Username string `json:"username"`
DisplayName *string `json:"display_name"`
Icon *string `json:"icon"`
}
type InitLoginRequest struct {
UserId *string `json:"user_id"`
}
type TokenResponse struct {
Token string `json:"token"`
}
func (c *Client) InitRegistration(
ctx context.Context,
req InitRegistrationRequest) (*protocol.CredentialCreation, error) {
var resp protocol.CredentialCreation
if err := c.requester.do(
ctx,
http.MethodPost,
fmt.Sprintf("/%s/registration/initialize", c.tenantID),
req,
&resp); err != nil {
return nil, err
}
return &resp, nil
}
func (c *Client) FinalizeRegistration(
ctx context.Context,
req protocol.CredentialCreationResponse) (string, error) {
var resp TokenResponse
if err := c.requester.do(
ctx,
http.MethodPost,
fmt.Sprintf("/%s/registration/finalize", c.tenantID),
req,
&resp); err != nil {
return "", err
}
return resp.Token, nil
}
func (c *Client) InitLogin(
ctx context.Context,
req InitLoginRequest) (*protocol.CredentialAssertion, error) {
var resp protocol.CredentialAssertion
if err := c.requester.do(
ctx,
http.MethodPost,
fmt.Sprintf("/%s/login/initialize", c.tenantID),
req,
&resp); err != nil {
return nil, err
}
return &resp, nil
}
func (c *Client) FinalizeLogin(
ctx context.Context,
req protocol.CredentialAssertionResponse) (string, error) {
var resp TokenResponse
if err := c.requester.do(
ctx,
http.MethodPost,
fmt.Sprintf("/%s/login/finalize", c.tenantID),
req,
&resp); err != nil {
return "", err
}
return resp.Token, nil
}