1006
1007
export function parseWWWAuthenticateHeader(wwwAuthenticateHeaderValue: string): IAuthenticationChallenge[] {
1008
>
const challenges: IAuthenticationChallenge[] = [];
oauth.ts
1009
>
1010
>
// According to RFC 7235, multiple challenges are separated by commas
1011
>
// But parameters within a challenge can also be separated by commas
1012
>
// We need to identify scheme names to know where challenges start
1013
>
1014
>
// First, split by commas while respecting quoted strings
1015
>
const tokens: string[] = [];
1016
>
let current = '';
1017
>
let inQuotes = false;
1018
>
1019
>
for (let i = 0; i < wwwAuthenticateHeaderValue.length; i++) {
1020
>
const char = wwwAuthenticateHeaderValue[i];
1021
>
1022
>
if (char === '"') {
1023
inQuotes = !inQuotes;
1024
current += char;
1025
>
} else if (char === ',' && !inQuotes) {
oauth.ts
1026
if (current.trim()) {
1027
tokens.push(current.trim());
1028
}
1029
current = '';
1031
>
current += char;
1032
>
}
1033
>
}
1034
>
1035
>
if (current.trim()) {
1036
>
tokens.push(current.trim());
1037
>
}
1038
>
1039
>
// Now process tokens to identify challenges
1040
>
// A challenge starts with a scheme name (a token that doesn't contain '=' and is followed by parameters or is standalone)
1041
>
let currentChallenge: { scheme: string; params: Record<string, string> } | undefined;
1042
>
1043
>
for (const token of tokens) {
1044
>
const hasEquals = token.includes('=');
1045
>
1046
>
if (!hasEquals) {
1047
// This token doesn't have '=', so it's likely a scheme name
1048
if (currentChallenge) {