You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fallback to .well-known/oauth-protected-resource on 401s without WWW-Authenticate (microsoft#268977)
* refactor resource metadata reading into oauth base file
the logic is going to get more complicated, so I want to encapsulate it where it should go.
* fix test
* Fallback to .well-known/oauth-protected-resource on 401s without WWW-Authenticate
Fixesmicrosoft#268210
// Use URL constructor for normalization - it handles hostname case and trailing slashes
1055
+
constprmValue=newURL(body.resource).toString();
1056
+
consttargetValue=targetResourceUrlObj.toString();
1057
+
if(prmValue!==targetValue){
1058
+
thrownewError(`Protected Resource Metadata resource property value "${prmValue}" (length: ${prmValue.length}) does not match target server url "${targetValue}" (length: ${targetValue.length}). These MUST match to follow OAuth spec https://datatracker.ietf.org/doc/html/rfc9728#PRConfigurationValidation`);
1059
+
}
1060
+
returnbody;
1061
+
}else{
1062
+
errors.push(newError(`Invalid resource metadata from ${urlToTry}. Expected to follow shape of https://datatracker.ietf.org/doc/html/rfc9728#name-protected-resource-metadata (Hints: is scopes_supported an array? Is resource a string?). Current payload: ${JSON.stringify(body)}`));
1063
+
continue;
1064
+
}
1065
+
}catch(e){
1066
+
errors.push(einstanceofError ? e : newError(String(e)));
1067
+
continue;
1068
+
}
1069
+
}
1070
+
// If we've tried all URLs and none worked, throw the error(s)
1071
+
if(errors.length===1){
1072
+
throwerrors[0];
1073
+
}else{
1074
+
thrownewAggregateError(errors,'Failed to fetch resource metadata from all attempted URLs');
0 commit comments