RevokeToken revokes a refresh token with the tenant so that it can no longer be used to get new tokens.
(ctx context.Context, refreshToken string)
| 190 | // RevokeToken revokes a refresh token with the tenant so that it can no longer |
| 191 | // be used to get new tokens. |
| 192 | func (a API) RevokeToken(ctx context.Context, refreshToken string) error { |
| 193 | data := url.Values{ |
| 194 | "client_id": {a.ClientID}, |
| 195 | "token": {refreshToken}, |
| 196 | } |
| 197 | |
| 198 | revokeURL := a.TenantURL + "/oauth/revoke" |
| 199 | resp, err := postForm(ctx, revokeURL, strings.NewReader(data.Encode())) |
| 200 | if err != nil { |
| 201 | return err |
| 202 | } |
| 203 | defer func() { |
| 204 | _ = resp.Body.Close() |
| 205 | }() |
| 206 | |
| 207 | if resp.StatusCode != http.StatusOK { |
| 208 | return tryDecodeOAuthError(resp) |
| 209 | } |
| 210 | |
| 211 | return nil |
| 212 | } |
| 213 | |
| 214 | func postForm(ctx context.Context, reqURL string, data io.Reader) (*http.Response, error) { |
| 215 | req, err := http.NewRequestWithContext(ctx, http.MethodPost, reqURL, data) |