Slack OAuth credentials are baked into the build at compile time. For custom builds, you’ll need to create your own Slack app and set environment variables.
Overview
Craft Agents integrates with Slack using OAuth 2.0 for user authentication (not bot installation). This allows the agent to post messages as you, read channels, and access workspace data. Key Features:- Post messages as the authenticated user
- Read channel history and messages
- Access direct messages and group chats
- Search workspace content
- Read and write files
- React to messages
Prerequisites
- A Slack workspace (free or paid)
- Admin access to create Slack apps (or use the built-in credentials)
- HTTPS redirect URI (uses Cloudflare Worker relay)
Using Built-In Credentials
If you’re using the official Craft Agents build, OAuth credentials are already configured. Simply:- Tell the agent:
Connect to my Slack workspace - Click the OAuth link when prompted
- Authorize the app in your browser
- Return to Craft Agent
Custom Slack App Setup
Create a Slack App
- Go to Slack API: Your Apps
- Click Create New App
- Choose From scratch
- App Name: e.g., “Craft Agent”
- Workspace: Select your development workspace
- Click Create App
Configure OAuth Settings
- In your app settings, go to OAuth & Permissions
- Scroll to Redirect URLs
- Click Add New Redirect URL
- Enter:
https://agents.craft.do/auth/slack/callback- This Cloudflare Worker relay redirects to
http://localhost:{port}/callback
- This Cloudflare Worker relay redirects to
- Click Add
- Click Save URLs
Slack requires HTTPS for OAuth redirects. The relay at
agents.craft.do forwards the callback to your local machine.Add User Scopes
Still in OAuth & Permissions, scroll to Scopes → User Token Scopes:For full workspace access, add these scopes:
Get OAuth Credentials
- Go to Basic Information
- Scroll to App Credentials
- Copy your Client ID
- Click Show next to Client Secret and copy it
Set Environment Variables
Add these to your
.env file (in the project root):.env
These credentials are baked into the build at compile time using environment variables.
OAuth Flow
Initiate Authentication
Tell the agent:The agent opens your browser to the Slack authorization page.
Scope Sets by Service
Craft Agent provides predefined scope sets:Messaging (service: 'messaging')
Messaging (service: 'messaging')
Channels (service: 'channels')
Channels (service: 'channels')
Users (service: 'users')
Users (service: 'users')
Files (service: 'files')
Files (service: 'files')
Full Workspace (service: 'full')
Full Workspace (service: 'full')
Token Types
Token Refresh
Slack supports token rotation if enabled in your app settings:- Go to OAuth & Permissions in Slack App settings
- Enable Token Rotation
- Access tokens expire after configured duration
- Craft Agent automatically refreshes using the refresh token
If token rotation is not enabled, your access token never expires (but can be manually revoked).
Security
- Encrypted storage: Tokens stored in
~/.craft-agent/credentials.enc(AES-256-GCM) - HTTPS required: OAuth callbacks use HTTPS via relay
- CSRF protection: State parameter prevents cross-site attacks
- Scope minimization: Only request scopes you need
Troubleshooting
Error: Slack OAuth not configured
Error: Slack OAuth not configured
Client ID or Client Secret is missing:
- Verify environment variables are set:
SLACK_OAUTH_CLIENT_IDandSLACK_OAUTH_CLIENT_SECRET - Rebuild Craft Agents after setting env vars
- Check
.envfile is in the project root
Error: OAuth state mismatch
Error: OAuth state mismatch
CSRF protection triggered. Possible causes:
- Multiple OAuth flows running simultaneously
- Browser cache issues
- Proxy modifying requests
Error: No user access token received
Error: No user access token received
Your Slack app is requesting bot scopes instead of user scopes:
- Go to OAuth & Permissions in Slack App settings
- Verify scopes are under User Token Scopes, not Bot Token Scopes
- Remove any bot scopes
- Re-authenticate
Redirect URI mismatch
Redirect URI mismatch
The redirect URI in your Slack app doesn’t match:
- Go to OAuth & Permissions → Redirect URLs
- Ensure
https://agents.craft.do/auth/slack/callbackis listed - Click Save URLs
- Try again
Token refresh fails
Token refresh fails
Token rotation might not be enabled:
- Check OAuth & Permissions → Token Rotation
- Enable if you want automatic token refresh
- Re-authenticate to get a refresh token
Source Configuration
Exampleconfig.json for a Slack source:
teamId, teamName, and userId are populated automatically during OAuth.