You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+32-3Lines changed: 32 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,16 +62,45 @@ See the [sample app using ActiveRecord](sample_apps/sample_app_activerecord) for
62
62
63
63
### Usage
64
64
65
-
Start with one of the samples above, which contain a couple of custom commands, necessary dependencies and tests, then [create a new application](https://api.slack.com/applications/new) on Slack.
65
+
Start with one of the samples above, which contain a couple of custom commands, necessary dependencies and tests, then [create a new Slack App](https://api.slack.com/applications/new).
66
66
67
-

67
+

68
68
69
-
Follow Slack's instructions, note the app client ID and secret, give the bot a default name, etc. The redirect URL should be the location of your app, for local testing purposes use `http://localhost:9292`.
69
+
Follow Slack's instructions, note the app client ID and secret, give the bot a default name, etc. The redirect URL should be the location of your app. For local testing purposes use a public tunneling service such as [ngrok](https://ngrok.com/) to expose local port 9292.
70
70
71
71
Within your application, edit your `.env` file and add `SLACK_CLIENT_ID=...` and `SLACK_CLIENT_SECRET=...` in it.
72
72
73
73
Run `bundle install` and `foreman start` to boot the app. Navigate to [localhost:9292](http://localhost:9292). You should see an "Add to Slack" button. Use it to install the app into your own Slack team.
74
74
75
+
### OAuth Code Grant
76
+
77
+
The "Add to Slack" button uses the standard OAuth code grant flow as described in the [Slack docs](https://api.slack.com/docs/oauth#flow).
78
+
79
+
The button itself contains a link that looks like this:
Once clicked, the user is taken through the authorization process at Slack's site. Upon successful completion, a callback containing a temporary code is sent to the redirect URL you specified. The endpoint at that URL contains code that looks like this:
86
+
87
+
```ruby
88
+
# Instantiate a web client
89
+
client =Slack::Web::Client.new
90
+
91
+
# Request a token using the temporary code
92
+
rc = client.oauth_access(
93
+
client_id:ENV['SLACK_CLIENT_ID'],
94
+
client_secret:ENV['SLACK_CLIENT_SECRET'],
95
+
code: params[:code]
96
+
)
97
+
98
+
# Pluck the token from the response
99
+
token = rc['bot']['bot_access_token']
100
+
```
101
+
102
+
The token is stored in persistent storage and used each time a Slack client is instantiated for the specific team.
103
+
75
104
### API
76
105
77
106
This library implements an app, [SlackRubyBotServer::App](lib/slack-ruby-bot-server/app.rb), a service manager, [SlackRubyBotServer::Service](lib/slack-ruby-bot-server/service.rb) that creates multiple instances of a bot server class, [SlackRubyBotServer::Server](lib/slack-ruby-bot-server/server.rb), one per team.
0 commit comments