Commit ec0da82
authored
refactor(auth): implement browser-based and refresh token authentication flow (#15)
## Summary
Adds browser-based OAuth PKCE authentication as an alternative to Service Account login, migrates secret storage to the OS keychain, and fixes several bugs discovered during implementation.
## What changed
### New authentication flow (`src/auth.rs`, `src/context.rs`)
- `fb auth` now offers a choice: **Browser login (PKCE)** or **Service Account**
- Browser flow: opens system browser → local callback server (5 fixed candidate ports) → PKCE code exchange → tokens stored in OS keychain
- After authenticating, interactively selects an account from the API (`GET /web/v3/myAccounts`) — auto-selects if only one account exists
- System engine URL is discovered automatically per account
- Both flows prompt for optional default database/engine
### Keyring-based secret storage
- All secrets (SA client secret, access tokens, refresh tokens) stored in OS keychain via `keyring` crate
- `--no-keyring` flag falls back to `~/.firebolt/fb_secrets` (YAML file)
- Enabled `apple-native` and `linux-native` keyring features — without these the crate compiled with an in-memory mock backend, losing tokens between invocations
- Namespaced keyring keys: `browser_access_token`/`browser_refresh_token` for browser flow, `sa_access_token`/`sa_secret` for SA flow — prevents cross-flow token collisions
### New subcommands
- `fb auth token` — prints current access token to stdout, refreshes if expired1 parent 85483b8 commit ec0da82
9 files changed
Lines changed: 2106 additions & 869 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
98 | 102 | | |
99 | 103 | | |
100 | 104 | | |
| |||
0 commit comments