From ab7d09e044be556873733ad83b083029e88bd65f Mon Sep 17 00:00:00 2001 From: Trygve Aaberge Date: Tue, 21 Jan 2020 23:56:02 +0100 Subject: Use GitHub Pages for the OAuth redirect page This adds a page which shows the OAuth code, and sets the redirect_uri for the OAuth link to this page. This url includes # at the end so the OAuth code is only seen by the browser, and not sent to the server. --- docs/oauth.html | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ wee_slack.py | 19 ++++++++-------- 2 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 docs/oauth.html diff --git a/docs/oauth.html b/docs/oauth.html new file mode 100644 index 0000000..7ef4d99 --- /dev/null +++ b/docs/oauth.html @@ -0,0 +1,68 @@ + + + + wee-slack + + + + +
+

OAuth code for wee-slack

+

Copy this command and run it in WeeChat:

+ + +
+ +
+

wee-slack

+

This page exists for using OAuth in wee-slack. For info about wee-slack see the github page.

+ +

If you came here as part of the OAuth flow and are seeing this text, that means that something went wrong. Please report this in the issue tracker and describe how you got here.

+
+ + + + diff --git a/wee_slack.py b/wee_slack.py index 2ce13e5..73a93ff 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -3771,23 +3771,23 @@ def command_register(data, current_buffer, args): """ CLIENT_ID = "2468770254.51917335286" CLIENT_SECRET = "dcb7fe380a000cba0cca3169a5fe8d70" # Not really a secret. + REDIRECT_URI = "https%3A%2F%2Fwee-slack.github.io%2Fwee-slack%2Foauth%23" if not args: message = textwrap.dedent(""" - #### 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** + ### Connecting to a Slack team with OAuth ### + 1) Paste this link into a browser: https://slack.com/oauth/authorize?client_id={}&scope=client&redirect_uri={} + 2) Select the team you wish to access from wee-slack in your browser. If you want to add multiple teams, you will have to repeat this whole process for each team. + 3) Click "Authorize" in the browser. If you get a message saying you are not authorized to install wee-slack, the team has restricted Slack app installation and you will have to request it from an admin. To do that, go to https://my.slack.com/apps/A1HSZ9V8E-wee-slack and click "Request to Install". - 4) Copy the "code" portion of the URL to your clipboard - 5) Return to weechat and run `/slack register [code]` - """).strip() + 4) The web page will show a command in the form `/slack register `. Run this command in weechat. + """).strip().format(CLIENT_ID, REDIRECT_URI) w.prnt("", message) return w.WEECHAT_RC_OK_EAT uri = ( "https://slack.com/api/oauth.access?" - "client_id={}&client_secret={}&code={}" - ).format(CLIENT_ID, CLIENT_SECRET, args) + "client_id={}&client_secret={}&redirect_uri={}&code={}" + ).format(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI, args) params = {'useragent': 'wee_slack {}'.format(SCRIPT_VERSION)} w.hook_process_hashtable('url:', params, config.slack_timeout, "", "") w.hook_process_hashtable("url:{}".format(uri), params, config.slack_timeout, "register_callback", "") @@ -3822,6 +3822,7 @@ def register_callback(data, command, return_code, out, err): w.prnt("", "Success! Added team \"%s\"" % (d['team_name'],)) w.prnt("", "Please reload wee-slack with: /python reload slack") + w.prnt("", "If you want to add another team you can repeat this process from step 1 before reloading wee-slack.") return w.WEECHAT_RC_OK_EAT -- cgit