summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/nlopes/slack/oauth.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2016-09-05 16:34:37 +0200
committerWim <wim@42.be>2016-09-05 16:34:37 +0200
commitb30e85836e575974bac1b2ea91e9b6c2dd39fe44 (patch)
treeb3aa5d148e436cacd6c737ad56ba3fc0b9369e26 /vendor/github.com/nlopes/slack/oauth.go
parente449a97bd0114e55c2a73aa79b061b55d755aa16 (diff)
downloadmatterbridge-msglm-b30e85836e575974bac1b2ea91e9b6c2dd39fe44.tar.gz
matterbridge-msglm-b30e85836e575974bac1b2ea91e9b6c2dd39fe44.tar.bz2
matterbridge-msglm-b30e85836e575974bac1b2ea91e9b6c2dd39fe44.zip
Add Slack support
Diffstat (limited to 'vendor/github.com/nlopes/slack/oauth.go')
-rw-r--r--vendor/github.com/nlopes/slack/oauth.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/vendor/github.com/nlopes/slack/oauth.go b/vendor/github.com/nlopes/slack/oauth.go
new file mode 100644
index 00000000..33c3ed2d
--- /dev/null
+++ b/vendor/github.com/nlopes/slack/oauth.go
@@ -0,0 +1,54 @@
+package slack
+
+import (
+ "errors"
+ "net/url"
+)
+
+type OAuthResponseIncomingWebhook struct {
+ URL string `json:"url"`
+ Channel string `json:"channel"`
+ ConfigurationURL string `json:"configuration_url"`
+}
+
+type OAuthResponseBot struct {
+ BotUserID string `json:"bot_user_id"`
+ BotAccessToken string `json:"bot_access_token"`
+}
+
+type OAuthResponse struct {
+ AccessToken string `json:"access_token"`
+ Scope string `json:"scope"`
+ TeamName string `json:"team_name"`
+ TeamID string `json:"team_id"`
+ IncomingWebhook OAuthResponseIncomingWebhook `json:"incoming_webhook"`
+ Bot OAuthResponseBot `json:"bot"`
+ SlackResponse
+}
+
+// GetOAuthToken retrieves an AccessToken
+func GetOAuthToken(clientID, clientSecret, code, redirectURI string, debug bool) (accessToken string, scope string, err error) {
+ response, err := GetOAuthResponse(clientID, clientSecret, code, redirectURI, debug)
+ if err != nil {
+ return "", "", err
+ }
+ return response.AccessToken, response.Scope, nil
+}
+
+func GetOAuthResponse(clientID, clientSecret, code, redirectURI string, debug bool) (resp *OAuthResponse, err error) {
+ values := url.Values{
+ "client_id": {clientID},
+ "client_secret": {clientSecret},
+ "code": {code},
+ "redirect_uri": {redirectURI},
+ }
+ response := &OAuthResponse{}
+ err = post("oauth.access", values, response, debug)
+ if err != nil {
+ return nil, err
+ }
+ if !response.Ok {
+ return nil, errors.New(response.Error)
+ }
+ return response, nil
+}