Skip to content

Commit 1e84583

Browse files
committed
fix: remove workspace/team prompt and --team flag from slack api
Token resolution now errors if no token is found rather than falling back to a workspace selection prompt. Users must provide a token via --token, --app, or SLACK_BOT_TOKEN/SLACK_USER_TOKEN env vars.
1 parent bd8933d commit 1e84583

2 files changed

Lines changed: 21 additions & 91 deletions

File tree

cmd/api/api.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ func NewCommand(clients *shared.ClientFactory) *cobra.Command {
6262
"",
6363
"Token resolution (in priority order):",
6464
" 1. --token flag Explicit token value",
65-
" 2. --app / --team flags Install app and use bot token (in project)",
65+
" 2. --app flag Install app and use bot token (in project)",
6666
" 3. SLACK_BOT_TOKEN env var Bot token (set during slack deploy)",
6767
" 4. SLACK_USER_TOKEN env var User token",
68-
" 5. Interactive prompt Select from stored workspaces (CLI tooling token)",
68+
" 5. App prompt (in project) Install app and use bot token",
6969
"",
7070
"See all methods at: https://docs.slack.dev/reference/methods",
7171
}, "\n"),
@@ -237,12 +237,9 @@ func resolveToken(ctx context.Context, clients *shared.ClientFactory) (string, e
237237
return token, nil
238238
}
239239

240-
clients.IO.PrintDebug(ctx, "Using CLI tooling token which has limited API scopes. Set SLACK_BOT_TOKEN or use --token for full access.")
241-
auth, err := prompts.PromptTeamSlackAuth(ctx, clients, "Select a workspace")
242-
if err != nil {
243-
return "", err
244-
}
245-
return auth.Token, nil
240+
return "", slackerror.New(slackerror.ErrNotAuthed).
241+
WithMessage("no token found").
242+
WithRemediation("Provide a token with --token, --app, or set SLACK_BOT_TOKEN")
246243
}
247244

