mirror of
https://github.com/danbulant/jose
synced 2026-05-25 04:51:47 +00:00
27 lines
894 B
JavaScript
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;
|