bcli supports three Business Central online authentication methods:
| Method | Flow | Use case |
|---|---|---|
browser |
Authorization code with PKCE | Default for local humans and AI agents |
client_credentials |
App permissions | CI/CD, servers, scheduled jobs |
device_code |
Delegated device code | SSH/headless fallback |
For a full zero-knowledge Entra ID and Business Central setup, start with Business Central Admin Setup.
Browser auth is the default for bcli config init. It opens the user's browser,
uses PKCE, needs no client secret, and Business Central enforces the signed-in
user's permission sets.
bcli config init
bcli auth login
bcli get customers --top 5The Entra app registration must be a public/native client with delegated Business Central permissions and a localhost redirect URI. See Business Central Admin Setup for the portal steps.
Useful login options:
# Fresh browser session, useful when switching accounts
bcli auth login --method browser --incognito
# Explicit browser profile setup
bcli config init --auth browserUse client credentials only for automation: CI/CD, background jobs, servers, and scheduled exports. This path uses application permissions and a client secret, so it should be set up deliberately.
bcli config init --automation
bcli auth store-secret
bcli get customers --top 5bcli never stores client secrets in config files. It resolves secrets in this order:
- OS keychain: macOS Keychain, Windows Credential Manager, or equivalent.
- The configured
client_secret_envenvironment variable. - Generic fallback env vars:
BCLI_SECRETorBCLI_CLIENT_SECRET.
In CI, use environment variables:
env:
BCLI_SECRET: ${{ secrets.BC_CLIENT_SECRET }}
steps:
- run: bcli get customers --top 1 -f json -qNo bcli auth login is required when a valid secret is available; bcli acquires
tokens automatically.
Device code is a fallback for hosts where a localhost browser callback is not practical, such as SSH sessions or locked-down remote machines.
bcli config init --headless
bcli auth login --method deviceThe terminal prints a URL and code. Open the URL in any browser, enter the code, and bcli caches the resulting delegated token.
After authentication, bcli caches access tokens at
~/.config/bcli/tokens.json. Tokens are reused until shortly before expiry.
bcli auth status
bcli auth logout| Symptom | Likely cause | Fix |
|---|---|---|
| Redirect URI mismatch | Entra app lacks localhost redirect URI | Add http://localhost as a mobile/desktop redirect URI |
| Consent required | Tenant admin has not granted API consent | Grant admin consent for Business Central delegated permissions |
| 403 Forbidden | User lacks BC permission set for that page/company | Assign the user the required Business Central permissions |
| Wrong tenant/account | Browser reused an existing Microsoft session | Re-run with --incognito |
| Secret missing | Automation profile cannot find BCLI_SECRET or keychain secret |
Run bcli auth store-secret or set the env var |