forked from slack-go/slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokens.go
33 lines (28 loc) · 1.03 KB
/
tokens.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package tokens
import (
"fmt"
"github.com/slack-go/slack"
)
func main() {
api := slack.New(
"YOUR_TOKEN_HERE",
// You may choose to provide your config tokens when creating your Slack client
// or when invoking the method calls
slack.OptionConfigToken("YOUR_CONFIG_ACCESS_TOKEN_HERE"),
slack.OptionConfigRefreshToken("YOUR_REFRESH_TOKEN_HERE"),
)
// Obtain a fresh set of tokens
// You may pass your tokens as a parameter here as well, if you didn't do it above
freshTokens, err := api.RotateTokens("", "")
if err != nil {
fmt.Printf("error rotating tokens: %v\n", err)
return
}
fmt.Printf("new access token: %s\n", freshTokens.Token)
fmt.Printf("new refresh token: %s\n", freshTokens.RefreshToken)
fmt.Printf("new tokenset expires at: %d\n", freshTokens.ExpiresAt)
// Optionally: update the tokens inside the running Slack client
// This isn't necessary if you restart the application after storing the tokens elsewhere,
// or pass them as parameters to RotateTokens() explicitly
api.UpdateConfigTokens(freshTokens)
}