@hardfin/cli 0.0.2-dev.13 → 0.0.2-dev.14
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.
- package/README.md +3 -3
- package/dist/cli.js +28 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -285,9 +285,9 @@ Nothing secret is printed. An API key and a refresh token are each reported as a
|
|
|
285
285
|
`sha256:` fingerprint, which identifies a credential across two machines without disclosing
|
|
286
286
|
it.
|
|
287
287
|
|
|
288
|
-
`refreshExpiresAt` is
|
|
289
|
-
|
|
290
|
-
|
|
288
|
+
`refreshExpiresAt` is what the server said when it issued the token. A sign in stored before
|
|
289
|
+
the server reported one falls back to Hardfin's 90-day rule, and `refreshExpiryIsEstimated`
|
|
290
|
+
says which of the two you are looking at.
|
|
291
291
|
|
|
292
292
|
## Local configuration
|
|
293
293
|
|
package/dist/cli.js
CHANGED
|
@@ -293,6 +293,7 @@ const TokenResponse = z.looseObject({
|
|
|
293
293
|
token_type: z.string(),
|
|
294
294
|
expires_in: z.number().optional(),
|
|
295
295
|
refresh_token: z.string().optional(),
|
|
296
|
+
refresh_token_expires_in: z.number().optional(),
|
|
296
297
|
scope: z.string().optional()
|
|
297
298
|
});
|
|
298
299
|
/** GrantFailure is a token request the authorization server refused. */
|
|
@@ -351,6 +352,7 @@ async function toTokens(url, form) {
|
|
|
351
352
|
return {
|
|
352
353
|
accessToken: parsed.data.access_token,
|
|
353
354
|
refreshToken: parsed.data.refresh_token,
|
|
355
|
+
refreshExpiresAt: parsed.data.refresh_token_expires_in === void 0 ? void 0 : Date.now() + parsed.data.refresh_token_expires_in * 1e3,
|
|
354
356
|
scope: parsed.data.scope,
|
|
355
357
|
expiresAt: parsed.data.expires_in === void 0 ? void 0 : Date.now() + parsed.data.expires_in * 1e3
|
|
356
358
|
};
|
|
@@ -375,12 +377,13 @@ function toCredentialPath() {
|
|
|
375
377
|
* family lifetime runs from. Callers hold the credential lock, which is what makes a write
|
|
376
378
|
* from another process merge rather than disappear.
|
|
377
379
|
*/
|
|
378
|
-
function keep(issuer, refreshToken) {
|
|
380
|
+
function keep(issuer, refreshToken, expiresAt) {
|
|
379
381
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
380
382
|
const record = {
|
|
381
383
|
refreshToken,
|
|
382
384
|
signedInAt: toCredential(issuer)?.signedInAt ?? now,
|
|
383
|
-
renewedAt: now
|
|
385
|
+
renewedAt: now,
|
|
386
|
+
expiresAt: expiresAt === void 0 ? void 0 : new Date(expiresAt).toISOString()
|
|
384
387
|
};
|
|
385
388
|
const keyring = toKeyring(issuer);
|
|
386
389
|
if (keyring) try {
|
|
@@ -566,7 +569,7 @@ async function toAccessToken(settings, refreshToken) {
|
|
|
566
569
|
try {
|
|
567
570
|
const tokens = await toTokensFromRefresh(metadata.token_endpoint, settings.clientId, latest);
|
|
568
571
|
held.set(settings.issuerUrl, tokens);
|
|
569
|
-
if (tokens.refreshToken && tokens.refreshToken !== latest) keep(settings.issuerUrl, tokens.refreshToken);
|
|
572
|
+
if (tokens.refreshToken && tokens.refreshToken !== latest) keep(settings.issuerUrl, tokens.refreshToken, tokens.refreshExpiresAt);
|
|
570
573
|
return tokens;
|
|
571
574
|
} catch (error) {
|
|
572
575
|
if (error instanceof GrantFailure && isDead(error.code)) {
|
|
@@ -1366,7 +1369,7 @@ async function toSignedIn(input, metadata, tokens) {
|
|
|
1366
1369
|
writeFailure("the authorization server issued no refresh token, so this sign in cannot be kept", input.isJSON);
|
|
1367
1370
|
return ExitCode.ERROR;
|
|
1368
1371
|
}
|
|
1369
|
-
const backend = await withLock(() => keep(input.resolved.settings.issuerUrl, refreshToken));
|
|
1372
|
+
const backend = await withLock(() => keep(input.resolved.settings.issuerUrl, refreshToken, tokens.refreshExpiresAt));
|
|
1370
1373
|
if (input.isJSON) {
|
|
1371
1374
|
writeData({
|
|
1372
1375
|
signedIn: true,
|
|
@@ -4378,6 +4381,23 @@ const surfaceCommands = [
|
|
|
4378
4381
|
}
|
|
4379
4382
|
]
|
|
4380
4383
|
},
|
|
4384
|
+
{
|
|
4385
|
+
name: "token",
|
|
4386
|
+
summary: "Token commands",
|
|
4387
|
+
arguments: [],
|
|
4388
|
+
flags: [],
|
|
4389
|
+
examples: [],
|
|
4390
|
+
subcommands: [defineOperation({
|
|
4391
|
+
name: "get",
|
|
4392
|
+
summary: "Report the credential this CLI is calling with",
|
|
4393
|
+
example: "hardfin token get",
|
|
4394
|
+
method: "GET",
|
|
4395
|
+
path: "/token",
|
|
4396
|
+
pathParameters: [],
|
|
4397
|
+
queryFlags: [],
|
|
4398
|
+
bodyFlags: []
|
|
4399
|
+
})]
|
|
4400
|
+
},
|
|
4381
4401
|
{
|
|
4382
4402
|
name: "url-link",
|
|
4383
4403
|
summary: "URL link commands",
|
|
@@ -4514,8 +4534,8 @@ function toFile(path) {
|
|
|
4514
4534
|
//#endregion
|
|
4515
4535
|
//#region src/command/status.ts
|
|
4516
4536
|
/**
|
|
4517
|
-
*
|
|
4518
|
-
*
|
|
4537
|
+
* What the CLI falls back to for an older sign in, stored before the server began reporting
|
|
4538
|
+
* when a refresh token expires. Hardfin's own rule, and an estimate rather than a fact.
|
|
4519
4539
|
*/
|
|
4520
4540
|
const REFRESH_SLIDING_DAYS = 90;
|
|
4521
4541
|
const statusCommand = defineCommand({
|
|
@@ -4619,8 +4639,8 @@ function toCredentialReport(apiKey, stored) {
|
|
|
4619
4639
|
fingerprint: toFingerprint(stored.refreshToken),
|
|
4620
4640
|
signedInAt: stored.signedInAt ?? null,
|
|
4621
4641
|
renewedAt: stored.renewedAt ?? null,
|
|
4622
|
-
refreshExpiresAt: toRefreshExpiry(stored.renewedAt),
|
|
4623
|
-
refreshExpiryIsEstimated:
|
|
4642
|
+
refreshExpiresAt: stored.expiresAt ?? toRefreshExpiry(stored.renewedAt),
|
|
4643
|
+
refreshExpiryIsEstimated: stored.expiresAt === void 0
|
|
4624
4644
|
};
|
|
4625
4645
|
}
|
|
4626
4646
|
function toServerReport(metadata) {
|