remind101 / slashdeploy

GitHub Deployments for Slack
https://slashdeploy.io
BSD 2-Clause "Simplified" License
153 stars 20 forks source link

Fix Slack OAuth flow bugs #168

Closed aengelas closed 4 years ago

aengelas commented 4 years ago

This fixes 2 (what I believe to be) bugs in the current code:

  1. app/models/slack_account.rb was attempting to use auth_hash[:info][:team_domain] to set the team domain (actually the subdomain prepended to slack.com to form the URL to a workspace. That key does not exist in the OAuth data; I suspect it used to and that we haven't updated the code since Slack made API changes. Unfortunately, per https://api.slack.com/authentication/oauth-v2#waiting, Slack no longer returns the team domain. They do however return the URL to the workspace. I updated the code to extract the subdomain from the workspace URL and use that as the domain.

  2. app/models/slack_bot.rb was attempting to use bot_info[:bot_user_id] to get the bot user id, which also does not exist as far as I can tell. I updated it to use bot_info[:bot_access_token], which is what the code uses immediately below; I think this was an actual bug where the two should be referencing the same keys.

It also tidies up code in a few places to improve readability.