generated from oklookat/gostarter
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1_getAnon.go
48 lines (37 loc) · 931 Bytes
/
1_getAnon.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
package vkmauth
import (
"context"
"github.com/oklog/ulid/v2"
)
func getAnonymousToken(ctx context.Context) (*anonymousToken, error) {
deviceId := ulid.Make().String()
form := map[string]string{
"client_id": _clientId,
"client_secret": _clientSecret,
"device_id": deviceId,
"api_id": _apiId,
}
result := &anonymousToken{}
respErr := map[string]any{}
cl := getClient()
resp, err := cl.R().
SetFormUrlMap(form).
SetResult(result).
SetError(&respErr).
Post(ctx, _vkOAuthUrl+"/get_anonym_token")
if err != nil {
return nil, err
}
if resp.IsError() {
return nil, newUnknownError(resp.StatusCode, "getAnonymousToken-resp.IsError()", respErr)
}
result.DeviceId = deviceId
return result, err
}
type anonymousToken struct {
Token string `json:"token"`
// Unix ms, expires after 1 day.
ExpiredAt int64 `json:"expired_at"`
// Not response of API.
DeviceId string `json:"-"`
}