Skip to content

feat: add --no-auth flag to api command for unauthenticated requests#566

Open
WilliamBergamin wants to merge 2 commits into
mainfrom
no-auth-for-api-command
Open

feat: add --no-auth flag to api command for unauthenticated requests#566
WilliamBergamin wants to merge 2 commits into
mainfrom
no-auth-for-api-command

Conversation

@WilliamBergamin
Copy link
Copy Markdown
Contributor

@WilliamBergamin WilliamBergamin commented May 29, 2026

Changelog

Allow the api command to send unauthenticated requests when no token is available or when --no-auth is specified.

Summary

Some Slack API methods (e.g. api.test, blocks.validate) don't require authentication. Previously, the api command always resolved a token and failed with an error if none was available, even when calling methods that don't need one.

This PR makes two changes:

  1. Graceful fallback: if no token is found through any resolution path (flags, env vars, app prompt), the request is sent without authentication instead of erroring.
  2. --no-auth flag: skips token resolution entirely. Useful in scripts or CI where you want to avoid interactive prompts and explicitly signal that no auth is needed.

The app selection prompt (shown in project directories) now includes a "No app" option, allowing users to opt out of authentication interactively.

--no-auth cannot be combined with --token or --app flags.

Preview

Screenshot 2026-06-01 at 4 01 26 PM
Screenshot 2026-06-01 at 4 00 50 PM

Testing

# Explicit no-auth
slack api blocks.validate --no-auth blocks='[{"type":"section","text":{"type":"mrkdwn","text":"Hello"}}]'
slack api api.test --no-auth

# Graceful fallback (no token configured, no project)
slack api api.test

Notes

None

Requirements

@WilliamBergamin WilliamBergamin added this to the Next Release milestone May 29, 2026
@WilliamBergamin WilliamBergamin self-assigned this May 29, 2026
@WilliamBergamin WilliamBergamin requested a review from a team as a code owner May 29, 2026 17:40
@WilliamBergamin WilliamBergamin added enhancement M-T: A feature request for new functionality semver:minor Use on pull requests to describe the release version increment labels May 29, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

❌ Patch coverage is 65.78947% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.67%. Comparing base (c693443) to head (df1e736).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/prompts/app_select.go 30.76% 7 Missing and 2 partials ⚠️
cmd/api/api.go 84.00% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #566      +/-   ##
==========================================
+ Coverage   71.66%   71.67%   +0.01%     
==========================================
  Files         226      226              
  Lines       19115    19140      +25     
==========================================
+ Hits        13699    13719      +20     
- Misses       4209     4215       +6     
+ Partials     1207     1206       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Member

@zimeg zimeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WilliamBergamin Super nice unlocks this is bringing 🔓 ✨

I'm leaving a comment on an adjacent approach we can consider? Not against having --no-auth also but think it could pair with a new app select prompt option "no app" within projects 🎲 so details on this flag or methods needing it isn't needed in scripts otherwise 👾

Comment thread cmd/api/api.go Outdated
Comment on lines 288 to 290
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return "", nil

🔮 thought: We might want to accept no token as valid input without requiring to know which flag is needed. I realize multiple cases exist for gathering tokens and we could use --help outputs toward this. The API response I think is meaningful too:

{
    "ok": false,
    "error": "not_authed"
}

🌛 suggestion: Might adding a "no app" option to app selection perhaps support having a --no-auth flag?

  Select an app
    A0B78JUQG4U devrelsandbox T02A074M3U3
    A0B78KLUSFN tinyspek E06LPMFSSTU
+ ❱ No app

🐮 ramble: In scripts a missing --token flag might have similar results and I hope the earlier error and documentation has details toward remediation!

@WilliamBergamin
Copy link
Copy Markdown
Contributor Author

@zimeg thanks for this awesome feedback 💯

I opted to add the "No app" option to the app selection prompt to allow users to submit a request without an app token 🚀 But I think we need to keep some sort of --no-auth flag to allow scripts and CI to bypass authentication if they need to 🤔

I did think of renaming it to --no-app, but this feels weird because the logic truly just bypasses the token resolution.

@WilliamBergamin WilliamBergamin requested a review from zimeg June 1, 2026 20:09
Copy link
Copy Markdown
Member

@zimeg zimeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WilliamBergamin Clean implementation! This puts things in great direction for building configurations of a selection! Thanks for improving this alongside feedback suggestions 🧰 ✨

Comment on lines +94 to +95
// ErrNoAppSelected is returned when the user selects "No app" in the prompt
var ErrNoAppSelected = fmt.Errorf("no app selected")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚧 suggestion: Can we import this from errors.go instead?

Comment on lines +97 to +102
// AppSelectOption configures optional behavior of AppSelectPrompt
type AppSelectOption func(*appSelectConfig)

type appSelectConfig struct {
includeNoApp bool
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌟 praise: Excited for what this pattern unlocks in customizations!

@zimeg zimeg added the changelog Use on updates to be included in the release notes label Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog Use on updates to be included in the release notes enhancement M-T: A feature request for new functionality semver:minor Use on pull requests to describe the release version increment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants