UNPKG

@authing/jose

Version:

Webpack v4 compatible version of panva/jose v3.x

28 lines (27 loc) 895 B
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 (err) { throw new JOSEError('Failed to parse the JSON Web Key Set HTTP response as JSON'); } }; export default fetchJwks;