feat(wrangler): add wrangler auth token command#11682
Conversation
Add a new command `wrangler auth token` that retrieves the current OAuth token, refreshing it if necessary. This is similar to `gh auth token` in the GitHub CLI and allows users to easily retrieve their authentication token for use with other tools and scripts. Fixes #10095 Co-Authored-By: mkane@cloudflare.com <m@mk.gg>
🦋 Changeset detectedLatest commit: e1e8955 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
Claude finished @ascorbic's task —— View job Changeset Review✅ All changesets look good The changeset file
|
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
Co-Authored-By: mkane@cloudflare.com <m@mk.gg>
Co-Authored-By: mkane@cloudflare.com <m@mk.gg>
Co-Authored-By: mkane@cloudflare.com <m@mk.gg>
ascorbic
left a comment
There was a problem hiding this comment.
Looks good. Tested locally.
|
Thanks for testing and reviewing! The PR is ready for merge whenever you're ready. |
|
(aside) This does need docs. I'll add them if everyone agrees this is the right API |
- Refactor getAuthToken to getOAuthTokenFromLocalState (only handles OAuth) - Rename LocalState to localState throughout user.ts - Add --json flag to return structured output with token type - Support API key/email auth with --json flag - Add JSDoc documentation for auth priority behavior - Update changeset to reflect all auth types - Update tests (24 tests passing) Co-Authored-By: mkane@cloudflare.com <m@mk.gg>
Add documentation for the new `wrangler auth token` command that retrieves authentication credentials for use with other tools and scripts. Documents: - Basic usage - --json flag for structured output with token type - Support for OAuth, API token, and API key/email auth types Related to cloudflare/workers-sdk#11682 Co-Authored-By: mkane@cloudflare.com <m@mk.gg>
Co-Authored-By: mkane@cloudflare.com <m@mk.gg>
|
Ty ❤️ |
* feat(wrangler): add `wrangler auth token` command Add a new command `wrangler auth token` that retrieves the current OAuth token, refreshing it if necessary. This is similar to `gh auth token` in the GitHub CLI and allows users to easily retrieve their authentication token for use with other tools and scripts. Fixes cloudflare#10095 Co-Authored-By: mkane@cloudflare.com <m@mk.gg> * fix: output auth token without preamble and update snapshots Co-Authored-By: mkane@cloudflare.com <m@mk.gg> * fix: use printBanner: false for proper preamble suppression Co-Authored-By: mkane@cloudflare.com <m@mk.gg> * docs: add usage example to changeset per review Co-Authored-By: mkane@cloudflare.com <m@mk.gg> * feat(wrangler): add --json flag and refactor auth token command - Refactor getAuthToken to getOAuthTokenFromLocalState (only handles OAuth) - Rename LocalState to localState throughout user.ts - Add --json flag to return structured output with token type - Support API key/email auth with --json flag - Add JSDoc documentation for auth priority behavior - Update changeset to reflect all auth types - Update tests (24 tests passing) Co-Authored-By: mkane@cloudflare.com <m@mk.gg> * chore: trigger CI re-run for PR description validation Co-Authored-By: mkane@cloudflare.com <m@mk.gg> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
* docs: add wrangler auth token command documentation Add documentation for the new `wrangler auth token` command that retrieves authentication credentials for use with other tools and scripts. Documents: - Basic usage - --json flag for structured output with token type - Support for OAuth, API token, and API key/email auth types Related to cloudflare/workers-sdk#11682 Co-Authored-By: mkane@cloudflare.com <m@mk.gg> * docs: address PR review comments - Remove mention of gh auth token - Change json to jsonc for code block with comments - Fix priority order (API token before OAuth token) Co-Authored-By: mkane@cloudflare.com <m@mk.gg> * docs: add API key/email option to auth methods list Explains that API key/email requires --json flag since it uses two values instead of a single token Co-Authored-By: mkane@cloudflare.com <m@mk.gg> * Update descriptions * docs: add changelog entry for wrangler auth token command Co-Authored-By: mkane@cloudflare.com <m@mk.gg> * docs: add JSON output examples to changelog entry Co-Authored-By: mkane@cloudflare.com <m@mk.gg> * docs: change 'requested' to 'configured' per review Co-Authored-By: mkane@cloudflare.com <m@mk.gg> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Fixes #10095.
Adds a new
wrangler auth tokencommand that retrieves the current authentication credentials for use with other tools and scripts. This is similar togh auth tokenin the GitHub CLI.The command supports all Wrangler authentication methods:
wrangler login(automatically refreshed if expired)CLOUDFLARE_API_TOKENenvironment variableCLOUDFLARE_API_KEY+CLOUDFLARE_EMAIL(requires--jsonflag)Basic usage:
JSON output with token type:
Implementation notes:
printBanner: false--json(no single token to return)LocalStatetolocalStatefor consistencygetOAuthTokenFromLocalState()function that only handles OAuth tokens from local stategetAuthFromEnv()Human Review Checklist:
--jsonoutput format is appropriate for all three auth types--jsonis helpfulauthnamespace is the appropriate location for this commandDevin PR requested by mkane@cloudflare.com
Link to Devin run: https://app.devin.ai/sessions/d407c26dd1da4edf905944a95e90226a
wrangler auth tokencommand documentation cloudflare-docs#27219