MCPcopy Create free account
hub / github.com/algolia/cli / RevokeToken

Method RevokeToken

api/dashboard/client.go:194–222  ·  view source on GitHub ↗

RevokeToken revokes an OAuth access or refresh token via POST /2/oauth/revoke.

(token string)

Source from the content-addressed store, hash-verified

192
193// RevokeToken revokes an OAuth access or refresh token via POST /2/oauth/revoke.
194func (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.

Callers 1

runLogoutCmdFunction · 0.80

Calls 4

parseOAuthErrorFunction · 0.85
ErrorfMethod · 0.65
CloseMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected