slack-ruby / slack-ruby-client

A Ruby and command-line client for the Slack Web, Real Time Messaging and Event APIs.
MIT License
1.21k stars 215 forks source link

How to setup using OAuth rather than API key? #267

Closed coryschires closed 5 years ago

coryschires commented 5 years ago

Hi, thanks for creating this gem!

Looking at the docs, I see instructions for getting started using an API Key. However, reading the most recent docs on Slack, it seems this method has been deprecated. Instead, they now recommend creating "apps" which apparently by default use an OAuth flow.

Probably, you already know all this 🤷‍♂

So my question: How do I setup auth for this gem using the new, oauth workflow? For example, I would expect that would need to specify my client_secret and client_id in an initializer?

But I couldn't find any instructions in the readme. Any help would be much appreciated!

Thanks again!

dblock commented 5 years ago

The short answer is yes. The client implements all the OAuth methods, eg. oauth_access and oauth_token. I realize it's not well documented in this README, maybe you can help?

Check out https://code.dblock.org/2016/03/11/your-first-slack-bot-service-video.html for a walkthrough and https://github.com/slack-ruby/slack-ruby-bot-server for a higher level gem that does a lot of the heavy lifting.

suryart commented 5 years ago

@dblock : Any reason for not using the oauth2 gem for this purpose? Such as setting up client id, scope etc, and generating the authorize URL/auth code URL manually doesn't feel idiomatic.

dblock commented 5 years ago

No reason @suryart. A good doc (and potentially PRs to slack-ruby-bot-server) would be appreciated.

jcraigk commented 5 years ago

@coryschires See this Slack OAuth callback implementation https://github.com/jcraigk/phishin-chatbot/blob/master/app/controllers/oauth/slack_controller.rb. At some point when I am more confident in this flow I will PR into the slack-ruby-bot-server README.