Skip to content

Commit 61f9bd1

Browse files
feat(standardized-auth): add an acme sample for standardized app auth
Connects user accounts with the Slack-owned Connect and Manage connection controls. Bolt's installation service holds each connection: the OAuth success hook reports it with apps.user.connection.requestAuth, the disconnect action forgets and revokes the user token, tokens_revoked forgets users who remove the app, and the user_connection_status_requested event is answered with apps.user.connection.update. App Home renders the auth_provider block. The user_connection request listener is written and tested but not yet registered, since no Bolt routes that payload to action listeners yet. This depends on java-slack-sdk 1.52.1-SNAPSHOT (AuthProviderBlock, the new methods, and the status-requested event model) until it is released.
1 parent be0c2ff commit 61f9bd1

22 files changed

Lines changed: 1165 additions & 0 deletions

‎.github/dependabot.yml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,15 @@ updates:
3030
slack:
3131
patterns:
3232
- "com.slack.api:*"
33+
- package-ecosystem: "maven"
34+
directory: "standardized-auth"
35+
schedule:
36+
interval: "daily"
37+
cooldown:
38+
default-days: 7
39+
exclude:
40+
- "com.slack.api:*"
41+
groups:
42+
slack:
43+
patterns:
44+
- "com.slack.api:*"

‎.github/workflows/test.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
showcase:
1717
- "block-kit"
1818
- "methods"
19+
- "standardized-auth"
1920
steps:
2021
- name: Checkout code
2122
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ This collections of examples highlights features of a Slack app in the language
66

77
- **[Block Kit](./block-kit)**: The framework of visual components arranged to create app layouts.
88
- **[Methods](./methods)**: An interface for querying information from and enacting change in a Slack workspace.
9+
- **[Standardized Auth](./standardized-auth)**: Connect user accounts with the Slack-owned Connect and Manage connection controls.

‎standardized-auth/.env.example‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SLACK_CLIENT_ID=
2+
SLACK_CLIENT_SECRET=
3+
SLACK_SIGNING_SECRET=
4+
BASE_URL=https://1234-56-78-90-0.ngrok-free.app
5+
PORT=3000

‎standardized-auth/.gitignore‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.classpath
2+
.project
3+
.settings
4+
target
5+
data/
6+
.env*
7+
!.env.example
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
apps.dev.json
2+
cache/
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"manifest": {
3+
"source": "local"
4+
},
5+
"project_id": "00000000-0000-0000-0000-000000000000"
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"hooks": {
3+
"start": "mvn --quiet compile exec:java"
4+
},
5+
"config": {
6+
"sdk-managed-connection-enabled": true
7+
}
8+
}

‎standardized-auth/README.md‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Standardized Auth
2+
3+
Connect your Acme account to Slack with the Slack-owned **Connect** and **Manage connection** controls. Rocket skates, anvils, and giant magnets not included.
4+
5+
Read the docs: https://docs.slack.dev/authentication/standardized-auth
6+
7+
## How it works
8+
9+
Acme keeps every connection in Bolt's installation service: a user is connected when it holds their user token.
10+
11+
- **Connect** opens `/slack/install`. When the OAuth flow saves the user's token, the app reports the connection with `apps.user.connection.requestAuth` and refreshes App Home.
12+
- **Disconnect** forgets the user's token, reports the user as disconnected, then revokes the token.
13+
- **`user_connection_status_requested`** answers with `apps.user.connection.update` whenever Slack asks about a user it doesn't know yet.
14+
- **`tokens_revoked`** forgets users who remove Acme from their Slack settings and reports them as disconnected.
15+
- **App Home** shows an `auth_provider` block with the user's current connection.
16+
17+
## Setup
18+
19+
```sh
20+
$ ngrok http 3000 # Replace 1234-56-78-90-0.ngrok-free.app in manifest.json
21+
$ slack install --environment local # Create a new app
22+
$ slack app settings # Gather the client ID, client secret, and signing secret
23+
$ slack env init # Update defaults with them and your ngrok URL
24+
$ slack manifest # Validate fields
25+
$ slack run
26+
$ open https://1234-56-78-90-0.ngrok-free.app/slack/install # Install the app
27+
```
28+
29+
Then open the app's **Home** tab and click **Connect**.
30+
31+
Swap the `users:read` and `users.profile:read` scopes for the ones your connection needs.

‎standardized-auth/manifest.json‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"display_information": {
3+
"name": "Acme",
4+
"description": "Rocket skates, anvils, and giant magnets for every plan",
5+
"background_color": "#4A154B"
6+
},
7+
"features": {
8+
"app_home": {
9+
"home_tab_enabled": true,
10+
"messages_tab_enabled": false
11+
},
12+
"bot_user": {
13+
"display_name": "Acme",
14+
"always_online": true
15+
},
16+
"user_connections": {
17+
"is_enabled": true,
18+
"auth_hosts": ["1234-56-78-90-0.ngrok-free.app"]
19+
}
20+
},
21+
"oauth_config": {
22+
"redirect_urls": ["https://1234-56-78-90-0.ngrok-free.app/slack/oauth_redirect"],
23+
"scopes": {
24+
"bot": ["users:read"],
25+
"user": ["users.profile:read"]
26+
}
27+
},
28+
"settings": {
29+
"event_subscriptions": {
30+
"request_url": "https://1234-56-78-90-0.ngrok-free.app/slack/events",
31+
"bot_events": [
32+
"app_home_opened",
33+
"tokens_revoked",
34+
"user_connection_status_requested"
35+
]
36+
},
37+
"interactivity": {
38+
"is_enabled": true,
39+
"request_url": "https://1234-56-78-90-0.ngrok-free.app/slack/events"
40+
},
41+
"org_deploy_enabled": true,
42+
"socket_mode_enabled": false,
43+
"token_rotation_enabled": false
44+
}
45+
}

0 commit comments

Comments
 (0)