forked from slack-go/slack
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
67 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package slack | ||
|
||
import ( | ||
"context" | ||
"net/url" | ||
) | ||
|
||
// RotateTokens exchanges a refresh token for a new app configuration token | ||
func (api *Client) RotateTokens(refreshToken string) (*TokenResponse, error) { | ||
return api.RotateTokensContext(context.Background(), refreshToken) | ||
} | ||
|
||
// RotateTokensContext exchanges a refresh token for a new app configuration token with a custom context | ||
func (api *Client) RotateTokensContext(ctx context.Context, refreshToken string) (*TokenResponse, error) { | ||
if refreshToken == "" { | ||
refreshToken = api.configRefreshToken | ||
} | ||
|
||
values := url.Values{ | ||
"refresh_token": {refreshToken}, | ||
} | ||
|
||
response := &TokenResponse{} | ||
err := api.postMethod(ctx, "tooling.tokens.rotate", values, response) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return response, response.Err() | ||
} | ||
|
||
type TokenResponse struct { | ||
Token string `json:"token,omitempty"` | ||
RefreshToken string `json:"refresh_token,omitempty"` | ||
TeamId string `json:"team_id,omitempty"` | ||
UserId string `json:"user_id,omitempty"` | ||
CreatedAt uint64 `json:"iat,omitempty"` | ||
ExpiresAt uint64 `json:"exp,omitempty"` | ||
SlackResponse | ||
} |