-
Notifications
You must be signed in to change notification settings - Fork 13
/
oauth.go
39 lines (31 loc) · 896 Bytes
/
oauth.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
package mixin
import (
"context"
"errors"
"time"
)
func AuthorizeToken(ctx context.Context, clientID, clientSecret string, code string, verifier string) (string, string, error) {
params := map[string]interface{}{
"client_id": clientID,
"client_secret": clientSecret,
"code": code,
"code_verifier": verifier,
}
resp, err := Request(ctx).SetBody(params).Post("/oauth/token")
if err != nil {
return "", "", err
}
var body struct {
AccessToken string `json:"access_token"`
Scope string `json:"scope"`
}
err = UnmarshalResponse(resp, &body)
return body.AccessToken, body.Scope, err
}
type accessTokenAuth string
func (a accessTokenAuth) SignToken(signature, requestID string, exp time.Duration) string {
return string(a)
}
func (a accessTokenAuth) EncryptPin(pin string) string {
panic(errors.New("[access token auth] encrypt pin: forbidden"))
}