aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan Huber <rhuber@gmail.com>2016-06-20 13:12:47 -0700
committerA. Jesse Jiryu Davis <jesse@mongodb.com>2018-01-15 15:35:31 -0500
commit30139cd31c9655f9e4c65775a5a4ea6809b72e76 (patch)
treea0e9081caa033b042a5a33fcd35a9be7f741d5a0
parent5e16fa41535a0347b34adca89a13560aec6d36bc (diff)
downloadwee-slack-30139cd31c9655f9e4c65775a5a4ea6809b72e76.tar.gz
add oauth code
-rw-r--r--wee_slack.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 49ec61e..5bdb30d 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -2964,6 +2964,37 @@ def me_command_cb(data, current_buffer, args):
return w.WEECHAT_RC_OK_EAT
+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
@utf8_decode
def msg_command_cb(data, current_buffer, args):