1346
* @see https://datatracker.ietf.org/doc/html/rfc8414#section-3
1347
*/
1348
>
export async function fetchAuthorizationServerMetadata(
oauth.ts
1349
>
authorizationServer: string,
1350
>
options: IFetchAuthorizationServerMetadataOptions = {}
1351
>
): Promise<{ metadata: IAuthorizationServerMetadata; discoveryUrl: string; errors: Error[] }> {
1352
>
const {
1353
>
additionalHeaders = {},
1354
>
fetch: fetchImpl = fetch
1355
>
} = options;
1356
>
1357
>
const authorizationServerUrl = new URL(authorizationServer);
1358
>
const extraPath = authorizationServerUrl.pathname === '/' ? '' : authorizationServerUrl.pathname;
1359
>
1360
>
const errors: Error[] = [];
1361
>
1362
>
const doFetch = async (url: string): Promise<IAuthorizationServerMetadata | undefined> => {
1363
>
try {
1364
>
const rawResponse = await fetchImpl(url, {
1365
>
method: 'GET',
1366
>
headers: {
1367
>
...additionalHeaders,
1368
>
'Accept': 'application/json'
1369
>
}
1370
>
});
1371
const metadata = await tryParseAuthServerMetadata(rawResponse);
1372
if (metadata) {