aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorRyan Huber <rhuber@gmail.com>2016-09-26 12:07:31 -0700
committerGitHub <noreply@github.com>2016-09-26 12:07:31 -0700
commit8e5d385f74b3b3b30a5230e3e88e1a5c21c98d2f (patch)
tree7547752118e85afd78ca1c58475f6409a9cddf62 /wee_slack.py
parent4958bfeddd9b8a02ae0e56e4d54b06dc05641a6f (diff)
parent4c518b69dbd91a1d0855141bf463be21e3ebece6 (diff)
downloadwee-slack-8e5d385f74b3b3b30a5230e3e88e1a5c21c98d2f.tar.gz
Merge pull request #245 from rawdigits/oauth-test
add oauth code
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/wee_slack.py b/wee_slack.py
index be3d2bd..1bd671f 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -1058,6 +1058,35 @@ def slack_buffer_required(f):
return f(current_buffer, *args, **kwargs)
return wrapper
+def command_register(current_buffer, args):
+ CLIENT_ID="2468770254.51917335286"
+ CLIENT_SECRET="dcb7fe380a000cba0cca3169a5fe8d70" #this is not really a secret
+ if not args:
+ message = """
+#### Retrieving a Slack token via OAUTH ####
+
+1) Paste this into a browser: https://slack.com/oauth/authorize?client_id=2468770254.51917335286&scope=client
+2) Select the team you wish to access from wee-slack in your browser.
+3) Click "Authorize" in the browser **IMPORTANT: the redirect will fail, this is expected**
+4) Copy the "code" portion of the URL to your clipboard
+5) Return to weechat and run `/slack register [code]`
+6) Add the returned token per the normal wee-slack setup instructions
+
+
+"""
+ w.prnt(current_buffer, message)
+ else:
+ aargs = args.split(None, 2)
+ if len(aargs) <> 1:
+ w.prnt(current_buffer, "ERROR: invalid args to register")
+ else:
+ #w.prnt(current_buffer, "https://slack.com/api/oauth.access?client_id={}&client_secret={}&code={}".format(CLIENT_ID, CLIENT_SECRET, aargs[0]))
+ ret = urllib.urlopen("https://slack.com/api/oauth.access?client_id={}&client_secret={}&code={}".format(CLIENT_ID, CLIENT_SECRET, aargs[0])).read()
+ d = json.loads(ret)
+ if d["ok"] == True:
+ w.prnt(current_buffer, "Success! Access token is: " + d['access_token'])
+ else:
+ w.prnt(current_buffer, "Failed! Error is: " + d['error'])
@slack_buffer_or_ignore