summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/nlopes/slack/oauth.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2018-01-08 22:41:38 +0100
committerWim <wim@42.be>2018-01-09 00:07:55 +0100
commitbe898b44c3c057c7b70efb83f66b7bbbdd5e9276 (patch)
tree01c8983913bcae177b5e0e015de9a45abe8369a7 /vendor/github.com/nlopes/slack/oauth.go
parent4828c434439949f62a6e219ab9947c221a06b111 (diff)
downloadmatterbridge-msglm-be898b44c3c057c7b70efb83f66b7bbbdd5e9276.tar.gz
matterbridge-msglm-be898b44c3c057c7b70efb83f66b7bbbdd5e9276.tar.bz2
matterbridge-msglm-be898b44c3c057c7b70efb83f66b7bbbdd5e9276.zip
Update vendor (slack)
Diffstat (limited to 'vendor/github.com/nlopes/slack/oauth.go')
-rw-r--r--vendor/github.com/nlopes/slack/oauth.go66
1 files changed, 66 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..db10aa1b
--- /dev/null
+++ b/vendor/github.com/nlopes/slack/oauth.go
@@ -0,0 +1,66 @@
+package slack
+
+import (
+ "context"
+ "errors"
+ "net/url"
+)
+
+type OAuthResponseIncomingWebhook struct {
+ URL string `json:"url"`
+ Channel string `json:"channel"`
+ ChannelID string `json:"channel_id,omitempty"`
+ 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"`
+ UserID string `json:"user_id,omitempty"`
+ SlackResponse
+}
+
+// GetOAuthToken retrieves an AccessToken
+func GetOAuthToken(clientID, clientSecret, code, redirectURI string, debug bool) (accessToken string, scope string, err error) {
+ return GetOAuthTokenContext(context.Background(), clientID, clientSecret, code, redirectURI, debug)
+}
+
+// GetOAuthTokenContext retrieves an AccessToken with a custom context
+func GetOAuthTokenContext(ctx context.Context, clientID, clientSecret, code, redirectURI string, debug bool) (accessToken string, scope string, err error) {
+ response, err := GetOAuthResponseContext(ctx, 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) {
+ return GetOAuthResponseContext(context.Background(), clientID, clientSecret, code, redirectURI, debug)
+}
+
+func GetOAuthResponseContext(ctx context.Context, 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(ctx, "oauth.access", values, response, debug)
+ if err != nil {
+ return nil, err
+ }
+ if !response.Ok {
+ return nil, errors.New(response.Error)
+ }
+ return response, nil
+}