-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Denis Halturin <[email protected]>
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package slack | ||
|
||
import ( | ||
"context" | ||
"net/url" | ||
) | ||
|
||
// ToolingTokensRotate contains our Auth response from the tooling.tokens.rotate endpoint | ||
type ToolingTokensRotate struct { | ||
SlackResponse // Contains the "ok", and "Error", if any | ||
Token string `json:"token"` | ||
RefreshToken string `json:"refresh_token"` | ||
TeamID string `json:"team_id"` | ||
UserID string `json:"user_id"` | ||
Iat int64 `json:"iat"` | ||
Exp int64 `json:"exp"` | ||
} | ||
|
||
// ToolingTokensRotate will send a refresh for our token | ||
func (api *Client) ToolingTokensRotate(refresh_token string) (*ToolingTokensRotate, error) { | ||
return api.ToolingTokensRotateContext(context.Background(), refresh_token) | ||
} | ||
|
||
// ToolingTokensRotateContext will send a refresh request for our token | ||
func (api *Client) ToolingTokensRotateContext(ctx context.Context, refresh_token string) (*ToolingTokensRotate, error) { | ||
response := &ToolingTokensRotate{} | ||
err := api.postMethod(ctx, "tooling.tokens.rotate", url.Values{"refresh_token": {refresh_token}}, response) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return response, response.Err() | ||
} |
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,45 @@ | ||
package slack | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func toolingTokensRotate(rw http.ResponseWriter, r *http.Request) { | ||
rw.Header().Set("Content-Type", "application/json") | ||
response := []byte(`{ | ||
"ok": true, | ||
"token": "xoxe.xoxp-...", | ||
"refresh_token": "xoxe-...", | ||
"team_id": "...", | ||
"user_id": "...", | ||
"iat": 1633095660, | ||
"exp": 1633138860 | ||
}`) | ||
rw.Write(response) | ||
} | ||
|
||
func TestToolingTokensRotate(t *testing.T) { | ||
http.HandleFunc("/tooling.tokens.rotate", toolingTokensRotate) | ||
|
||
once.Do(startServer) | ||
api := New("testing-token", OptionAPIURL("http://"+serverAddr+"/")) | ||
|
||
token, err := api.ToolingTokensRotate("xoxe.xoxp-...") | ||
if err != nil { | ||
t.Errorf("Unexpected error: %s", err) | ||
return | ||
} | ||
|
||
assert.Equal(t, true, token.Ok) | ||
assert.Equal(t, "", token.Error) | ||
|
||
assert.Equal(t, "xoxe.xoxp-...", token.Token) | ||
assert.Equal(t, "xoxe-...", token.RefreshToken) | ||
assert.Equal(t, "...", token.TeamID) | ||
assert.Equal(t, "...", token.UserID) | ||
assert.Equal(t, int64(1633095660), token.Iat) | ||
assert.Equal(t, int64(1633138860), token.Exp) | ||
} |