@dropsh/plugin-oauth2 0.7.3 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -172,12 +172,36 @@ export function oauth2Provider(cfg) {
|
|
|
172
172
|
current = minted;
|
|
173
173
|
await rt.save(minted);
|
|
174
174
|
}
|
|
175
|
+
// The session slot is shared by every process of this user (conductor, ui,
|
|
176
|
+
// agent CLI calls), and the server rotates the refresh token on each use.
|
|
177
|
+
// Adopt what another process stored instead of refreshing with a revoked token;
|
|
178
|
+
// returns true when the adopted access token is still valid.
|
|
179
|
+
async function adoptStored() {
|
|
180
|
+
const stored = await rt.load?.();
|
|
181
|
+
if (!stored ||
|
|
182
|
+
stored.access_token === current.access_token ||
|
|
183
|
+
typeof stored.refresh_token !== "string")
|
|
184
|
+
return false;
|
|
185
|
+
current = stored;
|
|
186
|
+
const expiresAt = typeof stored.expires_at === "number" ? stored.expires_at : 0;
|
|
187
|
+
return expiresAt - 30_000 > rt.now();
|
|
188
|
+
}
|
|
175
189
|
async function renewSession() {
|
|
176
190
|
if (cfg.type === "oauth2_authcode" || cfg.type === "oauth2_device_code") {
|
|
191
|
+
if (await adoptStored())
|
|
192
|
+
return;
|
|
177
193
|
const refresh = current.refresh_token;
|
|
178
194
|
if (typeof refresh !== "string")
|
|
179
195
|
throw new AuthError("Session expired. Run 'dropsh auth login'.");
|
|
180
|
-
|
|
196
|
+
try {
|
|
197
|
+
await refreshAuthcode(refresh);
|
|
198
|
+
}
|
|
199
|
+
catch (err) {
|
|
200
|
+
// Lost the race: another process rotated the token between load and post.
|
|
201
|
+
if (await adoptStored())
|
|
202
|
+
return;
|
|
203
|
+
throw err;
|
|
204
|
+
}
|
|
181
205
|
return;
|
|
182
206
|
}
|
|
183
207
|
if (cfg.type === "oauth2_client_credentials") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dropsh/plugin-oauth2",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/plugins/oauth2/src/index.js",
|
|
6
6
|
"types": "./dist/plugins/oauth2/src/index.d.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"typescript": "^5.6.0",
|
|
25
25
|
"vitest": "^4.1.8",
|
|
26
|
-
"dropsh": "0.7.
|
|
26
|
+
"dropsh": "0.7.5"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
29
|
"build": "tsc",
|