{"version":3,"file":"AuthenticationHeaderParser.js","sources":["../../src/request/AuthenticationHeaderParser.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ClientConfigurationError } from \"../error/ClientConfigurationError\";\nimport { Constants, HeaderNames } from \"../utils/Constants\";\n\ntype WWWAuthenticateChallenges = {\n nonce?: string,\n};\n\ntype AuthenticationInfoChallenges = {\n nextnonce?: string\n};\n\n/**\n * This is a helper class that parses supported HTTP response authentication headers to extract and return\n * header challenge values that can be used outside the basic authorization flows.\n */\nexport class AuthenticationHeaderParser {\n private headers: Record<string, string>;\n\n constructor(headers: Record<string, string>) {\n this.headers = headers;\n }\n\n /**\n * This method parses the SHR nonce value out of either the Authentication-Info or WWW-Authenticate authentication headers.\n * @returns \n */\n getShrNonce(): string {\n // Attempt to parse nonce from Authentiacation-Info\n const authenticationInfo = this.headers[HeaderNames.AuthenticationInfo];\n if (authenticationInfo) {\n const authenticationInfoChallenges = this.parseChallenges<AuthenticationInfoChallenges>(authenticationInfo);\n if (authenticationInfoChallenges.nextnonce) {\n return authenticationInfoChallenges.nextnonce;\n }\n throw ClientConfigurationError.createInvalidAuthenticationHeaderError(HeaderNames.AuthenticationInfo, \"nextnonce challenge is missing.\");\n }\n\n // Attempt to parse nonce from WWW-Authenticate\n const wwwAuthenticate = this.headers[HeaderNames.WWWAuthenticate];\n if (wwwAuthenticate) {\n const wwwAuthenticateChallenges = this.parseChallenges<WWWAuthenticateChallenges>(wwwAuthenticate); \n if (wwwAuthenticateChallenges.nonce){\n return wwwAuthenticateChallenges.nonce;\n }\n throw ClientConfigurationError.createInvalidAuthenticationHeaderError(HeaderNames.WWWAuthenticate, \"nonce challenge is missing.\");\n }\n\n // If neither header is present, throw missing headers error\n throw ClientConfigurationError.createMissingNonceAuthenticationHeadersError();\n }\n\n /**\n * Parses an HTTP header's challenge set into a key/value map.\n * @param header \n * @returns \n */\n private parseChallenges<T>(header: string): T {\n const schemeSeparator = header.indexOf(\" \");\n const challenges = header.substr(schemeSeparator + 1).split(\",\");\n const challengeMap = {} as T;\n\n challenges.forEach((challenge: string) => {\n const [ key, value ] = challenge.split(\"=\");\n // Remove escaped quotation marks (', \") from challenge string to keep only the challenge value\n challengeMap[key] = unescape(value.replace(/['\"]+/g, Constants.EMPTY_STRING));\n });\n\n return challengeMap;\n }\n}\n"],"names":[],"mappings":";;;;;AAAA;;;AAGG;AAaH;;;AAGG;AACH,IAAA,0BAAA,kBAAA,YAAA;AAGI,IAAA,SAAA,0BAAA,CAAY,OAA+B,EAAA;AACvC,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;KAC1B;AAED;;;AAGG;AACH,IAAA,0BAAA,CAAA,SAAA,CAAA,WAAW,GAAX,YAAA;;QAEI,IAAM,kBAAkB,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC;AACxE,QAAA,IAAI,kBAAkB,EAAE;YACpB,IAAM,4BAA4B,GAAG,IAAI,CAAC,eAAe,CAA+B,kBAAkB,CAAC,CAAC;YAC5G,IAAI,4BAA4B,CAAC,SAAS,EAAE;gBACxC,OAAO,4BAA4B,CAAC,SAAS,CAAC;AACjD,aAAA;YACD,MAAM,wBAAwB,CAAC,sCAAsC,CAAC,WAAW,CAAC,kBAAkB,EAAE,iCAAiC,CAAC,CAAC;AAC5I,SAAA;;QAGD,IAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;AAClE,QAAA,IAAI,eAAe,EAAE;YACjB,IAAM,yBAAyB,GAAG,IAAI,CAAC,eAAe,CAA4B,eAAe,CAAC,CAAC;YACnG,IAAI,yBAAyB,CAAC,KAAK,EAAC;gBAChC,OAAO,yBAAyB,CAAC,KAAK,CAAC;AAC1C,aAAA;YACD,MAAM,wBAAwB,CAAC,sCAAsC,CAAC,WAAW,CAAC,eAAe,EAAE,6BAA6B,CAAC,CAAC;AACrI,SAAA;;AAGD,QAAA,MAAM,wBAAwB,CAAC,4CAA4C,EAAE,CAAC;KACjF,CAAA;AAED;;;;AAIG;IACK,0BAAe,CAAA,SAAA,CAAA,eAAA,GAAvB,UAA2B,MAAc,EAAA;QACrC,IAAM,eAAe,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AAC5C,QAAA,IAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACjE,IAAM,YAAY,GAAG,EAAO,CAAC;AAE7B,QAAA,UAAU,CAAC,OAAO,CAAC,UAAC,SAAiB,EAAA;AAC3B,YAAA,IAAA,EAAiB,GAAA,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,EAAnC,GAAG,GAAA,EAAA,CAAA,CAAA,CAAA,EAAE,KAAK,QAAyB,CAAC;;AAE5C,YAAA,YAAY,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC;AAClF,SAAC,CAAC,CAAC;AAEH,QAAA,OAAO,YAAY,CAAC;KACvB,CAAA;IACL,OAAC,0BAAA,CAAA;AAAD,CAAC,EAAA;;;;"}
* - authority - URL of the authority, the security token service (STS) from which MSAL will acquire tokens. Defaults to https://login.microsoftonline.com/common. If using the same authority for all request, authority should set on client application object and not request, to avoid resolving authority endpoints multiple times.
* - correlationId - Unique GUID set per request to trace a request end-to-end for telemetry purposes.
* - scopes - Array of scopes the application is requesting access to.
* - authenticationScheme - The type of token retrieved. Defaults to "Bearer". Can also be type "pop" or "SSH".
* - claims - A stringified claims request which will be added to all /authorize and /token calls
* - shrClaims - A stringified claims object which will be added to a Signed HTTP Request
* - shrNonce - A server-generated timestamp that has been encrypted and base64URL encoded, which will be added to a Signed HTTP Request.
* - resourceRequestMethod - HTTP Request type used to request data from the resource (i.e. "GET", "POST", etc.). Used for proof-of-possession flows.
* - resourceRequestUri - URI that token will be used for. Used for proof-of-possession flows.
* - sshJwk - A stringified JSON Web Key representing a public key that can be signed by an SSH certificate.
* - sshKid - Key ID that uniquely identifies the SSH public key mentioned above.
* - azureCloudOptions - Convenience string enums for users to provide public/sovereign cloud ids
* - requestedClaimsHash - SHA 256 hash string of the requested claims string, used as part of an access token cache key so tokens can be filtered by requested claims
* Request object passed by user to acquire a token from the server exchanging a valid authorization code (second leg of OAuth2.0 Authorization Code flow)
*
* - scopes - Array of scopes the application is requesting access to.
* - claims - A stringified claims request which will be added to all /authorize and /token calls
* - authority: - URL of the authority, the security token service (STS) from which MSAL will acquire tokens. If authority is set on client application object, this will override that value. Overriding the value will cause for authority validation to happen each time. If the same authority will be used for all request, set on the application object instead of the requests.
* - correlationId - Unique GUID set per request to trace a request end-to-end for telemetry purposes.
* - redirectUri - The redirect URI of your app, where the authority will redirect to after the user inputs credentials and consents. It must exactly match one of the redirect URIs you registered in the portal
* - code - The authorization_code that the user acquired in the first leg of the flow.
* - codeVerifier - The same code_verifier that was used to obtain the authorization_code. Required if PKCE was used in the authorization code grant request.For more information, see the PKCE RFC: https://tools.ietf.org/html/rfc7636
* - resourceRequestMethod - HTTP Request type used to request data from the resource (i.e. "GET", "POST", etc.). Used for proof-of-possession flows.
* - resourceRequestUri - URI that token will be used for. Used for proof-of-possession flows.
* - enableSpaAuthCode - Enables the acqusition of a spa authorization code (confidential clients only)