feat: update
This commit is contained in:
@@ -11,6 +11,7 @@ func (r *ErrorResponse) Error() error {
|
||||
|
||||
type AccessTokenResponse struct {
|
||||
ErrorResponse
|
||||
AccessToken string `json:"access_token,omitempty"`
|
||||
ExpiresIn int `json:"expires_in,omitempty"` // seconds
|
||||
AccessToken string `json:"access_token,omitempty"`
|
||||
RefreshToken string `json:"refresh_token,omitempty"`
|
||||
ExpiresIn int `json:"expires_in,omitempty"` // seconds
|
||||
}
|
||||
|
||||
@@ -89,6 +89,26 @@ func (we *Client) wrapParams(params map[string]string) map[string]string {
|
||||
return params
|
||||
}
|
||||
|
||||
// RefreshAccessToken
|
||||
func (we *Client) RefreshAccessToken(refreshToken string) (*AccessTokenResponse, error) {
|
||||
params := we.wrapParams(map[string]string{
|
||||
"grant_type": "refresh_token",
|
||||
"refresh_token": refreshToken,
|
||||
})
|
||||
|
||||
var data AccessTokenResponse
|
||||
_, err := we.client.R().SetSuccessResult(&data).SetQueryParams(params).Get("/sns/oauth2/refresh_token")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "call /sns/oauth2/refresh_token failed")
|
||||
}
|
||||
|
||||
if data.ErrCode != 0 {
|
||||
return nil, data.Error()
|
||||
}
|
||||
|
||||
return &data, nil
|
||||
}
|
||||
|
||||
func (we *Client) GetAccessToken() (*AccessTokenResponse, error) {
|
||||
params := map[string]string{
|
||||
"grant_type": "client_credential",
|
||||
|
||||
Reference in New Issue
Block a user