Slack apps use several token types identified by prefix: bot tokens (xoxb-), user tokens (xoxp-) and app-level tokens (xapp-). Bot and user tokens do not expire unless you opt into token rotation, which makes access tokens last 12 hours and refresh tokens single-use.
Slack key types
| Type | Prefix | Secret? | Scope | Expiry |
|---|---|---|---|---|
| Bot token | xoxb- | Yes | Acts as the app's bot user, limited to the bot scopes granted at install | No default expiry; optional token rotation gives 12-hour access tokens |
| User token | xoxp- | Yes | Acts on behalf of a workspace member, including the installer, limited to granted user scopes | No default expiry; optional token rotation gives 12-hour access tokens |
| App-level token The opt-in rotating variant uses the prefix xoxe.xapp-, with access tokens that expire after 12 hours and single-use refresh tokens. | xapp- | Yes | Represents the app across organizations, for example for Socket Mode | Does not expire by default |
| Workflow token | xwfp- | Yes | A just-in-time subset of bot tokens that cannot perform user-scoped actions | Expires 15 minutes after issue, or when the function step completes or errors; cannot be refreshed |
How to create a Slack key
- Create or open your app in the Slack app management console at
api.slack.com/apps. - Add the scopes your app needs, then install it to the workspace.
- Copy the issued bot or user token from the app's settings.
Limiting what the key can do
A token can only do what its granted OAuth scopes allow. Request the narrowest bot scopes at install, and prefer a bot token over a user token so the app does not act as a person. The official Slack MCP server requires user-token scopes per tool (for example chat:write).
How to rotate a Slack key
- Enable token rotation for the app, then exchange the existing long-lived token once with
oauth.v2.exchange. - Refresh before the 12-hour expiry by calling
oauth.v2.accesswithgrant_type=refresh_token; each response returns a new access and refresh token. - Save the new refresh token every time; each one is single-use.
- Call
auth.revokeon the old access token to invalidate it immediately.
Refreshing does not immediately invalidate the previous access token. Only two active tokens are kept if you refresh repeatedly within 12 hours. Token rotation is opt-in and cannot be turned off once on.
How to revoke a Slack key
- Call
auth.revokewith the token. For a bot token this deactivates the bot user and removes its channel memberships but does not uninstall the app. - To get a new bot token, run the OAuth install flow again; single-workspace apps can read the new token in the app management console.
apps.uninstallremoves the app and revokes all tokens for the installation.
If your Slack key leaked
- Revoke the token with
auth.revoke, or uninstall the app withapps.uninstall. - Reinstall or re-run OAuth to obtain a new token, then update every deployment.
- Review the app's recent actions in the workspace.
Environment variables and CLI
Slack CLI (slack)
Things that catch people out
- Bot tokens never expire unless you enable token rotation, so a leaked token stays valid until revoked.
auth.revokeon a bot token deactivates the bot user; it does not uninstall the app.- The Slack MCP server uses OAuth with a registered app; only directory-published or internal apps can use it.
- Org-wide apps must be removed by an org admin in the admin console.
Common Slack authentication errors
invalid_auth
The credentials are invalid, the token cannot be validated, or the request came from a disallowed IP address.
not_authed
The request did not include an authentication token.
token_revoked
For a user token, the user or workspace was deleted or the app was removed.
Recent incidents that put Slack keys at risk
If you were affected by one of these, rotate your Slack keys using the rotation steps above.
- GhostAction returns: fake security workflows pushed to 30,000+ repos to steal Actions secrets 2026-10-07
Using your Slack key with AI agents
A coding agent that can read your .env file or your shell history can read the key, and anything in its context can end up in logs, transcripts or a prompt-injected request. The safer pattern is to keep the key in a credential broker that performs the authenticated step for the agent and hands back only the result.
BotPassword works this way. For a Slack key, these intents fit:
| Intent | What BotPassword does |
|---|---|
run_with | Runs a command with the key injected as an environment variable or a 0600 temporary file, never on the command line, and redacts the key from the output. |
http_request | Makes an authenticated API call after checking the destination against the hosts this key may be sent to. The response comes back with credential-shaped values redacted, and one that holds the key itself is refused. |
rotate | Partly built: creates a new key, stores it as pending, verifies it, promotes it, then revokes the old key after a grace period. Today it works for Cloudflare tokens and AWS IAM keys you have set up, and an agent can start it only under a grant with autopilot; other providers cannot be rotated through their API yet. |
store_secret | Saves a value the agent already holds as a new vault item. |
capture_secret | Planned, not built yet: will read a newly created key straight from the page or command output into the vault. |
Slack also publishes its own MCP server. Whatever server the agent uses, keep the credential it authenticates with out of the agent's context.
Set it up in your agent: Aider · Amp · Claude Code · Claude Desktop · Cline · OpenAI Codex CLI · all agents
Frequently asked questions
What is a Slack bot token?
A token starting xoxb- that represents your app's bot user, with the scopes you granted at install.
What is the difference between xoxb and xoxp?
xoxb- acts as the bot user; xoxp- acts on behalf of a workspace member, including the installer.
Do Slack tokens expire?
Not by default. If you opt into token rotation, access tokens expire after 12 hours and are refreshed with single-use refresh tokens.
Can an AI agent use my Slack key without seeing it?
Yes, if the key never enters the agent's context. Instead of pasting the key into a chat or leaving it in a .env file the agent can read, keep it in a credential broker that injects it into the command or request on the agent's behalf. BotPassword does this with run_with, http_request, store_secret, so the agent gets the result and never the value.