1196
* @throws Error if the fetch fails, returns non-200 status, or the response is invalid on all attempted URLs
1197
*/
1198
>
export async function fetchResourceMetadata(
oauth.ts
1199
>
targetResource: string,
1200
>
resourceMetadataUrl: string | undefined,
1201
>
options: IFetchResourceMetadataOptions = {}
1202
>
): Promise<{ metadata: IAuthorizationProtectedResourceMetadata; discoveryUrl: string; errors: Error[] }> {
1203
>
const {
1204
>
sameOriginHeaders = {},
1205
>
fetch: fetchImpl = fetch
1206
>
} = options;
1207
>
1208
>
const targetResourceUrlObj = new URL(targetResource);
1209
>
1210
>
const fetchPrm = async (prmUrl: string, validateUrl: string) => {
1211
>
// Determine if we should include same-origin headers
1212
>
let headers: Record<string, string> = {
1213
>
'Accept': 'application/json'
1214
>
};
1215
>
1216
>
const resourceMetadataUrlObj = new URL(prmUrl);
1217
>
if (resourceMetadataUrlObj.origin === targetResourceUrlObj.origin) {
1218
headers = {
1219
...headers,