Skip to content

Commit b67a11b

Browse files
authored
feat: store auth tokens in OS credential storage (#77)
1 parent faa7e81 commit b67a11b

File tree

12 files changed

+862
-50
lines changed

12 files changed

+862
-50
lines changed

README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,41 @@ This makes the `tw` command available globally.
2626

2727
## Setup
2828

29-
Set up your Twist API token:
30-
3129
```bash
3230
tw auth login
3331
```
3432

33+
This opens your browser to authenticate with Twist. Once approved, the token is stored in your OS credential manager:
34+
35+
- macOS: Keychain
36+
- Windows: Credential Manager
37+
- Linux: Secret Service/libsecret
38+
39+
If secure storage is unavailable, the CLI warns and falls back to `~/.config/twist-cli/config.json`. Existing plaintext tokens are migrated automatically the next time the CLI reads them successfully from the config file. Non-secret settings such as the current workspace remain in the config file.
40+
41+
### Alternative methods
42+
43+
**Manual token:**
44+
45+
```bash
46+
tw auth token "your-token"
47+
```
48+
49+
**Environment variable:**
50+
51+
```bash
52+
export TWIST_API_TOKEN="your-token"
53+
```
54+
55+
`TWIST_API_TOKEN` always takes priority over the stored token.
56+
57+
### Auth commands
58+
59+
```bash
60+
tw auth status # check if authenticated
61+
tw auth logout # remove saved token
62+
```
63+
3564
## Usage
3665

3766
```bash

docs/SPEC.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ __tests__/ # Test suite
5050
Token resolution (priority order):
5151

5252
1. Environment variable: `TWIST_API_TOKEN`
53-
2. Config file: `~/.config/twist-cli/config.json`
53+
2. System credential manager (Keychain, Credential Manager, or Secret Service)
54+
3. Legacy plaintext token in `~/.config/twist-cli/config.json` during auto-migration
55+
4. Plaintext config fallback when the OS credential store is unavailable
5456

5557
## Workspace Scoping
5658

@@ -469,11 +471,12 @@ Location: `~/.config/twist-cli/config.json`
469471

470472
```json
471473
{
472-
"token": "optional-token-here",
473474
"currentWorkspace": 12345
474475
}
475476
```
476477

478+
`token` may appear temporarily in legacy installs before migration, or as a fallback when the system credential manager is unavailable.
479+
477480
---
478481

479482
## Examples

package-lock.json

Lines changed: 224 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,8 @@
7070
"semantic-release": "25.0.3",
7171
"typescript": "5.9.3",
7272
"vitest": "4.0.18"
73+
},
74+
"optionalDependencies": {
75+
"@napi-rs/keyring": "1.2.0"
7376
}
7477
}

0 commit comments

Comments
 (0)