@openstax/ts-utils 1.16.2 → 1.17.0
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/dist/cjs/services/launchParams/signer.d.ts +1 -1
- package/dist/cjs/services/launchParams/signer.js +11 -7
- package/dist/cjs/tsconfig.without-specs.cjs.tsbuildinfo +1 -1
- package/dist/esm/services/launchParams/signer.d.ts +1 -1
- package/dist/esm/services/launchParams/signer.js +11 -7
- package/dist/esm/tsconfig.without-specs.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -21,7 +21,7 @@ export declare const createLaunchSigner: <C extends string = "launch">({ configS
|
|
|
21
21
|
jwks: () => Promise<{
|
|
22
22
|
keys: JWK.RawKey[];
|
|
23
23
|
}>;
|
|
24
|
-
sign: (subject: string,
|
|
24
|
+
sign: (subject: string, maxExp?: number | null | undefined) => Promise<string>;
|
|
25
25
|
};
|
|
26
26
|
export declare type LaunchSigner = ReturnType<ReturnType<typeof createLaunchSigner>>;
|
|
27
27
|
export {};
|
|
@@ -28,17 +28,21 @@ export const createLaunchSigner = ({ configSpace }) => (configProvider) => {
|
|
|
28
28
|
return keystore;
|
|
29
29
|
});
|
|
30
30
|
const jwks = async () => (await getKeyStore()).toJSON(false);
|
|
31
|
-
const getExpiresInWithMax = async (
|
|
31
|
+
const getExpiresInWithMax = async (maxExp) => {
|
|
32
32
|
const expiresIn = await getExpiresIn();
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
// The ms library used by jsonwebtoken can handle a value in seconds as well as a string like '1d'
|
|
34
|
+
if (!maxExp) {
|
|
35
|
+
return expiresIn;
|
|
36
|
+
}
|
|
37
|
+
// Convert both values to seconds for comparison
|
|
38
|
+
const expiresInSeconds = Math.floor(ms(expiresIn) / 1000);
|
|
39
|
+
const maxExpSeconds = maxExp - Math.floor(Date.now() / 1000);
|
|
40
|
+
return Math.min(expiresInSeconds, maxExpSeconds);
|
|
37
41
|
};
|
|
38
|
-
const sign = async (subject,
|
|
42
|
+
const sign = async (subject, maxExp) => {
|
|
39
43
|
const alg = await getAlg();
|
|
40
44
|
// expiresIn can be a number of seconds or a string like '1h' or '1d'
|
|
41
|
-
const expiresIn = await getExpiresInWithMax(
|
|
45
|
+
const expiresIn = await getExpiresInWithMax(maxExp);
|
|
42
46
|
const iss = await getIss();
|
|
43
47
|
const header = { alg, iss };
|
|
44
48
|
return jwt.sign({}, await getPrivateKey(), { algorithm: alg, expiresIn, header, issuer: iss, subject });
|