generated from mythrnr/template-lib-golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_user.go
117 lines (98 loc) · 2.68 KB
/
api_user.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
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
package paypayopa
import (
"context"
"encoding/json"
"net/url"
"time"
)
type CreateAccountLinkQRCodePayload struct {
Scopes []Scope `json:"scopes"`
Nonce string `json:"nonce"`
RedirectType string `json:"redirectType"`
RedirectURL string `json:"redirectUrl"`
ReferenceID string `json:"referenceId"`
PhoneNumber string `json:"phoneNumber"`
DeviceID string `json:"deviceId"`
UserAgent string `json:"userAgent"`
}
type CreateAccountLinkQRCodeResponse struct {
LinkQRCodeURL string `json:"linkQRCodeURL"`
}
func createAccountLinkQRCode(
ctx context.Context,
client *opaClient,
req *CreateAccountLinkQRCodePayload,
) (*CreateAccountLinkQRCodeResponse, *ResultInfo, error) {
const timeout = 10 * time.Second
res := &CreateAccountLinkQRCodeResponse{}
info, err := client.POST(
ctxWithTimeout(ctx, timeout),
"/v1/qr/sessions",
res,
req,
)
if err != nil || !info.Success() {
return nil, info, err
}
return res, info, nil
}
type GetUserAuthorizationStatusResponse struct {
UserAuthorizationID string `json:"userAuthorizationId"`
ReferenceIDs *json.RawMessage `json:"referenceIds"`
Status string `json:"status"`
Scopes []string `json:"scopes"`
ExpireAt int64 `json:"expireAt"`
IssuedAt int64 `json:"issuedAt"`
}
func getUserAuthorizationStatus(
ctx context.Context,
client *opaClient,
userAuthorizationID string,
) (*GetUserAuthorizationStatusResponse, *ResultInfo, error) {
const timeout = 15 * time.Second
res := &GetUserAuthorizationStatusResponse{}
info, err := client.GET(
ctxWithTimeout(ctx, timeout),
"/v2/user/authorizations?"+url.Values{
"userAuthorizationId": []string{userAuthorizationID},
}.Encode(),
res,
)
if err != nil || !info.Success() {
return nil, info, err
}
return res, info, nil
}
func unlinkUser(
ctx context.Context,
client *opaClient,
userAuthorizationID string,
) (*ResultInfo, error) {
const timeout = 15 * time.Second
return client.DELETE(
ctxWithTimeout(ctx, timeout),
"/v2/user/authorizations/"+userAuthorizationID,
)
}
type GetMaskedUserProfileResponse struct {
PhoneNumber string `json:"phoneNumber"`
}
func getMaskedUserProfile(
ctx context.Context,
client *opaClient,
userAuthorizationID string,
) (*GetMaskedUserProfileResponse, *ResultInfo, error) {
const timeout = 15 * time.Second
res := &GetMaskedUserProfileResponse{}
info, err := client.GET(
ctxWithTimeout(ctx, timeout),
"/v2/user/profile/secure?"+url.Values{
"userAuthorizationId": []string{userAuthorizationID},
}.Encode(),
res,
)
if err != nil || !info.Success() {
return nil, info, err
}
return res, info, nil
}