Skip to content

Commit 42c813b

Browse files
committed
update documentation and comments with oauth information
1 parent f7c0c40 commit 42c813b

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

documentation/secret_docs.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ A secrets file stores sensitive information. Unlike the repository configuration
2020
| `slack_access_token` | slack bot access token to enable message posting to the workspace | Yes | try to use webhooks defined in `slack_hooks` instead |
2121
| `slack_hooks` | list of channel names and their corresponding webhook endpoint | Yes | try to use token defined in `slack_access_token` instead |
2222
| `slack_signing_secret` | specify to verify incoming slack requests | Yes | - |
23+
| `slack_client_id` | slack client ID, used for [oauth](https://api.slack.com/authentication/oauth-v2) authentication | Yes | - |
24+
| `slack_client_secret` | slack client secret, used for [oauth](https://api.slack.com/authentication/oauth-v2) authentication | Yes | - |
25+
| `slack_oauth_state` | specify some unique value to maintain state b/w oauth request and callback and prevent CSRF (see [RFC6749](https://tools.ietf.org/html/rfc6749#section-4.1.1)) | Yes | - |
2326

2427
Note that either `slack_access_token` or `slack_hooks` must be defined.
2528

29+
The fields `slack_client_id`, `slack_client_secret`, and `slack_oauth_state` only apply if you need to distribute the app to multiple users.
30+
2631
## `gh_token`
2732

2833
Some operations, such as fetching a config file from a private repository, or the commit corresponding to a commit comment event, require a personal access token. Refer [here](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token) for detailed instructions on token generation.
@@ -35,6 +40,8 @@ Refer [here](https://docs.github.com/en/free-pro-team@latest/developers/webhooks
3540

3641
Refer [here](https://api.slack.com/authentication/oauth-v2) for obtaining an access token via OAuth.
3742

43+
If automatic OAuth exchange is set up, the bot will configure this value at runtime.
44+
3845
## `slack_hooks`
3946

4047
*Note: If `slack_access_token` is also defined, the bot will authenticate over Slack's Web API and this option will not be used.*

lib/action.ml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,28 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
281281
match notification.event with
282282
| Link_shared event -> process_link_shared_event ctx event
283283

284+
(**
285+
286+
If there is a need to distribute the app, automatic OAuth exchange must be enabled.
287+
288+
The fields `slack_client_id` and `slack_client_secret` must be configured in the
289+
secrets file. The `slack_oauth_state` field can be optionally provided to avoid
290+
forgery attacks during the OAuth exchange.
291+
(see: https://tools.ietf.org/html/rfc6749#section-4.1.1)
292+
293+
All of these fields are retrievable from the Slack app dashboard.
294+
295+
Once the server has been configured and launched, it will listen on `/slack/oauth`
296+
for incoming OAuth requests from Slack. Each user should then go to the following
297+
address, replacing the appropriate values (the `state` argument is only needed
298+
if `slack_oauth_state` is set).
299+
300+
https://slack.com/oauth/v2/authorize?scope=chat:write&client_id=<slack_client_id>&redirect_uri=<server_domain>/slack/oauth&state=<slack_oauth_state>
301+
302+
A page should open asking the user permission to install the bot to their
303+
workspace. Clicking `allow` will trigger the OAuth exchange.
304+
305+
*)
284306
let process_slack_oauth (ctx : Context.t) args =
285307
try%lwt
286308
let secrets = Context.get_secrets_exn ctx in

0 commit comments

Comments
 (0)