-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathauth.go
61 lines (56 loc) · 1.51 KB
/
auth.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package slack
import (
"net/http"
"net/url"
)
// AuthTestResponse is response to auth.test - see https://api.slack.com/methods/auth.test
type AuthTestResponse struct {
slackResponse
URL string `json:"url"`
Team string `json:"team"`
User string `json:"user"`
TeamID string `json:"team_id"`
UserID string `json:"user_id"`
}
// OAuthAccessResponse - See https://api.slack.com/methods/oauth.access
type OAuthAccessResponse struct {
slackResponse
AccessToken string `json:"access_token"`
Scope string `json:"scope"`
TeamName string `json:"team_name"`
TeamID string `json:"team_id"`
Bot struct {
BotUserID string `json:"bot_user_id"`
BotAccessToken string `json:"bot_access_token"`
} `json:"bot"`
}
// AuthTest tests if the authentication is in place - see https://api.slack.com/methods/auth.test
func (s *Slack) AuthTest() (*AuthTestResponse, error) {
r := &AuthTestResponse{}
err := s.do("auth.test", url.Values{}, r)
if err != nil {
return nil, err
}
return r, nil
}
// OAuthAccess returns the token for OAuth
func OAuthAccess(clientID, clientSecret, code, redirectURI string) (*OAuthAccessResponse, error) {
params := url.Values{
"client_id": {clientID},
"client_secret": {clientSecret},
"code": {code},
}
if redirectURI != "" {
params.Set("redirect_uri", redirectURI)
}
s := &Slack{
url: DefaultURL,
c: http.DefaultClient,
}
r := &OAuthAccessResponse{}
err := s.do("oauth.access", params, r)
if err != nil {
return nil, err
}
return r, nil
}