Commit 0be82d4
committed
feat(oauth): add bidirectional OAuth phantom token swap
Extend sluice's phantom token system to handle OAuth credentials
bidirectionally. Previously, phantom swap was request-only (phantom to
real in outbound requests). This adds response-side interception: when
an OAuth token endpoint returns new access/refresh tokens, sluice
captures the real tokens, stores them in the vault, and replaces them
with phantom tokens in the response body before it reaches the agent.
Key changes:
Vault: new OAuthCredential type storing access_token, refresh_token,
token_url, and expires_at as JSON blob in age-encrypted files. Phantom
tokens are deterministic (SLUICE_PHANTOM:name.access/refresh).
Store: new credential_meta table (migration 000002) tracking credential
type and token_url. CRUD operations with upsert semantics.
CLI: --type oauth and --token-url flags on sluice cred add. Tokens
read from stdin to avoid shell history exposure. Two phantom files
per OAuth credential (CRED_ACCESS, CRED_REFRESH).
Proxy: OAuthIndex maps token URLs to credential names for fast lookup
during response interception. Response handler uses singleflight for
concurrent refresh dedup. Supports both JSON and form-encoded token
responses per RFC 6749. Request-side swap extended to handle OAuth
phantom pairs alongside static credentials.
API: OpenAPI spec and REST handlers updated with type/token_url fields
for credential CRUD endpoints.
Hot-reload: OAuth index rebuilt on StoreResolver calls. Async vault
writes after response interception do not block HTTP response delivery.1 parent 348f0cb commit 0be82d4
33 files changed
Lines changed: 5327 additions & 283 deletions
File tree
- api
- cmd/sluice
- docs/plans/completed
- internal
- api
- proxy
- store
- migrations
- telegram
- vault
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
| 76 | + | |
| 77 | + | |
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
| |||
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
| 87 | + | |
| 88 | + | |
86 | 89 | | |
87 | 90 | | |
88 | 91 | | |
89 | 92 | | |
90 | 93 | | |
91 | 94 | | |
92 | | - | |
| 95 | + | |
93 | 96 | | |
94 | 97 | | |
95 | 98 | | |
| |||
104 | 107 | | |
105 | 108 | | |
106 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
107 | 131 | | |
108 | 132 | | |
109 | 133 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
233 | 233 | | |
234 | 234 | | |
235 | 235 | | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
236 | 273 | | |
237 | 274 | | |
238 | 275 | | |
| |||
255 | 292 | | |
256 | 293 | | |
257 | 294 | | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
258 | 307 | | |
259 | 308 | | |
260 | 309 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
716 | 716 | | |
717 | 717 | | |
718 | 718 | | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
719 | 726 | | |
720 | 727 | | |
721 | 728 | | |
722 | | - | |
| 729 | + | |
723 | 730 | | |
724 | 731 | | |
725 | 732 | | |
726 | 733 | | |
727 | 734 | | |
728 | | - | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
729 | 750 | | |
730 | 751 | | |
731 | 752 | | |
| |||
0 commit comments