| 1 | package slack |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "net/url" |
| 6 | ) |
| 7 | |
| 8 | // AuthRevokeResponse contains our Auth response from the auth.revoke endpoint |
| 9 | type AuthRevokeResponse struct { |
| 10 | SlackResponse // Contains the "ok", and "Error", if any |
| 11 | Revoked bool `json:"revoked,omitempty"` |
| 12 | } |
| 13 | |
| 14 | // authRequest sends the actual request, and unmarshals the response |
| 15 | func (api *Client) authRequest(ctx context.Context, path string, values url.Values) (*AuthRevokeResponse, error) { |
| 16 | response := &AuthRevokeResponse{} |
| 17 | err := api.postMethod(ctx, path, values, response) |
| 18 | if err != nil { |
| 19 | return nil, err |
| 20 | } |
| 21 | |
| 22 | return response, response.Err() |
| 23 | } |
| 24 | |
| 25 | // SendAuthRevoke will send a revocation for our token |
| 26 | func (api *Client) SendAuthRevoke(token string) (*AuthRevokeResponse, error) { |
| 27 | return api.SendAuthRevokeContext(context.Background(), token) |
| 28 | } |
| 29 | |
| 30 | // SendAuthRevokeContext will send a revocation request for our token to api.revoke with context |
| 31 | func (api *Client) SendAuthRevokeContext(ctx context.Context, token string) (*AuthRevokeResponse, error) { |
| 32 | if token == "" { |
| 33 | token = api.token |
| 34 | } |
| 35 | values := url.Values{ |
| 36 | "token": {token}, |
| 37 | } |
| 38 | |
| 39 | return api.authRequest(ctx, "auth.revoke", values) |
| 40 | } |