Add slack user level authentication#32
Open
ajinkyasraj wants to merge 6 commits into
Open
Conversation
Slack connections can now authenticate as the installing human (xoxp- user token, auth_kind=user_token) in addition to the existing bot identity (xoxb-, auth_kind=oauth|token). A user connection carries that person's full permissions and unblocks search_messages, which Slack's search.messages API only accepts with a user token. - config.go: KindUserToken constant, UserToken field, validate + accessToken branches (require xoxp-/xoxe. prefix). - ops.go: search_messages runs for real on user-token connections with page->cursor pagination; bot connections still return the typed ErrOperationNotEnabled sentinel. - slack.go: declare the user_token setup field so the registry architecture invariant stays satisfied. - mockslack: serve search.messages for user tokens (xoxp-/xoxe.) and keep the not_allowed_token_type rejection for bot tokens. - tests: user-token validate/parse/accessToken cases and end-to-end search (incl. pagination) against the mock.
Expose the user-token identity in the admin UI alongside the existing bot install paths (no bot functionality removed). - Two new routes: POST /connections/slack/oauth/user/start (OAuth install requesting user_scope incl. search:read) and POST /connections/slack/user-token (paste an xoxp- User OAuth Token). - slackOAuthExchange detects a user install by the presence of authed_user.access_token in the oauth.v2.access response and persists auth_kind=user_token; the bot path is otherwise unchanged. - Reauth supports re-pasting a user token and re-running the matching OAuth identity (reads the stored auth_kind). - connections.html: "Install via OAuth (as user)" button and "Add via user token" form on the Slack card. - tests: user-token paste happy/bad-prefix, user OAuth callback, a regression test asserting the bot OAuth path still yields auth_kind= oauth, and card-render checks for the new forms.
- connectors-slack.md: "Two identities" section, two new install options (user OAuth + user-token paste), revised search_messages and limitations notes, bot-vs-user guidance. - connections-guide.md: bot-vs-user quick reference and updated search caveat. - CLAUDE.md: update the Slack specifics note (auth_kind identities, search gating, the four web install routes, callback discrimination).
bot_token was declared Required but not Secret. On the generic edit
form, a Required non-secret field rejects an empty submission ("Bot
token is required"), so editing any Slack connection forced the operator
to re-enter the bot token — and a user_token connection (which has no
bot token) could not be saved at all.
A bot token is a secret credential and should be declared as one:
Secret=true makes an empty edit submission mean "keep stored" and stops
the value from being echoed back into the form. Create still requires it
(unaffected; Slack create is a bespoke flow anyway).
Tests: a user connection now round-trips through the edit form with both
secrets left blank, and the user-token install path rejects agent
bearer tokens (parity with the bot-token path).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a user-identity option to the Slack connector
Slack connections can now authenticate as the installing human (a
xoxp-user token), in addition to the existing bot identity (xoxb-). This is additive — no bot functionality is removed; a connection simply picks one of two identities viaauth_kind.Why
A bot token only sees channels the app's bot user is invited to and cannot use Slack's
search.messagesAPI (Slack rejects bot tokens there). Some agent workflows need a human's full reach — every channel/DM the person can see, plus workspace search. A user-token connection provides that, scoped by a Sieve role + policy.Identity model
auth_kindoauth/tokenxoxb-…user_tokenxoxp-…search_messagesBoth identities expose the same curated operation set; they differ in reach and attribution. Bot remains the least-privilege default.
What changed
Connector (
internal/connectors/slack)config.go: newKindUserTokenconstant +UserTokenfield;validate()/accessToken()branch on the kind (user kind requires anxoxp-/xoxe.prefix).ops.go:search_messagesnow runs for real on user-token connections (with page→cursor pagination); bot connections still return the typedconnector.ErrOperationNotEnabledsentinel (→ HTTP 501 on REST,operation_not_enabled:tool error on MCP).slack.go: declares theuser_tokensetup field so the registry architecture invariant stays satisfied.Admin UI / web (
internal/web)POST /connections/slack/oauth/user/start(OAuth install requestinguser_scope, incl.search:read) andPOST /connections/slack/user-token(paste axoxp-User OAuth Token).slackOAuthExchangedistinguishes a user install from a bot install by the presence ofauthed_user.access_tokenin theoauth.v2.accessresponse — no side-channel flag.auth_kind).connections.html: "Install via OAuth (as user)" button and "Add via user token" form on the Slack card, alongside the existing bot options.Test mock (
internal/testing/mockslack)search.messagesfor user tokens (xoxp-/xoxe.) and keeps thenot_allowed_token_typerejection for bot tokens.Docs
docs/connectors-slack.md,docs/connections-guide.md, and theCLAUDE.mdSlack note updated for the bot-vs-user choice, the four install paths, and the revisedsearch_messagesbehavior.Testing
go build ./...clean.go test ./internal/connectors/slack/ ./internal/web/ ./cmd/sieve/all pass, including:accessTokencases and end-to-endsearch_messages(incl. pagination) against the mock;auth_kind=user_token;auth_kind=oauth;user_tokendeclared onMeta()).Backward compatibility
Fully backward compatible. Existing bot connections (
auth_kindoauth/token) are untouched; all existing Slack install/paste/reauth flows behave as before.