RevokeToken revokes an OAuth access or refresh token via POST /2/oauth/revoke.
(token string)
| 192 | |
| 193 | // RevokeToken revokes an OAuth access or refresh token via POST /2/oauth/revoke. |
| 194 | func (c *Client) RevokeToken(token string) error { |
| 195 | form := url.Values{ |
| 196 | "client_id": {c.ClientID}, |
| 197 | "token": {token}, |
| 198 | } |
| 199 | |
| 200 | req, err := http.NewRequest( |
| 201 | http.MethodPost, |
| 202 | c.DashboardURL+"/2/oauth/revoke", |
| 203 | strings.NewReader(form.Encode()), |
| 204 | ) |
| 205 | if err != nil { |
| 206 | return err |
| 207 | } |
| 208 | req.Header.Set("Content-Type", "application/x-www-form-urlencoded") |
| 209 | req.Header.Set("Accept", "application/json") |
| 210 | |
| 211 | resp, err := c.client.Do(req) |
| 212 | if err != nil { |
| 213 | return fmt.Errorf("token revocation request failed: %w", err) |
| 214 | } |
| 215 | defer resp.Body.Close() |
| 216 | |
| 217 | if resp.StatusCode != http.StatusOK { |
| 218 | return parseOAuthError(resp, "token revocation") |
| 219 | } |
| 220 | |
| 221 | return nil |
| 222 | } |
| 223 | |
| 224 | // ListApplications returns all applications for the authenticated user, |
| 225 | // following pagination to fetch every page. |
no test coverage detected