@meistrari/data-token 0.0.19 → 1.0.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/index.d.mts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.mjs +11 -5
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as jose from 'jose';
|
|
2
|
-
import { errors } from 'jose';
|
|
2
|
+
import { RemoteJWKSetOptions, errors } from 'jose';
|
|
3
3
|
import * as zod from 'zod';
|
|
4
4
|
export { D as DataToken, V as ValidatorConfig } from './shared/data-token.1d70cb5e.mjs';
|
|
5
5
|
|
|
@@ -9,10 +9,12 @@ export { D as DataToken, V as ValidatorConfig } from './shared/data-token.1d70cb
|
|
|
9
9
|
* @param jwksUrl - The URL of the JWKS endpoint.
|
|
10
10
|
* @param options - The options for the validator.
|
|
11
11
|
* @param options.algorithms - The algorithms to use for validation.
|
|
12
|
+
* @param options.remoteJwksOptions - The options to pass to `createRemoteJWKSet`.
|
|
12
13
|
* @returns A function that can validate a data token.
|
|
13
14
|
*/
|
|
14
|
-
declare function getValidator(jwksUrl: string, { algorithms }?: {
|
|
15
|
-
algorithms
|
|
15
|
+
declare function getValidator(jwksUrl: string, { algorithms, remoteJwksOptions }?: {
|
|
16
|
+
algorithms?: string[] | undefined;
|
|
17
|
+
remoteJwksOptions?: RemoteJWKSetOptions | undefined;
|
|
16
18
|
}): (token: string) => Promise<{
|
|
17
19
|
requestId: string;
|
|
18
20
|
workspace: {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as jose from 'jose';
|
|
2
|
-
import { errors } from 'jose';
|
|
2
|
+
import { RemoteJWKSetOptions, errors } from 'jose';
|
|
3
3
|
import * as zod from 'zod';
|
|
4
4
|
export { D as DataToken, V as ValidatorConfig } from './shared/data-token.1d70cb5e.js';
|
|
5
5
|
|
|
@@ -9,10 +9,12 @@ export { D as DataToken, V as ValidatorConfig } from './shared/data-token.1d70cb
|
|
|
9
9
|
* @param jwksUrl - The URL of the JWKS endpoint.
|
|
10
10
|
* @param options - The options for the validator.
|
|
11
11
|
* @param options.algorithms - The algorithms to use for validation.
|
|
12
|
+
* @param options.remoteJwksOptions - The options to pass to `createRemoteJWKSet`.
|
|
12
13
|
* @returns A function that can validate a data token.
|
|
13
14
|
*/
|
|
14
|
-
declare function getValidator(jwksUrl: string, { algorithms }?: {
|
|
15
|
-
algorithms
|
|
15
|
+
declare function getValidator(jwksUrl: string, { algorithms, remoteJwksOptions }?: {
|
|
16
|
+
algorithms?: string[] | undefined;
|
|
17
|
+
remoteJwksOptions?: RemoteJWKSetOptions | undefined;
|
|
16
18
|
}): (token: string) => Promise<{
|
|
17
19
|
requestId: string;
|
|
18
20
|
workspace: {
|
package/dist/index.mjs
CHANGED
|
@@ -56,12 +56,18 @@ const retry = createExponentialBackoff({
|
|
|
56
56
|
maxRetries: 3,
|
|
57
57
|
jitter: true
|
|
58
58
|
});
|
|
59
|
-
function getValidator(jwksUrl, { algorithms
|
|
60
|
-
|
|
61
|
-
new URL(jwksUrl),
|
|
62
|
-
{ cacheMaxAge: 0, headers: { "cache-control": "no-cache", "pragma": "no-cache" } }
|
|
63
|
-
);
|
|
59
|
+
function getValidator(jwksUrl, { algorithms = ["RS256"], remoteJwksOptions = {} } = {}) {
|
|
60
|
+
let JWKS;
|
|
64
61
|
return async (token) => {
|
|
62
|
+
JWKS || (JWKS = createRemoteJWKSet(
|
|
63
|
+
new URL(jwksUrl),
|
|
64
|
+
{
|
|
65
|
+
// Cache control is done by the remote JWKS instance, so we need to set it to no-cache to avoid
|
|
66
|
+
// interference from any CDN that might be caching the JWKS.
|
|
67
|
+
headers: { "cache-control": "no-cache", "pragma": "no-cache" },
|
|
68
|
+
...remoteJwksOptions
|
|
69
|
+
}
|
|
70
|
+
));
|
|
65
71
|
const { payload } = await retry(
|
|
66
72
|
async () => jwtVerify(token, JWKS, { algorithms }),
|
|
67
73
|
(err) => err instanceof errors.JWKSTimeout || err instanceof Error && err.message.includes("ECONNRESET")
|
package/package.json
CHANGED