Skip to content

fix: always prompt for token in auth init#1870

Open
lazydiv wants to merge 1 commit into
digitalocean:mainfrom
lazydiv:fix/auth-init-always-prompt
Open

fix: always prompt for token in auth init#1870
lazydiv wants to merge 1 commit into
digitalocean:mainfrom
lazydiv:fix/auth-init-always-prompt

Conversation

@lazydiv

@lazydiv lazydiv commented Jul 4, 2026

Copy link
Copy Markdown

Summary

  • doctl auth init now always prompts the user for a new token, even when one already exists in the config
  • Previously, if an expired/revoked token was saved, auth init would immediately fail with a 401 error without giving the user a chance to enter a new token
  • Tokens passed via the --access-token flag are still respected without prompting

Motivation

When a saved token expires or is revoked, running doctl auth init (the command specifically meant to set up authentication) would error out instantly. Users had no way to re-authenticate without manually editing ~/.config/doctl/config.yaml.

Test plan

  • TestAuthInit — basic flow with no existing token
  • TestAuthInitWithProvidedToken--access-token flag skips prompt
  • TestAuthInitPromptsWhenTokenExists — new test for the fix (prompts even when old token exists)
  • TestAuthForcesLowercase — context handling still works
  • All existing auth tests pass (go test ./commands/ -run TestAuth)

Previously, `auth init` would skip the token prompt if an existing token
was found in the config, and instead immediately validate the old token.
If that token was expired or revoked, the user received a 401 error with
no opportunity to enter a new one.

Now `auth init` always prompts for a new token (its intended purpose),
unless a token is explicitly provided via the `--access-token` flag.
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