Commit 9f010a5
fix(auth): refresh on 401 and stop writing bogus refresh tokens
Users report being logged out of brev-cli multiple times per hour,
forcing repeated `brev login --token`. Two bugs in the auth flow
caused this:
1. `LoginWithToken` stored the literal string "auto-login" as the
RefreshToken whenever it was handed a valid JWT access token
(pkg/auth/auth.go). When that short-lived access token later
expired, the refresh path in `GetFreshAccessTokenOrNil` tried to
exchange "auto-login" with the IdP, which always failed, so the
user was prompted to re-login every time the access token aged
out — roughly hourly with typical NVIDIA KAS token lifetimes.
2. The auth-failure retry handler in pkg/store/http.go only fired on
HTTP 403 Forbidden. APIs returning 401 Unauthorized (the more
standard response for expired credentials) bypassed the refresh
hook entirely and surfaced as a hard failure on the first such
response, even when the refresh token was still good.
This change:
- Stores an empty RefreshToken when LoginWithToken receives a JWT,
so the refresh path correctly recognizes there is nothing to
refresh and falls through without a failed IdP round-trip. Emits a
one-line notice on stderr so the user knows this session cannot
be auto-renewed.
- Normalizes the legacy "auto-login" sentinel to "" on read, so
users with existing credentials.json files from older CLI versions
benefit from the fix without re-running `brev login --token`.
- Changes `GetFreshAccessTokenOrNil` to return "" (rather than an
expired AccessToken) when there is no way to refresh, so callers
prompt for re-login cleanly instead of shipping an expired JWT to
the API.
- Extends the refresh-and-retry handler in AuthHTTPStore to fire on
both 401 and 403.
Longer-term the website at brev.nvidia.com/settings/cli should hand
out a real refresh token (or a short-lived exchange code) rather
than a raw access JWT so `brev login --token` can produce a
refreshable session. This PR is the CLI-only stop-the-bleeding fix.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent 9e0e34b commit 9f010a5
2 files changed
Lines changed: 43 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
149 | 156 | | |
150 | 157 | | |
151 | 158 | | |
| |||
154 | 161 | | |
155 | 162 | | |
156 | 163 | | |
157 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
158 | 171 | | |
159 | 172 | | |
160 | 173 | | |
161 | 174 | | |
162 | 175 | | |
163 | 176 | | |
164 | 177 | | |
165 | | - | |
166 | | - | |
167 | 178 | | |
168 | 179 | | |
169 | 180 | | |
| |||
197 | 208 | | |
198 | 209 | | |
199 | 210 | | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
200 | 216 | | |
201 | 217 | | |
202 | 218 | | |
203 | 219 | | |
204 | 220 | | |
205 | 221 | | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
206 | 231 | | |
207 | 232 | | |
208 | | - | |
| 233 | + | |
209 | 234 | | |
210 | 235 | | |
211 | 236 | | |
212 | 237 | | |
213 | 238 | | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
214 | 242 | | |
215 | | - | |
| 243 | + | |
216 | 244 | | |
217 | 245 | | |
218 | 246 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
| 107 | + | |
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
| 120 | + | |
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
128 | 136 | | |
129 | 137 | | |
130 | 138 | | |
| |||
0 commit comments