jose/dist/browser/runtime/fetch_jwks.js
2021-08-20 15:51:24 +02:00

27 lines
894 B
JavaScript

import { JOSEError } from '../util/errors.js';
import globalThis from './global.js';
const fetchJwks = async (url, timeout) => {
let controller;
if (typeof AbortController === 'function') {
controller = new AbortController();
setTimeout(() => controller.abort(), timeout);
}
const response = await globalThis.fetch(url.href, {
signal: controller ? controller.signal : undefined,
redirect: 'manual',
referrerPolicy: 'no-referrer',
credentials: 'omit',
mode: 'cors',
method: 'GET',
});
if (response.status !== 200) {
throw new JOSEError('Expected 200 OK from the JSON Web Key Set HTTP response');
}
try {
return await response.json();
}
catch (_a) {
throw new JOSEError('Failed to parse the JSON Web Key Set HTTP response as JSON');
}
};
export default fetchJwks;