6. Storing tokens on the developer machine

10 cards

Review this deck
All cards in this deck

OS credential store

macOS Keychain, Windows Credential Manager, Linux Secret Service (libsecret); the preferred place to store refresh tokens.

File fallback

A JSON file in the user's config directory with 0600 permissions, readable only by the owner.

Typical fields in the auth file

`version` plus `profiles{}`, each profile with issuer, userId, email, team, scope, refreshToken, accessToken (optional), expiresAt (epoch ms); when debugging, print only field names, never values.

Keychain library for Node

`@napi-rs/keyring` is still maintained; `keytar` has been archived and should not be chosen for new projects.

expiresAt

The CLI compares it with the current time minus a skew margin so it refreshes before the access token expires.

Proper logout

Call revoke on the server (RFC 7009) for the refresh token, then delete the local credential.

RFC 7009

Token revocation endpoint; the server returns 200 even for invalid tokens to avoid leaking information.

Token environment variable

Used for CI, takes precedence over the stored credential; easily causes identity confusion when you forget to unset it on a developer machine.

whoami

A command that shows the account, the team/scope in use, and the credential source; the first debugging tool.

Multiple accounts / teams

Store them per profile; the CLI must show which profile is active.

6. Storing tokens on the developer machine – Flashcards – CLI Auth | Học Dev