248245
func installAndGetBotToken(ctx context.Context, clients *shared.ClientFactory, selected prompts.SelectedApp) (string, error) {

cmd/api/api_test.go

Lines changed: 16 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -322,36 +322,6 @@ func Test_resolveToken_TokenFlag(t *testing.T) {
322322
assert.Equal(t, "xoxb-direct-token", token)
323323
}
324324

325-
func Test_resolveToken_TeamFlag(t *testing.T) {
326-
ctx := slackcontext.MockContext(t.Context())
327-
clientsMock := shared.NewClientsMock()
328-
clientsMock.IO.On("PrintDebug", mock.Anything, mock.Anything, mock.MatchedBy(func(args ...any) bool { return true }))
329-
clientsMock.Config.TeamFlag = "T12345"
330-
clientsMock.Auth.On("Auths", mock.Anything).Return([]types.SlackAuth{
331-
{Token: "xoxb-team-token", TeamID: "T12345", TeamDomain: "myteam"},
332-
}, nil)
333-
clientsMock.Auth.On("SetSelectedAuth", mock.Anything, mock.Anything, mock.Anything, mock.Anything)
334-
clientsMock.IO.On("SelectPrompt", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
335-
Return(iostreams.SelectPromptResponse{Flag: true, Option: "T12345"}, nil)
336-
clients := shared.NewClientFactory(clientsMock.MockClientFactory())
337-
338-
token, err := resolveToken(ctx, clients)
339-
assert.NoError(t, err)
340-
assert.Equal(t, "xoxb-team-token", token)
341-
}
342-
343-
func Test_resolveToken_SingleAuth(t *testing.T) {
344-
ctx := slackcontext.MockContext(t.Context())
345-
clientsMock := shared.NewClientsMock()
346-
clientsMock.IO.On("PrintDebug", mock.Anything, mock.Anything, mock.MatchedBy(func(args ...any) bool { return true }))
347-
clientsMock.Auth.On("Auths", mock.Anything).Return([]types.SlackAuth{{Token: "xoxb-only-token"}}, nil)
348-
clients := shared.NewClientFactory(clientsMock.MockClientFactory())
349-
350-
token, err := resolveToken(ctx, clients)
351-
assert.NoError(t, err)
352-
assert.Equal(t, "xoxb-only-token", token)
353-
}
354-
355325
func Test_resolveToken_EnvBotToken(t *testing.T) {
356326
t.Setenv("SLACK_BOT_TOKEN", "xoxb-env-bot-token")
357327

@@ -376,34 +346,32 @@ func Test_resolveToken_EnvUserToken(t *testing.T) {
376346
assert.Equal(t, "xoxp-env-user-token", token)
377347
}
378348

379-
func Test_resolveToken_TeamOverridesEnv(t *testing.T) {
349+
func Test_resolveToken_AppOverridesEnv(t *testing.T) {
380350
t.Setenv("SLACK_BOT_TOKEN", "xoxb-env-bot-token")
381351

382352
ctx := slackcontext.MockContext(t.Context())
383353
clientsMock := shared.NewClientsMock()
384354
clientsMock.Os.AddDefaultMocks()
385355
clientsMock.IO.On("PrintDebug", mock.Anything, mock.Anything, mock.MatchedBy(func(args ...any) bool { return true }))
386-
clientsMock.Config.TeamFlag = "T12345"
356+
clientsMock.Config.AppFlag = "A111"
387357

388358
clientsMock.Auth.On("Auths", mock.Anything).Return([]types.SlackAuth{
389-
{Token: "xoxp-tooling", TeamID: "T12345", TeamDomain: "myteam"},
359+
{Token: "xoxp-tooling", TeamID: "T111", TeamDomain: "team-a"},
390360
}, nil)
391361
clientsMock.Auth.On("SetSelectedAuth", mock.Anything, mock.Anything, mock.Anything, mock.Anything)
392362

393363
appClientMock := &app.AppClientMock{}
394364
appClientMock.On("GetDeployedAll", mock.Anything).Return([]types.App{
395-
{AppID: "A111", TeamID: "T12345", TeamDomain: "myteam"},
365+
{AppID: "A111", TeamID: "T111", TeamDomain: "team-a"},
396366
}, "", nil)
397367
appClientMock.On("GetLocalAll", mock.Anything).Return([]types.App{}, nil)
398-
appClientMock.On("GetDeployed", mock.Anything, "T12345").Return(types.App{AppID: "A111", TeamID: "T12345", TeamDomain: "myteam"}, nil)
399-
appClientMock.On("GetLocal", mock.Anything, "T12345").Return(types.App{}, nil)
368+
appClientMock.On("GetDeployed", mock.Anything, "T111").Return(types.App{AppID: "A111", TeamID: "T111", TeamDomain: "team-a"}, nil)
369+
appClientMock.On("GetLocal", mock.Anything, "T111").Return(types.App{}, nil)
400370
clientsMock.AppClient.AppClientInterface = appClientMock
401371

402-
clientsMock.API.On("GetAppStatus", mock.Anything, "xoxp-tooling", []string{"A111"}, "T12345").
372+
clientsMock.API.On("GetAppStatus", mock.Anything, "xoxp-tooling", []string{"A111"}, "T111").
403373
Return(internalapi.GetAppStatusResult{Apps: []internalapi.AppStatusResultAppInfo{{AppID: "A111", Installed: true}}}, nil)
404374
clientsMock.API.On("ValidateSession", mock.Anything, mock.Anything).Return(internalapi.AuthSession{}, nil)
405-
clientsMock.IO.On("SelectPrompt", mock.Anything, "Select an app", mock.Anything, mock.Anything).
406-
Return(iostreams.SelectPromptResponse{Index: 0, Prompt: true}, nil)
407375

408376
manifestMock := clientsMock.AppClient.Manifest.(*app.ManifestMockObject)
409377
manifestMock.On("GetManifestLocal", mock.Anything, mock.Anything, mock.Anything).Return(types.SlackYaml{
@@ -417,32 +385,14 @@ func Test_resolveToken_TeamOverridesEnv(t *testing.T) {
417385
Bot string `json:"bot,omitempty"`
418386
AppLevel string `json:"app_level,omitempty"`
419387
User string `json:"user,omitempty"`
420-
}{Bot: "xoxb-team-bot-token"}}, types.InstallSuccess, nil)
388+
}{Bot: "xoxb-app-bot-token"}}, types.InstallSuccess, nil)
421389

422390
clients := shared.NewClientFactory(clientsMock.MockClientFactory())
423391
clients.SDKConfig.WorkingDirectory = "/fake/project"
424392

425393
token, err := resolveToken(ctx, clients)
426394
assert.NoError(t, err)
427-
assert.Equal(t, "xoxb-team-bot-token", token)
428-
}
429-
430-
func Test_resolveToken_MultipleAuths_SelectsViaPrompt(t *testing.T) {
431-
ctx := slackcontext.MockContext(t.Context())
432-
clientsMock := shared.NewClientsMock()
433-
clientsMock.IO.On("PrintDebug", mock.Anything, mock.Anything, mock.MatchedBy(func(args ...any) bool { return true }))
434-
clientsMock.Auth.On("Auths", mock.Anything).Return([]types.SlackAuth{
435-
{Token: "xoxb-token-1", TeamDomain: "team-a", TeamID: "T111"},
436-
{Token: "xoxb-token-2", TeamDomain: "team-b", TeamID: "T222"},
437-
}, nil)
438-
clientsMock.Auth.On("SetSelectedAuth", mock.Anything, mock.Anything, mock.Anything, mock.Anything)
439-
clientsMock.IO.On("SelectPrompt", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
440-
Return(iostreams.SelectPromptResponse{Index: 0, Prompt: true}, nil)
441-
clients := shared.NewClientFactory(clientsMock.MockClientFactory())
442-
443-
token, err := resolveToken(ctx, clients)
444-
assert.NoError(t, err)
445-
assert.Equal(t, "xoxb-token-1", token)
395+
assert.Equal(t, "xoxb-app-bot-token", token)
446396
}
447397

448398
func Test_resolveToken_AppFlag_ByID(t *testing.T) {
@@ -567,10 +517,9 @@ func Test_resolveToken_AppFlag_NotFound(t *testing.T) {
567517
clients := shared.NewClientFactory(clientsMock.MockClientFactory())
568518
clients.SDKConfig.WorkingDirectory = "/fake/project"
569519

570-
// AppSelectPrompt returns ErrAppNotFound for A999, resolveToken falls through to team prompt
571-
token, err := resolveToken(ctx, clients)
572-
assert.NoError(t, err)
573-
assert.Equal(t, "xoxp-tooling", token)
520+
_, err := resolveToken(ctx, clients)
521+
assert.Error(t, err)
522+
assert.Contains(t, err.Error(), "no token found")
574523
}
575524

576525
func Test_resolveToken_AppSelection(t *testing.T) {
@@ -622,28 +571,12 @@ func Test_resolveToken_AppSelection(t *testing.T) {
622571
assert.Equal(t, "xoxb-app-bot-token", token)
623572
}
624573

625-
func Test_resolveToken_AppSelection_FallsThrough(t *testing.T) {
574+
func Test_resolveToken_NoTokenFound(t *testing.T) {
626575
ctx := slackcontext.MockContext(t.Context())
627576
clientsMock := shared.NewClientsMock()
628-
clientsMock.Os.AddDefaultMocks()
629-
clientsMock.IO.On("PrintDebug", mock.Anything, mock.Anything, mock.MatchedBy(func(args ...any) bool { return true }))
630-
631-
clientsMock.Auth.On("Auths", mock.Anything).Return([]types.SlackAuth{
632-
{Token: "xoxp-tooling", TeamID: "T111", TeamDomain: "team-a"},
633-
}, nil)
634-
635-
appClientMock := &app.AppClientMock{}
636-
appClientMock.On("GetDeployedAll", mock.Anything).Return([]types.App{}, "", nil)
637-
appClientMock.On("GetLocalAll", mock.Anything).Return([]types.App{}, nil)
638-
appClientMock.On("GetDeployed", mock.Anything, "T111").Return(types.App{}, nil)
639-
appClientMock.On("GetLocal", mock.Anything, "T111").Return(types.App{}, nil)
640-
clientsMock.AppClient.AppClientInterface = appClientMock
641-
642577
clients := shared.NewClientFactory(clientsMock.MockClientFactory())
643-
clients.SDKConfig.WorkingDirectory = "/fake/project"
644578

645-
// No installed apps found, AppSelectPrompt returns ErrInstallationRequired, falls through to team prompt
646-
token, err := resolveToken(ctx, clients)
647-
assert.NoError(t, err)
648-
assert.Equal(t, "xoxp-tooling", token)
579+
_, err := resolveToken(ctx, clients)
580+
assert.Error(t, err)
581+
assert.Contains(t, err.Error(), "no token found")
649582
}

0 commit comments

Comments
 (0)