Skip to content

fix: prefer env var over keychain for API token resolution#118

Merged
piekstra merged 1 commit intomainfrom
piekstra/fix-env-var-token-precedence
Feb 20, 2026
Merged

fix: prefer env var over keychain for API token resolution#118
piekstra merged 1 commit intomainfrom
piekstra/fix-env-var-token-precedence

Conversation

@piekstra
Copy link
Collaborator

Summary

  • GetAPIToken() now checks SLACK_API_TOKEN env var before keychain, matching how GetUserToken() already works
  • GetTokenSource() updated to reflect the same precedence
  • No behavior change when env var is not set — falls back to keychain as before

Why

Automation tools (like daemons) inject tokens via SLACK_API_TOKEN env var, but GetAPIToken() checked keychain first and never reached the env var fallback. This made it impossible for subprocess-based tools to use their own bot tokens when the user also had a personal token stored in keychain.

GetUserToken() already had the correct precedence (env var first), so this aligns the two functions.

Test plan

  • SLACK_API_TOKEN=xoxb-test slck config show shows "from environment variable" for bot token
  • Without env var set, slck config show still shows keychain token
  • slck whoami works with both env var and keychain tokens

GetAPIToken() now checks SLACK_API_TOKEN env var before keychain,
matching GetUserToken() behavior. This allows automation tools to
inject their own tokens via env vars without conflicting with
locally stored keychain credentials.
@piekstra piekstra merged commit 4e13edd into main Feb 20, 2026
2 checks passed
@piekstra piekstra deleted the piekstra/fix-env-var-token-precedence branch February 20, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant