This skill guides you on how to use contract-cli 's login and identity switching capabilities in this repository, and stay consistent with the current implementation.
Scope
- Initialize local
profile - with
useridentity via OAuth authorization code + PKCE login - with
botidentity, enterapp_id/app_secret - View or clear local identity status
- Switch the default business identity
- Troubleshoot
config.jsonandsecrets.jsonlocal persistence issues
Implementation source
- internal/cli/app.go
- internal/cli/auth_provider.go
- internal/config/store.go
- internal/config/secrets.go
Configuration initialization
Before first use, you must run:
contract-cli config add --env dev
The current implementation only has built-in dev environment, with the default profile named contract-group. This command will:
- Discover well-known metadata
- Save MCP server / resource / OAuth server configuration
- Initialize
default_identityasuser
identity model
Two identities are maintained under the same profile:
| Identity | Command | Local storage | Current implementation |
|---|---|---|---|
user |
contract-cli auth login --as user |
profiles.<name>.identities.user.token |
OAuth login implemented |
bot |
contract-cli auth login --as bot |
profiles.<name>.identities.bot + secrets.json |
Credential entry and tenant_access_token exchange implemented |
There is also an additional default identity pointer:
profiles.<name>.default_identity- Modified by
contract-cli auth use --as user|botModify auth login --as ...After success, it will also automatically switch to the corresponding identity
Quick flow
user login
contract-cli config add --env dev
contract-cli auth login --as user
contract-cli auth status --as user
Behavior constraints:
userlogin automatically registersclient_id- Uses authorization code mode + PKCE
- Will start a local callback service; the callback address comes from the profile's
redirect_url - By default, automatically opens the browser; to only print the link, use
--no-open-browser - After successful login, write
identities.user.token
bot login
contract-cli auth login --as bot --app-id "<app_id>" --app-secret "<app_secret>"
contract-cli auth status --as bot
Credentials can also be provided via environment variables:
export CONTRACT_CLI_BOT_APP_ID="<app_id>"
export CONTRACT_CLI_BOT_APP_SECRET="<app_secret>"
contract-cli auth login --as bot
At runtime it is also compatible with the old variable DEMOCLI_BOT_APP_ID / DEMOCLI_BOT_APP_SECRET, but newly added configurations should uniformly use CONTRACT_CLI_*。
Credential priority is fixed as:
- Command-line arguments
- Environment variables
- Locally saved credentials
Behavior constraints:
botlogin will first saveapp_id/app_secret, then calltenant_access_token/internalto exchange for tokenapp_secretis not written toconfig.json- After token success, write
identities.bot.token - If token exchange fails, the new credentials will be retained, but the default identity will not be switched to
bot - After successful login, will switch
default_identity=bot
Status, logout, and switching
View status
contract-cli auth status --as user
contract-cli auth status --as bot
Rules:
- When
--asis not passed,auth statusdefaults to viewinguser usershowsauthorizedorunauthorizedbotshowsauthorized、expired、configuredorunconfiguredbotstatus will showToken Endpoint、Token Protocol: tenant_access_token/internaland expiration time (if any)
Logout
contract-cli auth logout --as user
contract-cli auth logout --as bot
Rules:
logout --as useronly clearsuser.tokenlogout --as botonly clearsbot.token, retainsapp_id/app_secretand the corresponding secret- When
--asis not passed,auth logoutdefaults to handlinguser
Switch default identity
contract-cli auth use --as user
contract-cli auth use --as bot
Rules:
- This command only modifies
default_identity - does not log in again
- does not verify that the target identity has already obtained a token
Local file
The default path is as follows; if CONTRACT_CLI_CONFIG_DIRis set, it changes to that directory:
~/.contract-cli/config.json~/.contract-cli/secrets.json
At runtime it is also compatible with the old DEMOCLI_CONFIG_DIR and the historical default directory ~/.democli, for smoothly reading the existing local login state.
Storage constraints:
config.jsonsaves profile, identity metadata, and tokensecrets.jsononly saves the bot'sapp_secretuser.tokenandbot.tokenare stored separately and are not shared- Legacy flat OAuth fields are automatically migrated to
identities.user
Security rules
- Do not output in plaintext in the terminal or documentation
app_secret、access_token、refresh_token - Do not
botdescribe bot logout as "deleting credentials"; the current implementation only clears the token and does not deleteapp_id/app_secret - Do not let users mistakenly think that
default_identitywill affectauth statusorauth logout's default target; when these two commands are not passed--as, they still followuser - When writing or clearing local credentials, first confirm that the operation is on the current profile
Troubleshooting
user identity is not configured: first runcontract-cli config add --env dev- Browser does not open automatically: use
--no-open-browser, and manually visit the output authorization link - Callback timeout: check whether the port corresponding to
redirect_urlcan be listened on, and increase it if necessary--timeout - Bot credentials incomplete: complete
--app-id/--app-secretor setCONTRACT_CLI_BOT_APP_ID/CONTRACT_CLI_BOT_APP_SECRET - Bot login prompt is missing
bot_token_endpoint: this indicates the profile is too old; reruncontract-cli config add --env dev --name <profile> - Bot status shows
expired: reruncontract-cli auth login --as bot