Auth Commands
Manage authentication with Bitbucket.
Global options available on all auth commands: --json [fields], --jq <expression>, --no-color, --no-unicode, --locale <locale>. See Global flags for the full list.
bb auth login
Section titled “bb auth login”Authenticate with Bitbucket using OAuth (default) or an API token.
bb auth login [options]Options
Section titled “Options”| Option | Description |
|---|---|
-u, --username <username> |
Bitbucket username (implies API token auth) |
-p, --password <password> |
Bitbucket API token (implies API token auth) |
--with-token |
Read the API token from stdin so it never appears in shell history or process args (implies API token auth) |
--app-password |
Use API token authentication instead of OAuth (see the note below) |
--client-id <clientId> |
Custom OAuth consumer client ID |
--client-secret <clientSecret> |
Custom OAuth consumer client secret |
Examples
Section titled “Examples”# Login with OAuth (opens browser)bb auth login
# Login with a custom OAuth consumerbb auth login --client-id YOUR_KEY --client-secret YOUR_SECRET
# Login with API tokenbb auth login -u myuser -p your-api-token
# Login by piping the token via stdin (keeps it out of shell history and `ps`)echo "$BB_API_TOKEN" | bb auth login -u myuser --with-token
# Login using environment variables (API token)export BB_USERNAME=myuserexport BB_API_TOKEN=your-api-tokenbb auth loginHow it works
Section titled “How it works”OAuth is used unless any of --app-password, --with-token, -u, -p, or the BB_API_TOKEN environment variable is present.
OAuth flow (default):
- The CLI starts a local callback server and opens your browser
- You authorize the CLI on Bitbucket’s consent screen
- Bitbucket redirects back to the CLI with an authorization code
- The CLI exchanges the code for access and refresh tokens
- Tokens are stored in your config file
- Access tokens expire after 2 hours and are refreshed automatically
API token flow:
- You provide your Bitbucket username and API token (token via
-p, piped to stdin with--with-token, or theBB_API_TOKENenvironment variable) - The CLI stores the credentials in your config file
- The CLI verifies the credentials by fetching your user information
- If verification fails, credentials are not saved
Required scopes (API token)
Section titled “Required scopes (API token)”bb auth login and bb auth status need read:user:bitbucket to verify your identity, and so does bb pr list --mine (it resolves your account UUID).
Repository and pull request commands need read:repository:bitbucket and read:pullrequest:bitbucket, plus the matching write: scopes to create, edit, merge, approve, or decline. Creating a repository needs the admin scope (legacy repository:admin) and deleting one needs the delete scope (legacy repository:delete); Atlassian publishes these as admin:repository:bitbucket and delete:repository:bitbucket.
Everything else — pipelines, snippets, projects — needs its own scope. See Token scopes for the per-command table.
OAuth logins request a fixed scope set: account repository repository:admin pullrequest pullrequest:write. Commands outside repositories and pull requests (bb pipeline, bb snippet, bb project) are not covered, and neither is bb repo delete. Use an API token with the matching scopes for those.
See the Authentication guide for setup instructions.
bb auth logout
Section titled “bb auth logout”Log out of Bitbucket and remove stored credentials.
bb auth logout [options]Examples
Section titled “Examples”bb auth logout
# Machine-readable resultbb auth logout --jsonWhat gets removed
Section titled “What gets removed”- OAuth: Revokes the token on Bitbucket’s side, then removes
oauthAccessToken,oauthRefreshToken,oauthExpiresAt,authMethod, and custom OAuth consumer credentials from the config file. - API Token: Removes
usernameandapiTokenfrom the config file.
Other settings like defaultWorkspace, skipVersionCheck, and versionCheckInterval are preserved.
If revocation fails, the CLI still clears local credentials and warns you to revoke the token manually (revokeFailed: true in --json).
bb auth status
Section titled “bb auth status”Show current authentication status and account information.
bb auth status [options]Examples
Section titled “Examples”# Check authentication statusbb auth status
# Get status as JSONbb auth status --jsonOutput
Section titled “Output”When authenticated with OAuth:
✓ Logged in to Bitbucket Authentication: OAuth Username: myuser Display name: My Name Account ID: 712020:3cfed7e0-0ed6-49fc-bb35-410a00ccee6f Token expires: in 1h 42m Default workspace: myworkspaceWhen authenticated with API token:
✓ Logged in to Bitbucket Authentication: API Token Username: myuser Display name: My Name Account ID: 712020:3cfed7e0-0ed6-49fc-bb35-410a00ccee6f Default workspace: myworkspaceThe Default workspace: line appears only when defaultWorkspace is set. On an OAuth login with a stale token, Token expires: reads expired (will refresh automatically).
When not authenticated:
ℹ Not logged inRun bb auth login to authenticate.bb auth token
Section titled “bb auth token”Print the current access token.
bb auth token [options]Examples
Section titled “Examples”# Print the tokenbb auth token
# Copy it to the clipboardbb auth token | pbcopy
# Use it against the raw API (OAuth login — bearer token)curl -H "Authorization: Bearer $(bb auth token)" https://api.bitbucket.org/2.0/user
# Use it against the raw API (API token login — base64 basic credentials)curl -H "Authorization: Basic $(bb auth token)" https://api.bitbucket.org/2.0/user
# Get token as JSONbb auth token --jsonOutput
Section titled “Output”- OAuth: Prints the bearer access token (automatically refreshes if expired).
--jsonreportstype: "bearer". - API Token: Prints a base64-encoded
username:apiTokenstring suitable for HTTP Basic auth headers.--jsonreportstype: "basic".