@kokuin/oauth 0.7.6 → 0.7.7
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.
|
@@ -20,6 +20,7 @@ export type CreateClientAssertionParams = {
|
|
|
20
20
|
signer: ClientAssertionSigner;
|
|
21
21
|
clientID: string;
|
|
22
22
|
audience: string;
|
|
23
|
+
/** Seconds from `iat` to `exp`: a positive integer, default `60`. */
|
|
23
24
|
lifetimeSeconds?: number;
|
|
24
25
|
/** Current time in seconds since epoch. */
|
|
25
26
|
now?: () => number;
|
package/lib/client-assertion.js
CHANGED
|
@@ -31,6 +31,10 @@ function assertSupportedAlgorithm(alg) {
|
|
|
31
31
|
/** Build a signed JWT client assertion for `private_key_jwt` client authentication. */ export async function createClientAssertion(params) {
|
|
32
32
|
const { signer, clientID, audience, lifetimeSeconds = DEFAULT_LIFETIME_SECONDS, now = ()=>Math.floor(Date.now() / 1000), typ = DEFAULT_TYP, runtime } = params;
|
|
33
33
|
assertSupportedAlgorithm(signer.alg);
|
|
34
|
+
// Anything else gives an assertion that is already expired or has a malformed `exp`.
|
|
35
|
+
if (!Number.isInteger(lifetimeSeconds) || lifetimeSeconds <= 0) {
|
|
36
|
+
throw new Error(`Client assertion lifetimeSeconds must be a positive integer, got: ${lifetimeSeconds}`);
|
|
37
|
+
}
|
|
34
38
|
const randomBytes = (length)=>runtime == null ? globalThis.crypto.getRandomValues(new Uint8Array(length)) : runtime.getRandomValues(new Uint8Array(length));
|
|
35
39
|
const iat = now();
|
|
36
40
|
const header = {
|