Integrations3 min read
Slack OAuth Setup
OAuth setup steps for the Slack integration
Slack OAuth Integration Setup
Overview
The Slack integration supports two methods:
- OAuth Integration (Recommended): Connect Slack workspace via OAuth for full API access
- Webhook (Legacy): Use incoming webhooks (limited functionality)
OAuth Setup Steps
1. Create Slack App
- Go to https://api.slack.com/apps
- Click "Create New App" → "From scratch"
- Name your app (e.g., "OpsKnight") and select your workspace
- Click "Create App"
2. Configure OAuth & Permissions
-
In your app settings, go to OAuth & Permissions
-
Under Redirect URLs, add:
https://yourdomain.com/api/slack/oauth/callback http://localhost:3000/api/slack/oauth/callback (for development) -
Under Scopes → Bot Token Scopes, add:
chat:write- Send messageschannels:read- List channelsgroups:read- List private channelsim:read- List DMsmpim:read- List group DMsusers:read- Read user information
-
Under Scopes → User Token Scopes (optional):
- No user scopes needed for basic functionality
3. Install App to Workspace
- Go to OAuth & Permissions page
- Click Install to Workspace
- Review permissions and click Allow
- Copy the Bot User OAuth Token (starts with
xoxb-)
4. Get Signing Secret
- Go to Basic Information in your app settings
- Under App Credentials, find Signing Secret
- Click Show and copy the secret
5. Configure Environment Variables
Add to your .env file:
# Slack OAuth Configuration
SLACK_CLIENT_ID=your_client_id_here
SLACK_CLIENT_SECRET=your_client_secret_here
SLACK_REDIRECT_URI=https://yourdomain.com/api/slack/oauth/callback
# Optional: Encryption key for token storage (generate with: openssl rand -hex 32)
ENCRYPTION_KEY=your_32_byte_hex_key_here
# Optional: Legacy webhook URL (fallback if OAuth not configured)
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR/WEBHOOK/URL
# Optional: Legacy bot token (fallback if OAuth not configured)
SLACK_BOT_TOKEN=xoxb-your-bot-token-here
# Optional: Signing secret for interactive components
SLACK_SIGNING_SECRET=your_signing_secret_here
6. Generate Encryption Key
For production, generate a secure encryption key:
openssl rand -hex 32
Add this to your ENCRYPTION_KEY environment variable.
Usage
Connect Slack to Service
- Go to Service Settings → Notifications
- Click "Connect Slack Workspace"
- Authorize the app in Slack
- Select a channel for notifications
- Save settings
Connect Slack Globally
- Go to Settings → Integrations
- Click "Connect Slack Workspace"
- Authorize the app
- This becomes the default Slack integration
How It Works
- OAuth Flow: User clicks "Connect Slack" → Redirected to Slack → Authorizes → Callback stores encrypted token
- Token Storage: Bot tokens are encrypted and stored in
SlackIntegrationtable - Service-Specific: Each service can have its own Slack workspace connection
- Global Fallback: If no service-specific integration, uses global integration
- Env Fallback: If no OAuth integration, falls back to
SLACK_BOT_TOKENenv var
Security
- Bot tokens are encrypted using AES-256-CBC before storage
- Encryption key should be stored securely (env var, secret manager)
- Tokens are decrypted only when needed for API calls
- Never log or expose decrypted tokens
Troubleshooting
"Slack bot token not configured"
- Ensure OAuth integration is connected
- Or set
SLACK_BOT_TOKENenvironment variable - Check that integration is enabled
"Failed to decrypt token"
- Ensure
ENCRYPTION_KEYis set correctly - Key must be same across all instances
- If changed, re-connect Slack integrations
"Invalid OAuth state"
- OAuth state expired (10 minutes)
- Try connecting again
- Clear cookies if issue persists
Endpoints
GET /api/slack/oauth- Initiate OAuth flowGET /api/slack/oauth/callback- OAuth callback handlerGET /api/slack/channels- List available channelsPOST /api/slack/actions- Handle interactive button clicksDELETE /api/slack/disconnect- Disconnect integration
Last updated for v1
Edit this page on GitHub