You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jcook-sdk/api/auth/refresh.go

48 lines
1.1 KiB

package auth
import (
"encoding/json"
"fmt"
"git.oa00.com/go/jcook-sdk/util/http"
"net/url"
)
const (
PAppKey = "app_key"
PAppSecret = "app_secret"
PRefreshToken = "refresh_token"
Url = "https://open-oauth.jd.com/oauth2/refresh_token"
PGrantType = "grant_type"
)
type Bearer struct {
AccessToken string `json:"access_token"`
ExpiresIn uint `json:"expires_in"`
RefreshToken string `json:"refresh_token"`
Scope string `json:"scope"`
UID string `json:"uid"`
Time int64 `json:"time"`
TokenType string `json:"token_type"`
Code uint `json:"code"`
Xid string `json:"xid"`
}
func RefreshToken(appKey string, appSecret string, token string) (*Bearer, error) {
value := url.Values{}
value.Set(PAppKey, appKey)
value.Set(PAppSecret, appSecret)
value.Set(PRefreshToken, token)
value.Set(PGrantType, "refresh_token")
data, err := http.JGet(Url, value, nil)
if err != nil {
fmt.Println(err.Error())
return nil, err
}
var b Bearer
if err = json.Unmarshal(data, &b); err != nil {
return nil, err
}
return &b, nil
}