g(x,C)?(a[d]=x,a[n]=c,d=n):(a[d]=C,a[m]=c,d=m);else if(ng(x,c))a[d]=x,a[n]=c,d=n;else break a}}return b}\nfunction g(a,b){var c=a.sortIndex-b.sortIndex;return 0!==c?c:a.id-b.id}if(\"object\"===typeof performance&&\"function\"===typeof performance.now){var l=performance;exports.unstable_now=function(){return l.now()}}else{var p=Date,q=p.now();exports.unstable_now=function(){return p.now()-q}}var r=[],t=[],u=1,v=null,y=3,z=!1,A=!1,B=!1,D=\"function\"===typeof setTimeout?setTimeout:null,E=\"function\"===typeof clearTimeout?clearTimeout:null,F=\"undefined\"!==typeof setImmediate?setImmediate:null;\n\"undefined\"!==typeof navigator&&void 0!==navigator.scheduling&&void 0!==navigator.scheduling.isInputPending&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function G(a){for(var b=h(t);null!==b;){if(null===b.callback)k(t);else if(b.startTime<=a)k(t),b.sortIndex=b.expirationTime,f(r,b);else break;b=h(t)}}function H(a){B=!1;G(a);if(!A)if(null!==h(r))A=!0,I(J);else{var b=h(t);null!==b&&K(H,b.startTime-a)}}\nfunction J(a,b){A=!1;B&&(B=!1,E(L),L=-1);z=!0;var c=y;try{G(b);for(v=h(r);null!==v&&(!(v.expirationTime>b)||a&&!M());){var d=v.callback;if(\"function\"===typeof d){v.callback=null;y=v.priorityLevel;var e=d(v.expirationTime<=b);b=exports.unstable_now();\"function\"===typeof e?v.callback=e:v===h(r)&&k(r);G(b)}else k(r);v=h(r)}if(null!==v)var w=!0;else{var m=h(t);null!==m&&K(H,m.startTime-b);w=!1}return w}finally{v=null,y=c,z=!1}}var N=!1,O=null,L=-1,P=5,Q=-1;\nfunction M(){return exports.unstable_now()-Qa||125d?(a.sortIndex=c,f(t,a),null===h(r)&&a===h(t)&&(B?(E(L),L=-1):B=!0,K(H,c-d))):(a.sortIndex=e,f(r,a),A||z||(A=!0,I(J)));return a};\nexports.unstable_shouldYield=M;exports.unstable_wrapCallback=function(a){var b=y;return function(){var c=y;y=b;try{return a.apply(this,arguments)}finally{y=c}}};\n","'use strict';\n\nif (process.env.NODE_ENV === 'production') {\n module.exports = require('./cjs/scheduler.production.min.js');\n} else {\n module.exports = require('./cjs/scheduler.development.js');\n}\n","var map = {\n\t\"./bettercotton.png\": 4836,\n\t\"./bettercotton_inv.png\": 8556,\n\t\"./bettercotton_reg.png\": 8791,\n\t\"./excel.png\": 6010,\n\t\"./material.png\": 8624,\n\t\"./power-bi.png\": 6992,\n\t\"./radixtree.png\": 6793,\n\t\"./radixtree_inv.png\": 1557,\n\t\"./radixtree_reg.png\": 9070,\n\t\"./retraced.png\": 4077,\n\t\"./retraced_inv.png\": 7489,\n\t\"./retraced_reg.png\": 2810,\n\t\"./textilegenesis.png\": 9448,\n\t\"./textilegenesis_inv.png\": 9176,\n\t\"./textilegenesis_reg.png\": 4547\n};\n\n\nfunction webpackContext(req) {\n\tvar id = webpackContextResolve(req);\n\treturn __webpack_require__(id);\n}\nfunction webpackContextResolve(req) {\n\tif(!__webpack_require__.o(map, req)) {\n\t\tvar e = new Error(\"Cannot find module '\" + req + \"'\");\n\t\te.code = 'MODULE_NOT_FOUND';\n\t\tthrow e;\n\t}\n\treturn map[req];\n}\nwebpackContext.keys = function webpackContextKeys() {\n\treturn Object.keys(map);\n};\nwebpackContext.resolve = webpackContextResolve;\nmodule.exports = webpackContext;\nwebpackContext.id = 5336;","function _extends() {\n return (module.exports = _extends = Object.assign ? Object.assign.bind() : function (n) {\n for (var e = 1; e < arguments.length; e++) {\n var t = arguments[e];\n for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);\n }\n return n;\n }, module.exports.__esModule = true, module.exports[\"default\"] = module.exports), _extends.apply(null, arguments);\n}\nmodule.exports = _extends, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;","function _interopRequireDefault(e) {\n return e && e.__esModule ? e : {\n \"default\": e\n };\n}\nmodule.exports = _interopRequireDefault, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;","function _objectWithoutPropertiesLoose(r, e) {\n if (null == r) return {};\n var t = {};\n for (var n in r) if ({}.hasOwnProperty.call(r, n)) {\n if (e.indexOf(n) >= 0) continue;\n t[n] = r[n];\n }\n return t;\n}\nmodule.exports = _objectWithoutPropertiesLoose, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;","function _extends() {\n return _extends = Object.assign ? Object.assign.bind() : function (n) {\n for (var e = 1; e < arguments.length; e++) {\n var t = arguments[e];\n for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);\n }\n return n;\n }, _extends.apply(null, arguments);\n}\nexport { _extends as default };","function _setPrototypeOf(t, e) {\n return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {\n return t.__proto__ = e, t;\n }, _setPrototypeOf(t, e);\n}\nexport { _setPrototypeOf as default };","import setPrototypeOf from \"./setPrototypeOf.js\";\nfunction _inheritsLoose(t, o) {\n t.prototype = Object.create(o.prototype), t.prototype.constructor = t, setPrototypeOf(t, o);\n}\nexport { _inheritsLoose as default };","function _objectWithoutPropertiesLoose(r, e) {\n if (null == r) return {};\n var t = {};\n for (var n in r) if ({}.hasOwnProperty.call(r, n)) {\n if (e.indexOf(n) >= 0) continue;\n t[n] = r[n];\n }\n return t;\n}\nexport { _objectWithoutPropertiesLoose as default };","function r(e){var t,f,n=\"\";if(\"string\"==typeof e||\"number\"==typeof e)n+=e;else if(\"object\"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","var getProto = Object.getPrototypeOf ? (obj) => (Object.getPrototypeOf(obj)) : (obj) => (obj.__proto__);\nvar leafPrototypes;\n// create a fake namespace object\n// mode & 1: value is a module id, require it\n// mode & 2: merge all properties of value into the ns\n// mode & 4: return value when already ns object\n// mode & 16: return value when it's Promise-like\n// mode & 8|1: behave like require\n__webpack_require__.t = function(value, mode) {\n\tif(mode & 1) value = this(value);\n\tif(mode & 8) return value;\n\tif(typeof value === 'object' && value) {\n\t\tif((mode & 4) && value.__esModule) return value;\n\t\tif((mode & 16) && typeof value.then === 'function') return value;\n\t}\n\tvar ns = Object.create(null);\n\t__webpack_require__.r(ns);\n\tvar def = {};\n\tleafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)];\n\tfor(var current = mode & 2 && value; typeof current == 'object' && !~leafPrototypes.indexOf(current); current = getProto(current)) {\n\t\tObject.getOwnPropertyNames(current).forEach((key) => (def[key] = () => (value[key])));\n\t}\n\tdef['default'] = () => (value);\n\t__webpack_require__.d(ns, def);\n\treturn ns;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.g = (function() {\n\tif (typeof globalThis === 'object') return globalThis;\n\ttry {\n\t\treturn this || new Function('return this')();\n\t} catch (e) {\n\t\tif (typeof window === 'object') return window;\n\t}\n})();","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","__webpack_require__.p = \"/\";","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nexport const Constants = {\r\n LIBRARY_NAME: \"MSAL.JS\",\r\n SKU: \"msal.js.common\",\r\n // Prefix for all library cache entries\r\n CACHE_PREFIX: \"msal\",\r\n // default authority\r\n DEFAULT_AUTHORITY: \"https://login.microsoftonline.com/common/\",\r\n DEFAULT_AUTHORITY_HOST: \"login.microsoftonline.com\",\r\n DEFAULT_COMMON_TENANT: \"common\",\r\n // ADFS String\r\n ADFS: \"adfs\",\r\n DSTS: \"dstsv2\",\r\n // Default AAD Instance Discovery Endpoint\r\n AAD_INSTANCE_DISCOVERY_ENDPT: \"https://login.microsoftonline.com/common/discovery/instance?api-version=1.1&authorization_endpoint=\",\r\n // CIAM URL\r\n CIAM_AUTH_URL: \".ciamlogin.com\",\r\n AAD_TENANT_DOMAIN_SUFFIX: \".onmicrosoft.com\",\r\n // Resource delimiter - used for certain cache entries\r\n RESOURCE_DELIM: \"|\",\r\n // Placeholder for non-existent account ids/objects\r\n NO_ACCOUNT: \"NO_ACCOUNT\",\r\n // Claims\r\n CLAIMS: \"claims\",\r\n // Consumer UTID\r\n CONSUMER_UTID: \"9188040d-6c67-4c5b-b112-36a304b66dad\",\r\n // Default scopes\r\n OPENID_SCOPE: \"openid\",\r\n PROFILE_SCOPE: \"profile\",\r\n OFFLINE_ACCESS_SCOPE: \"offline_access\",\r\n EMAIL_SCOPE: \"email\",\r\n // Default response type for authorization code flow\r\n CODE_RESPONSE_TYPE: \"code\",\r\n CODE_GRANT_TYPE: \"authorization_code\",\r\n RT_GRANT_TYPE: \"refresh_token\",\r\n FRAGMENT_RESPONSE_MODE: \"fragment\",\r\n S256_CODE_CHALLENGE_METHOD: \"S256\",\r\n URL_FORM_CONTENT_TYPE: \"application/x-www-form-urlencoded;charset=utf-8\",\r\n AUTHORIZATION_PENDING: \"authorization_pending\",\r\n NOT_DEFINED: \"not_defined\",\r\n EMPTY_STRING: \"\",\r\n NOT_APPLICABLE: \"N/A\",\r\n FORWARD_SLASH: \"/\",\r\n IMDS_ENDPOINT: \"http://169.254.169.254/metadata/instance/compute/location\",\r\n IMDS_VERSION: \"2020-06-01\",\r\n IMDS_TIMEOUT: 2000,\r\n AZURE_REGION_AUTO_DISCOVER_FLAG: \"TryAutoDetect\",\r\n REGIONAL_AUTH_PUBLIC_CLOUD_SUFFIX: \"login.microsoft.com\",\r\n REGIONAL_AUTH_NON_MSI_QUERY_STRING: \"allowestsrnonmsi=true\",\r\n KNOWN_PUBLIC_CLOUDS: [\"login.microsoftonline.com\", \"login.windows.net\", \"login.microsoft.com\", \"sts.windows.net\"],\r\n TOKEN_RESPONSE_TYPE: \"token\",\r\n ID_TOKEN_RESPONSE_TYPE: \"id_token\",\r\n SHR_NONCE_VALIDITY: 240,\r\n INVALID_INSTANCE: \"invalid_instance\",\r\n};\r\n\r\nexport const OIDC_DEFAULT_SCOPES = [\r\n Constants.OPENID_SCOPE,\r\n Constants.PROFILE_SCOPE,\r\n Constants.OFFLINE_ACCESS_SCOPE\r\n];\r\n\r\nexport const OIDC_SCOPES = [\r\n ...OIDC_DEFAULT_SCOPES,\r\n Constants.EMAIL_SCOPE\r\n];\r\n\r\n/**\r\n * Request header names\r\n */\r\nexport enum HeaderNames {\r\n CONTENT_TYPE = \"Content-Type\",\r\n RETRY_AFTER = \"Retry-After\",\r\n CCS_HEADER = \"X-AnchorMailbox\",\r\n WWWAuthenticate = \"WWW-Authenticate\",\r\n AuthenticationInfo = \"Authentication-Info\",\r\n X_MS_REQUEST_ID = \"x-ms-request-id\",\r\n X_MS_HTTP_VERSION= \"x-ms-httpver\"\r\n}\r\n\r\n/**\r\n * Persistent cache keys MSAL which stay while user is logged in.\r\n */\r\nexport enum PersistentCacheKeys {\r\n ID_TOKEN = \"idtoken\",\r\n CLIENT_INFO = \"client.info\",\r\n ADAL_ID_TOKEN = \"adal.idtoken\",\r\n ERROR = \"error\",\r\n ERROR_DESC = \"error.description\",\r\n ACTIVE_ACCOUNT = \"active-account\", // Legacy active-account cache key, use new key instead\r\n ACTIVE_ACCOUNT_FILTERS = \"active-account-filters\" // new cache entry for active_account for a more robust version for browser\r\n}\r\n\r\n/**\r\n * String constants related to AAD Authority\r\n */\r\nexport enum AADAuthorityConstants {\r\n COMMON = \"common\",\r\n ORGANIZATIONS = \"organizations\",\r\n CONSUMERS = \"consumers\"\r\n}\r\n\r\n/**\r\n * Keys in the hashParams sent by AAD Server\r\n */\r\nexport enum AADServerParamKeys {\r\n CLIENT_ID = \"client_id\",\r\n REDIRECT_URI = \"redirect_uri\",\r\n RESPONSE_TYPE = \"response_type\",\r\n RESPONSE_MODE = \"response_mode\",\r\n GRANT_TYPE = \"grant_type\",\r\n CLAIMS = \"claims\",\r\n SCOPE = \"scope\",\r\n ERROR = \"error\",\r\n ERROR_DESCRIPTION = \"error_description\",\r\n ACCESS_TOKEN = \"access_token\",\r\n ID_TOKEN = \"id_token\",\r\n REFRESH_TOKEN = \"refresh_token\",\r\n EXPIRES_IN = \"expires_in\",\r\n STATE = \"state\",\r\n NONCE = \"nonce\",\r\n PROMPT = \"prompt\",\r\n SESSION_STATE = \"session_state\",\r\n CLIENT_INFO = \"client_info\",\r\n CODE = \"code\",\r\n CODE_CHALLENGE = \"code_challenge\",\r\n CODE_CHALLENGE_METHOD = \"code_challenge_method\",\r\n CODE_VERIFIER = \"code_verifier\",\r\n CLIENT_REQUEST_ID = \"client-request-id\",\r\n X_CLIENT_SKU = \"x-client-SKU\",\r\n X_CLIENT_VER = \"x-client-VER\",\r\n X_CLIENT_OS = \"x-client-OS\",\r\n X_CLIENT_CPU = \"x-client-CPU\",\r\n X_CLIENT_CURR_TELEM = \"x-client-current-telemetry\",\r\n X_CLIENT_LAST_TELEM = \"x-client-last-telemetry\",\r\n X_MS_LIB_CAPABILITY = \"x-ms-lib-capability\",\r\n X_APP_NAME = \"x-app-name\",\r\n X_APP_VER = \"x-app-ver\",\r\n POST_LOGOUT_URI = \"post_logout_redirect_uri\",\r\n ID_TOKEN_HINT = \"id_token_hint\",\r\n DEVICE_CODE = \"device_code\",\r\n CLIENT_SECRET = \"client_secret\",\r\n CLIENT_ASSERTION = \"client_assertion\",\r\n CLIENT_ASSERTION_TYPE = \"client_assertion_type\",\r\n TOKEN_TYPE = \"token_type\",\r\n REQ_CNF = \"req_cnf\",\r\n OBO_ASSERTION = \"assertion\",\r\n REQUESTED_TOKEN_USE = \"requested_token_use\",\r\n ON_BEHALF_OF = \"on_behalf_of\",\r\n FOCI = \"foci\",\r\n CCS_HEADER = \"X-AnchorMailbox\",\r\n RETURN_SPA_CODE = \"return_spa_code\",\r\n NATIVE_BROKER = \"nativebroker\",\r\n LOGOUT_HINT = \"logout_hint\"\r\n}\r\n\r\n/**\r\n * Claims request keys\r\n */\r\nexport enum ClaimsRequestKeys {\r\n ACCESS_TOKEN = \"access_token\",\r\n XMS_CC = \"xms_cc\"\r\n}\r\n\r\n/**\r\n * we considered making this \"enum\" in the request instead of string, however it looks like the allowed list of\r\n * prompt values kept changing over past couple of years. There are some undocumented prompt values for some\r\n * internal partners too, hence the choice of generic \"string\" type instead of the \"enum\"\r\n */\r\nexport const PromptValue = {\r\n LOGIN: \"login\",\r\n SELECT_ACCOUNT: \"select_account\",\r\n CONSENT: \"consent\",\r\n NONE: \"none\",\r\n CREATE: \"create\",\r\n NO_SESSION: \"no_session\"\r\n};\r\n\r\n/**\r\n * SSO Types - generated to populate hints\r\n */\r\nexport enum SSOTypes {\r\n ACCOUNT = \"account\",\r\n SID = \"sid\",\r\n LOGIN_HINT = \"login_hint\",\r\n ID_TOKEN = \"id_token\",\r\n DOMAIN_HINT = \"domain_hint\",\r\n ORGANIZATIONS = \"organizations\",\r\n CONSUMERS = \"consumers\",\r\n ACCOUNT_ID = \"accountIdentifier\",\r\n HOMEACCOUNT_ID = \"homeAccountIdentifier\"\r\n}\r\n\r\n/**\r\n * allowed values for codeVerifier\r\n */\r\nexport const CodeChallengeMethodValues = {\r\n PLAIN: \"plain\",\r\n S256: \"S256\"\r\n};\r\n\r\n/**\r\n * The method used to encode the code verifier for the code challenge parameter. can be one\r\n * of plain or s256. if excluded, code challenge is assumed to be plaintext. for more\r\n * information, see the pkce rcf: https://tools.ietf.org/html/rfc7636\r\n */\r\nexport const CodeChallengeMethodValuesArray: string[] = [\r\n CodeChallengeMethodValues.PLAIN,\r\n CodeChallengeMethodValues.S256\r\n];\r\n\r\n/**\r\n * allowed values for response_mode\r\n */\r\nexport enum ResponseMode {\r\n QUERY = \"query\",\r\n FRAGMENT = \"fragment\",\r\n FORM_POST = \"form_post\"\r\n}\r\n\r\n/**\r\n * allowed grant_type\r\n */\r\nexport enum GrantType {\r\n IMPLICIT_GRANT = \"implicit\",\r\n AUTHORIZATION_CODE_GRANT = \"authorization_code\",\r\n CLIENT_CREDENTIALS_GRANT = \"client_credentials\",\r\n RESOURCE_OWNER_PASSWORD_GRANT = \"password\",\r\n REFRESH_TOKEN_GRANT = \"refresh_token\",\r\n DEVICE_CODE_GRANT = \"device_code\",\r\n JWT_BEARER = \"urn:ietf:params:oauth:grant-type:jwt-bearer\"\r\n}\r\n\r\n/**\r\n * Account types in Cache\r\n */\r\nexport enum CacheAccountType {\r\n MSSTS_ACCOUNT_TYPE = \"MSSTS\",\r\n ADFS_ACCOUNT_TYPE = \"ADFS\",\r\n MSAV1_ACCOUNT_TYPE = \"MSA\",\r\n GENERIC_ACCOUNT_TYPE = \"Generic\" // NTLM, Kerberos, FBA, Basic etc\r\n}\r\n\r\n/**\r\n * Separators used in cache\r\n */\r\nexport enum Separators {\r\n CACHE_KEY_SEPARATOR = \"-\",\r\n CLIENT_INFO_SEPARATOR = \".\"\r\n}\r\n\r\n/**\r\n * Credential Type stored in the cache\r\n */\r\nexport enum CredentialType {\r\n ID_TOKEN = \"IdToken\",\r\n ACCESS_TOKEN = \"AccessToken\",\r\n ACCESS_TOKEN_WITH_AUTH_SCHEME = \"AccessToken_With_AuthScheme\",\r\n REFRESH_TOKEN = \"RefreshToken\",\r\n}\r\n\r\n/**\r\n * Combine all cache types\r\n */\r\nexport enum CacheType {\r\n ADFS = 1001,\r\n MSA = 1002,\r\n MSSTS = 1003,\r\n GENERIC = 1004,\r\n ACCESS_TOKEN = 2001,\r\n REFRESH_TOKEN = 2002,\r\n ID_TOKEN = 2003,\r\n APP_METADATA = 3001,\r\n UNDEFINED = 9999\r\n}\r\n\r\n/**\r\n * More Cache related constants\r\n */\r\nexport const APP_METADATA = \"appmetadata\";\r\nexport const CLIENT_INFO = \"client_info\";\r\nexport const THE_FAMILY_ID = \"1\";\r\n\r\nexport const AUTHORITY_METADATA_CONSTANTS = {\r\n CACHE_KEY: \"authority-metadata\",\r\n REFRESH_TIME_SECONDS: 3600 * 24 // 24 Hours\r\n};\r\n\r\nexport enum AuthorityMetadataSource {\r\n CONFIG = \"config\",\r\n CACHE = \"cache\",\r\n NETWORK = \"network\",\r\n HARDCODED_VALUES= \"hardcoded_values\",\r\n}\r\n\r\nexport const SERVER_TELEM_CONSTANTS = {\r\n SCHEMA_VERSION: 5,\r\n MAX_CUR_HEADER_BYTES: 80, // ESTS limit is 100B, set to 80 to provide a 20B buffer\r\n MAX_LAST_HEADER_BYTES: 330, // ESTS limit is 350B, set to 330 to provide a 20B buffer,\r\n MAX_CACHED_ERRORS: 50, // Limit the number of errors that can be stored to prevent uncontrolled size gains\r\n CACHE_KEY: \"server-telemetry\",\r\n CATEGORY_SEPARATOR: \"|\",\r\n VALUE_SEPARATOR: \",\",\r\n OVERFLOW_TRUE: \"1\",\r\n OVERFLOW_FALSE: \"0\",\r\n UNKNOWN_ERROR: \"unknown_error\"\r\n};\r\n\r\n/**\r\n * Type of the authentication request\r\n */\r\nexport enum AuthenticationScheme {\r\n BEARER = \"Bearer\",\r\n POP = \"pop\",\r\n SSH = \"ssh-cert\"\r\n}\r\n\r\n/**\r\n * Constants related to throttling\r\n */\r\nexport const ThrottlingConstants = {\r\n // Default time to throttle RequestThumbprint in seconds\r\n DEFAULT_THROTTLE_TIME_SECONDS: 60,\r\n // Default maximum time to throttle in seconds, overrides what the server sends back\r\n DEFAULT_MAX_THROTTLE_TIME_SECONDS: 3600,\r\n // Prefix for storing throttling entries\r\n THROTTLING_PREFIX: \"throttling\",\r\n // Value assigned to the x-ms-lib-capability header to indicate to the server the library supports throttling\r\n X_MS_LIB_CAPABILITY_VALUE: \"retry-after, h429\"\r\n};\r\n\r\nexport const Errors = {\r\n INVALID_GRANT_ERROR: \"invalid_grant\",\r\n CLIENT_MISMATCH_ERROR: \"client_mismatch\",\r\n};\r\n\r\n/**\r\n * Password grant parameters\r\n */\r\nexport enum PasswordGrantConstants {\r\n username = \"username\",\r\n password = \"password\"\r\n}\r\n\r\n/**\r\n * Response codes\r\n */\r\nexport enum ResponseCodes {\r\n httpSuccess = 200,\r\n httpBadRequest = 400\r\n}\r\n\r\n/**\r\n * Region Discovery Sources\r\n */\r\nexport enum RegionDiscoverySources {\r\n FAILED_AUTO_DETECTION = \"1\",\r\n INTERNAL_CACHE = \"2\",\r\n ENVIRONMENT_VARIABLE = \"3\",\r\n IMDS = \"4\",\r\n}\r\n\r\n/**\r\n * Region Discovery Outcomes\r\n */\r\nexport enum RegionDiscoveryOutcomes {\r\n CONFIGURED_MATCHES_DETECTED = \"1\",\r\n CONFIGURED_NO_AUTO_DETECTION = \"2\",\r\n CONFIGURED_NOT_DETECTED = \"3\",\r\n AUTO_DETECTION_REQUESTED_SUCCESSFUL = \"4\",\r\n AUTO_DETECTION_REQUESTED_FAILED = \"5\"\r\n}\r\n\r\nexport enum CacheOutcome {\r\n NO_CACHE_HIT = \"0\",\r\n FORCE_REFRESH = \"1\",\r\n NO_CACHED_ACCESS_TOKEN = \"2\",\r\n CACHED_ACCESS_TOKEN_EXPIRED = \"3\",\r\n REFRESH_CACHED_ACCESS_TOKEN = \"4\",\r\n CLAIMS_REQUESTED_CACHE_SKIPPED = \"5\"\r\n}\r\n\r\nexport enum JsonTypes {\r\n Jwt = \"JWT\",\r\n Jwk = \"JWK\",\r\n Pop = \"pop\"\r\n}\r\n\r\nexport const ONE_DAY_IN_MS = 86400000;\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { OIDC_DEFAULT_SCOPES } from \"@azure/msal-common\";\r\nimport { PopupRequest } from \"../request/PopupRequest\";\r\nimport { RedirectRequest } from \"../request/RedirectRequest\";\r\n\r\n/**\r\n * Constants\r\n */\r\nexport const BrowserConstants = {\r\n /**\r\n * Interaction in progress cache value\r\n */\r\n INTERACTION_IN_PROGRESS_VALUE: \"interaction_in_progress\",\r\n /**\r\n * Invalid grant error code\r\n */\r\n INVALID_GRANT_ERROR: \"invalid_grant\",\r\n /**\r\n * Default popup window width\r\n */\r\n POPUP_WIDTH: 483,\r\n /**\r\n * Default popup window height\r\n */\r\n POPUP_HEIGHT: 600,\r\n /**\r\n * Name of the popup window starts with\r\n */\r\n POPUP_NAME_PREFIX: \"msal\",\r\n /**\r\n * Default popup monitor poll interval in milliseconds\r\n */\r\n DEFAULT_POLL_INTERVAL_MS: 30,\r\n /**\r\n * Msal-browser SKU\r\n */\r\n MSAL_SKU: \"msal.js.browser\",\r\n};\r\n\r\nexport const NativeConstants = {\r\n CHANNEL_ID: \"53ee284d-920a-4b59-9d30-a60315b26836\",\r\n PREFERRED_EXTENSION_ID: \"ppnbnpeolgkicgegkbkbjmhlideopiji\",\r\n MATS_TELEMETRY: \"MATS\"\r\n};\r\n\r\nexport enum NativeExtensionMethod {\r\n HandshakeRequest = \"Handshake\",\r\n HandshakeResponse = \"HandshakeResponse\",\r\n GetToken = \"GetToken\",\r\n Response = \"Response\"\r\n}\r\n\r\nexport enum BrowserCacheLocation {\r\n LocalStorage = \"localStorage\",\r\n SessionStorage = \"sessionStorage\",\r\n MemoryStorage = \"memoryStorage\"\r\n}\r\n\r\n/**\r\n * HTTP Request types supported by MSAL.\r\n */\r\nexport enum HTTP_REQUEST_TYPE {\r\n GET = \"GET\",\r\n POST = \"POST\"\r\n}\r\n\r\n/**\r\n * Temporary cache keys for MSAL, deleted after any request.\r\n */\r\nexport enum TemporaryCacheKeys {\r\n AUTHORITY = \"authority\",\r\n ACQUIRE_TOKEN_ACCOUNT = \"acquireToken.account\",\r\n SESSION_STATE = \"session.state\",\r\n REQUEST_STATE = \"request.state\",\r\n NONCE_IDTOKEN = \"nonce.id_token\",\r\n ORIGIN_URI = \"request.origin\",\r\n RENEW_STATUS = \"token.renew.status\",\r\n URL_HASH = \"urlHash\",\r\n REQUEST_PARAMS = \"request.params\",\r\n SCOPES = \"scopes\",\r\n INTERACTION_STATUS_KEY = \"interaction.status\",\r\n CCS_CREDENTIAL = \"ccs.credential\",\r\n CORRELATION_ID = \"request.correlationId\",\r\n NATIVE_REQUEST = \"request.native\",\r\n REDIRECT_CONTEXT = \"request.redirect.context\"\r\n}\r\n\r\nexport enum StaticCacheKeys {\r\n ACCOUNT_KEYS = \"msal.account.keys\",\r\n TOKEN_KEYS = \"msal.token.keys\"\r\n}\r\n\r\n/**\r\n * Cache keys stored in-memory\r\n */\r\nexport enum InMemoryCacheKeys {\r\n WRAPPER_SKU = \"wrapper.sku\",\r\n WRAPPER_VER = \"wrapper.version\"\r\n}\r\n\r\n/**\r\n * API Codes for Telemetry purposes. \r\n * Before adding a new code you must claim it in the MSAL Telemetry tracker as these number spaces are shared across all MSALs\r\n * 0-99 Silent Flow\r\n * 800-899 Auth Code Flow\r\n */\r\nexport enum ApiId {\r\n acquireTokenRedirect = 861,\r\n acquireTokenPopup = 862,\r\n ssoSilent = 863,\r\n acquireTokenSilent_authCode = 864,\r\n handleRedirectPromise = 865,\r\n acquireTokenByCode = 866,\r\n acquireTokenSilent_silentFlow = 61,\r\n logout = 961,\r\n logoutPopup = 962\r\n}\r\n\r\n/*\r\n * Interaction type of the API - used for state and telemetry\r\n */\r\nexport enum InteractionType {\r\n Redirect = \"redirect\",\r\n Popup = \"popup\",\r\n Silent = \"silent\",\r\n None = \"none\"\r\n}\r\n\r\n/**\r\n * Types of interaction currently in progress.\r\n * Used in events in wrapper libraries to invoke functions when certain interaction is in progress or all interactions are complete.\r\n */\r\nexport enum InteractionStatus {\r\n /**\r\n * Initial status before interaction occurs\r\n */\r\n Startup = \"startup\",\r\n /**\r\n * Status set when all login calls occuring\r\n */\r\n Login = \"login\",\r\n /**\r\n * Status set when logout call occuring\r\n */ \r\n Logout = \"logout\",\r\n /**\r\n * Status set for acquireToken calls\r\n */\r\n AcquireToken = \"acquireToken\",\r\n /**\r\n * Status set for ssoSilent calls\r\n */\r\n SsoSilent = \"ssoSilent\",\r\n /**\r\n * Status set when handleRedirect in progress\r\n */\r\n HandleRedirect = \"handleRedirect\",\r\n /**\r\n * Status set when interaction is complete\r\n */\r\n None = \"none\"\r\n}\r\n\r\nexport const DEFAULT_REQUEST: RedirectRequest|PopupRequest = {\r\n scopes: OIDC_DEFAULT_SCOPES\r\n};\r\n\r\n/**\r\n * JWK Key Format string (Type MUST be defined for window crypto APIs)\r\n */\r\nexport const KEY_FORMAT_JWK = \"jwk\";\r\n\r\n// Supported wrapper SKUs\r\nexport enum WrapperSKU {\r\n React = \"@azure/msal-react\",\r\n Angular = \"@azure/msal-angular\"\r\n}\r\n\r\n// DatabaseStorage Constants\r\nexport const DB_NAME = \"msal.db\";\r\nexport const DB_VERSION = 1;\r\nexport const DB_TABLE_NAME = `${DB_NAME}.keys`;\r\n\r\nexport enum CacheLookupPolicy {\r\n /*\r\n * acquireTokenSilent will attempt to retrieve an access token from the cache. If the access token is expired\r\n * or cannot be found the refresh token will be used to acquire a new one. Finally, if the refresh token\r\n * is expired acquireTokenSilent will attempt to acquire new access and refresh tokens.\r\n */\r\n Default = 0, // 0 is falsy, is equivalent to not passing in a CacheLookupPolicy\r\n /*\r\n * acquireTokenSilent will only look for access tokens in the cache. It will not attempt to renew access or\r\n * refresh tokens.\r\n */\r\n AccessToken = 1,\r\n /*\r\n * acquireTokenSilent will attempt to retrieve an access token from the cache. If the access token is expired or\r\n * cannot be found, the refresh token will be used to acquire a new one. If the refresh token is expired, it\r\n * will not be renewed and acquireTokenSilent will fail.\r\n */\r\n AccessTokenAndRefreshToken = 2,\r\n /*\r\n * acquireTokenSilent will not attempt to retrieve access tokens from the cache and will instead attempt to\r\n * exchange the cached refresh token for a new access token. If the refresh token is expired, it will not be\r\n * renewed and acquireTokenSilent will fail.\r\n */\r\n RefreshToken = 3,\r\n /*\r\n * acquireTokenSilent will not look in the cache for the access token. It will go directly to network with the\r\n * cached refresh token. If the refresh token is expired an attempt will be made to renew it. This is equivalent to\r\n * setting \"forceRefresh: true\".\r\n */\r\n RefreshTokenAndNetwork = 4,\r\n /*\r\n * acquireTokenSilent will attempt to renew both access and refresh tokens. It will not look in the cache. This will\r\n * always fail if 3rd party cookies are blocked by the browser.\r\n */\r\n Skip = 5,\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { Constants } from \"../utils/Constants\";\r\n\r\n/**\r\n * AuthErrorMessage class containing string constants used by error codes and messages.\r\n */\r\nexport const AuthErrorMessage = {\r\n unexpectedError: {\r\n code: \"unexpected_error\",\r\n desc: \"Unexpected error in authentication.\"\r\n },\r\n postRequestFailed: {\r\n code: \"post_request_failed\",\r\n desc: \"Post request failed from the network, could be a 4xx/5xx or a network unavailability. Please check the exact error code for details.\"\r\n }\r\n};\r\n\r\n/**\r\n * General error class thrown by the MSAL.js library.\r\n */\r\nexport class AuthError extends Error {\r\n\r\n /**\r\n * Short string denoting error\r\n */\r\n errorCode: string;\r\n\r\n /**\r\n * Detailed description of error\r\n */\r\n errorMessage: string;\r\n\r\n /**\r\n * Describes the subclass of an error\r\n */\r\n subError: string;\r\n\r\n /**\r\n * CorrelationId associated with the error\r\n */\r\n correlationId: string;\r\n\r\n constructor(errorCode?: string, errorMessage?: string, suberror?: string) {\r\n const errorString = errorMessage ? `${errorCode}: ${errorMessage}` : errorCode;\r\n super(errorString);\r\n Object.setPrototypeOf(this, AuthError.prototype);\r\n\r\n this.errorCode = errorCode || Constants.EMPTY_STRING;\r\n this.errorMessage = errorMessage || Constants.EMPTY_STRING;\r\n this.subError = suberror || Constants.EMPTY_STRING;\r\n this.name = \"AuthError\";\r\n }\r\n\r\n setCorrelationId(correlationId: string): void {\r\n this.correlationId = correlationId;\r\n }\r\n\r\n /**\r\n * Creates an error that is thrown when something unexpected happens in the library.\r\n * @param errDesc\r\n */\r\n static createUnexpectedError(errDesc: string): AuthError {\r\n return new AuthError(AuthErrorMessage.unexpectedError.code, `${AuthErrorMessage.unexpectedError.desc}: ${errDesc}`);\r\n }\r\n\r\n /**\r\n * Creates an error for post request failures.\r\n * @param errDesc \r\n * @returns \r\n */\r\n static createPostRequestFailed(errDesc: string): AuthError {\r\n return new AuthError(AuthErrorMessage.postRequestFailed.code, `${AuthErrorMessage.postRequestFailed.desc}: ${errDesc}`);\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { AuthError } from \"@azure/msal-common\";\r\n\r\n/**\r\n * BrowserAuthErrorMessage class containing string constants used by error codes and messages.\r\n */\r\nexport const BrowserConfigurationAuthErrorMessage = {\r\n redirectUriNotSet: {\r\n code: \"redirect_uri_empty\",\r\n desc: \"A redirect URI is required for all calls, and none has been set.\"\r\n },\r\n postLogoutUriNotSet: {\r\n code: \"post_logout_uri_empty\",\r\n desc: \"A post logout redirect has not been set.\"\r\n },\r\n storageNotSupportedError: {\r\n code: \"storage_not_supported\",\r\n desc: \"Given storage configuration option was not supported.\"\r\n },\r\n noRedirectCallbacksSet: {\r\n code: \"no_redirect_callbacks\",\r\n desc: \"No redirect callbacks have been set. Please call setRedirectCallbacks() with the appropriate function arguments before continuing. \" +\r\n \"More information is available here: https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics.\"\r\n },\r\n invalidCallbackObject: {\r\n code: \"invalid_callback_object\",\r\n desc: \"The object passed for the callback was invalid. \" +\r\n \"More information is available here: https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/MSAL-basics.\"\r\n },\r\n stubPcaInstanceCalled: {\r\n code: \"stubbed_public_client_application_called\",\r\n desc: \"Stub instance of Public Client Application was called. If using msal-react, please ensure context is not used without a provider. For more visit: aka.ms/msaljs/browser-errors\"\r\n },\r\n inMemRedirectUnavailable: {\r\n code: \"in_mem_redirect_unavailable\",\r\n desc: \"Redirect cannot be supported. In-memory storage was selected and storeAuthStateInCookie=false, which would cause the library to be unable to handle the incoming hash. If you would like to use the redirect API, please use session/localStorage or set storeAuthStateInCookie=true.\"\r\n },\r\n entropyNotProvided: {\r\n code: \"entropy_not_provided\",\r\n desc: \"The available browser crypto interface requires entropy set via system.cryptoOptions.entropy configuration option.\"\r\n }\r\n};\r\n\r\n/**\r\n * Browser library error class thrown by the MSAL.js library for SPAs\r\n */\r\nexport class BrowserConfigurationAuthError extends AuthError {\r\n\r\n constructor(errorCode: string, errorMessage?: string) {\r\n super(errorCode, errorMessage);\r\n this.name = \"BrowserConfigurationAuthError\";\r\n\r\n Object.setPrototypeOf(this, BrowserConfigurationAuthError.prototype);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the redirect uri is empty (not set by caller)\r\n */\r\n static createRedirectUriEmptyError(): BrowserConfigurationAuthError {\r\n return new BrowserConfigurationAuthError(BrowserConfigurationAuthErrorMessage.redirectUriNotSet.code,\r\n BrowserConfigurationAuthErrorMessage.redirectUriNotSet.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the post-logout redirect uri is empty (not set by caller)\r\n */\r\n static createPostLogoutRedirectUriEmptyError(): BrowserConfigurationAuthError {\r\n return new BrowserConfigurationAuthError(BrowserConfigurationAuthErrorMessage.postLogoutUriNotSet.code,\r\n BrowserConfigurationAuthErrorMessage.postLogoutUriNotSet.desc);\r\n }\r\n\r\n /**\r\n * Creates error thrown when given storage location is not supported.\r\n * @param givenStorageLocation \r\n */\r\n static createStorageNotSupportedError(givenStorageLocation: string): BrowserConfigurationAuthError {\r\n return new BrowserConfigurationAuthError(BrowserConfigurationAuthErrorMessage.storageNotSupportedError.code, `${BrowserConfigurationAuthErrorMessage.storageNotSupportedError.desc} Given Location: ${givenStorageLocation}`);\r\n }\r\n\r\n /**\r\n * Creates error thrown when redirect callbacks are not set before calling loginRedirect() or acquireTokenRedirect().\r\n */\r\n static createRedirectCallbacksNotSetError(): BrowserConfigurationAuthError {\r\n return new BrowserConfigurationAuthError(BrowserConfigurationAuthErrorMessage.noRedirectCallbacksSet.code, \r\n BrowserConfigurationAuthErrorMessage.noRedirectCallbacksSet.desc);\r\n }\r\n\r\n /**\r\n * Creates error thrown when the stub instance of PublicClientApplication is called.\r\n */\r\n static createStubPcaInstanceCalledError(): BrowserConfigurationAuthError {\r\n return new BrowserConfigurationAuthError(BrowserConfigurationAuthErrorMessage.stubPcaInstanceCalled.code,\r\n BrowserConfigurationAuthErrorMessage.stubPcaInstanceCalled.desc);\r\n }\r\n\r\n /*\r\n * Create an error thrown when in-memory storage is used and storeAuthStateInCookie=false.\r\n */\r\n static createInMemoryRedirectUnavailableError(): BrowserConfigurationAuthError {\r\n return new BrowserConfigurationAuthError(BrowserConfigurationAuthErrorMessage.inMemRedirectUnavailable.code, BrowserConfigurationAuthErrorMessage.inMemRedirectUnavailable.desc);\r\n }\r\n \r\n /**\r\n * Creates an error thrown when a crypto interface that requires entropy is initialized without entropy\r\n */\r\n static createEntropyNotProvided(): BrowserConfigurationAuthError {\r\n return new BrowserConfigurationAuthError(BrowserConfigurationAuthErrorMessage.entropyNotProvided.code, BrowserConfigurationAuthErrorMessage.entropyNotProvided.desc);\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { AuthenticationResult, AccountInfo, Logger, PerformanceCallbackFunction } from \"@azure/msal-common\";\r\nimport { RedirectRequest } from \"../request/RedirectRequest\";\r\nimport { PopupRequest } from \"../request/PopupRequest\";\r\nimport { SilentRequest } from \"../request/SilentRequest\";\r\nimport { SsoSilentRequest } from \"../request/SsoSilentRequest\";\r\nimport { EndSessionRequest } from \"../request/EndSessionRequest\";\r\nimport { BrowserConfigurationAuthError } from \"../error/BrowserConfigurationAuthError\";\r\nimport { WrapperSKU } from \"../utils/BrowserConstants\";\r\nimport { INavigationClient } from \"../navigation/INavigationClient\";\r\nimport { EndSessionPopupRequest } from \"../request/EndSessionPopupRequest\";\r\nimport { ITokenCache } from \"../cache/ITokenCache\";\r\nimport { AuthorizationCodeRequest } from \"../request/AuthorizationCodeRequest\";\r\nimport { BrowserConfiguration } from \"../config/Configuration\";\r\n\r\nexport interface IPublicClientApplication {\r\n initialize(): Promise;\r\n acquireTokenPopup(request: PopupRequest): Promise;\r\n acquireTokenRedirect(request: RedirectRequest): Promise;\r\n acquireTokenSilent(silentRequest: SilentRequest): Promise;\r\n acquireTokenByCode(request: AuthorizationCodeRequest): Promise;\r\n addEventCallback(callback: Function): string | null;\r\n removeEventCallback(callbackId: string): void;\r\n addPerformanceCallback(callback: PerformanceCallbackFunction): string;\r\n removePerformanceCallback(callbackId: string): boolean;\r\n enableAccountStorageEvents(): void;\r\n disableAccountStorageEvents(): void;\r\n getAccountByHomeId(homeAccountId: string): AccountInfo | null;\r\n getAccountByLocalId(localId: string): AccountInfo | null;\r\n getAccountByUsername(userName: string): AccountInfo | null;\r\n getAllAccounts(): AccountInfo[];\r\n handleRedirectPromise(hash?: string): Promise;\r\n loginPopup(request?: PopupRequest): Promise;\r\n loginRedirect(request?: RedirectRequest): Promise;\r\n logout(logoutRequest?: EndSessionRequest): Promise;\r\n logoutRedirect(logoutRequest?: EndSessionRequest): Promise;\r\n logoutPopup(logoutRequest?: EndSessionPopupRequest): Promise;\r\n ssoSilent(request: SsoSilentRequest): Promise;\r\n getTokenCache(): ITokenCache;\r\n getLogger(): Logger;\r\n setLogger(logger: Logger): void;\r\n setActiveAccount(account: AccountInfo | null): void;\r\n getActiveAccount(): AccountInfo | null;\r\n initializeWrapperLibrary(sku: WrapperSKU, version: string): void;\r\n setNavigationClient(navigationClient: INavigationClient): void;\r\n getConfiguration(): BrowserConfiguration;\r\n hydrateCache(\r\n result: AuthenticationResult,\r\n request: SilentRequest\r\n | SsoSilentRequest\r\n | RedirectRequest\r\n | PopupRequest\r\n ): Promise;\r\n}\r\n\r\nexport const stubbedPublicClientApplication: IPublicClientApplication = {\r\n initialize: () => {\r\n return Promise.reject(BrowserConfigurationAuthError.createStubPcaInstanceCalledError());\r\n },\r\n acquireTokenPopup: () => {\r\n return Promise.reject(BrowserConfigurationAuthError.createStubPcaInstanceCalledError());\r\n },\r\n acquireTokenRedirect: () => {\t\r\n return Promise.reject(BrowserConfigurationAuthError.createStubPcaInstanceCalledError());\t\r\n },\t\r\n acquireTokenSilent: () => {\t\r\n return Promise.reject(BrowserConfigurationAuthError.createStubPcaInstanceCalledError());\t\r\n },\r\n acquireTokenByCode: () => {\r\n return Promise.reject(BrowserConfigurationAuthError.createStubPcaInstanceCalledError());\r\n },\r\n getAllAccounts: () => {\r\n return [];\t\r\n },\t\r\n getAccountByHomeId: () => {\r\n return null;\r\n },\r\n getAccountByUsername: () => {\t\r\n return null;\t\r\n },\t\r\n getAccountByLocalId: () => {\r\n return null;\r\n },\r\n handleRedirectPromise: () => {\t\r\n return Promise.reject(BrowserConfigurationAuthError.createStubPcaInstanceCalledError());\t\r\n },\t\r\n loginPopup: () => {\t\r\n return Promise.reject(BrowserConfigurationAuthError.createStubPcaInstanceCalledError());\t\r\n },\t\r\n loginRedirect: () => {\t\r\n return Promise.reject(BrowserConfigurationAuthError.createStubPcaInstanceCalledError());\t\r\n },\t\r\n logout: () => {\t\r\n return Promise.reject(BrowserConfigurationAuthError.createStubPcaInstanceCalledError());\t\r\n },\t\r\n logoutRedirect: () => {\t\r\n return Promise.reject(BrowserConfigurationAuthError.createStubPcaInstanceCalledError());\t\r\n },\r\n logoutPopup: () => {\t\r\n return Promise.reject(BrowserConfigurationAuthError.createStubPcaInstanceCalledError());\t\r\n },\r\n ssoSilent: () => {\t\r\n return Promise.reject(BrowserConfigurationAuthError.createStubPcaInstanceCalledError());\t\r\n },\r\n addEventCallback: () => {\r\n return null;\r\n },\r\n removeEventCallback: () => {\r\n return;\r\n },\r\n addPerformanceCallback: () => {\r\n return \"\";\r\n },\r\n removePerformanceCallback: () => {\r\n return false;\r\n },\r\n enableAccountStorageEvents: () => {\r\n return;\r\n },\r\n disableAccountStorageEvents: () => {\r\n return;\r\n },\r\n getTokenCache: () => {\r\n throw BrowserConfigurationAuthError.createStubPcaInstanceCalledError();\r\n },\r\n getLogger: () => {\r\n throw BrowserConfigurationAuthError.createStubPcaInstanceCalledError();\r\n },\r\n setLogger: () => {\r\n return;\r\n },\r\n setActiveAccount: () => {\r\n return;\r\n },\r\n getActiveAccount: () => {\r\n return null;\r\n },\r\n initializeWrapperLibrary: () => {\r\n return;\r\n },\r\n setNavigationClient: () => {\r\n return;\r\n },\r\n getConfiguration: () => {\r\n throw BrowserConfigurationAuthError.createStubPcaInstanceCalledError();\r\n },\r\n hydrateCache: () => {\r\n return Promise.reject(\r\n BrowserConfigurationAuthError.createStubPcaInstanceCalledError()\r\n );\r\n },\r\n};\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { AuthError } from \"./AuthError\";\r\n\r\n/**\r\n * ClientAuthErrorMessage class containing string constants used by error codes and messages.\r\n */\r\nexport const ClientAuthErrorMessage = {\r\n clientInfoDecodingError: {\r\n code: \"client_info_decoding_error\",\r\n desc: \"The client info could not be parsed/decoded correctly. Please review the trace to determine the root cause.\"\r\n },\r\n clientInfoEmptyError: {\r\n code: \"client_info_empty_error\",\r\n desc: \"The client info was empty. Please review the trace to determine the root cause.\"\r\n },\r\n tokenParsingError: {\r\n code: \"token_parsing_error\",\r\n desc: \"Token cannot be parsed. Please review stack trace to determine root cause.\"\r\n },\r\n nullOrEmptyToken: {\r\n code: \"null_or_empty_token\",\r\n desc: \"The token is null or empty. Please review the trace to determine the root cause.\"\r\n },\r\n endpointResolutionError: {\r\n code: \"endpoints_resolution_error\",\r\n desc: \"Error: could not resolve endpoints. Please check network and try again.\"\r\n },\r\n networkError: {\r\n code: \"network_error\",\r\n desc: \"Network request failed. Please check network trace to determine root cause.\"\r\n },\r\n unableToGetOpenidConfigError: {\r\n code: \"openid_config_error\",\r\n desc: \"Could not retrieve endpoints. Check your authority and verify the .well-known/openid-configuration endpoint returns the required endpoints.\"\r\n },\r\n hashNotDeserialized: {\r\n code: \"hash_not_deserialized\",\r\n desc: \"The hash parameters could not be deserialized. Please review the trace to determine the root cause.\"\r\n },\r\n blankGuidGenerated: {\r\n code: \"blank_guid_generated\",\r\n desc: \"The guid generated was blank. Please review the trace to determine the root cause.\"\r\n },\r\n invalidStateError: {\r\n code: \"invalid_state\",\r\n desc: \"State was not the expected format. Please check the logs to determine whether the request was sent using ProtocolUtils.setRequestState().\"\r\n },\r\n stateMismatchError: {\r\n code: \"state_mismatch\",\r\n desc: \"State mismatch error. Please check your network. Continued requests may cause cache overflow.\"\r\n },\r\n stateNotFoundError: {\r\n code: \"state_not_found\",\r\n desc: \"State not found\"\r\n },\r\n nonceMismatchError: {\r\n code: \"nonce_mismatch\",\r\n desc: \"Nonce mismatch error. This may be caused by a race condition in concurrent requests.\"\r\n },\r\n nonceNotFoundError: {\r\n code: \"nonce_not_found\",\r\n desc: \"nonce not found\"\r\n },\r\n authTimeNotFoundError: {\r\n code: \"auth_time_not_found\",\r\n desc: \"Max Age was requested and the ID token is missing the auth_time variable.\" +\r\n \" auth_time is an optional claim and is not enabled by default - it must be enabled.\" +\r\n \" See https://aka.ms/msaljs/optional-claims for more information.\"\r\n },\r\n maxAgeTranspiredError: {\r\n code: \"max_age_transpired\",\r\n desc: \"Max Age is set to 0, or too much time has elapsed since the last end-user authentication.\"\r\n },\r\n noTokensFoundError: {\r\n code: \"no_tokens_found\",\r\n desc: \"No tokens were found for the given scopes, and no authorization code was passed to acquireToken. You must retrieve an authorization code before making a call to acquireToken().\"\r\n },\r\n multipleMatchingTokens: {\r\n code: \"multiple_matching_tokens\",\r\n desc: \"The cache contains multiple tokens satisfying the requirements. \" +\r\n \"Call AcquireToken again providing more requirements such as authority or account.\"\r\n },\r\n multipleMatchingAccounts: {\r\n code: \"multiple_matching_accounts\",\r\n desc: \"The cache contains multiple accounts satisfying the given parameters. Please pass more info to obtain the correct account\"\r\n },\r\n multipleMatchingAppMetadata: {\r\n code: \"multiple_matching_appMetadata\",\r\n desc: \"The cache contains multiple appMetadata satisfying the given parameters. Please pass more info to obtain the correct appMetadata\"\r\n },\r\n tokenRequestCannotBeMade: {\r\n code: \"request_cannot_be_made\",\r\n desc: \"Token request cannot be made without authorization code or refresh token.\"\r\n },\r\n appendEmptyScopeError: {\r\n code: \"cannot_append_empty_scope\",\r\n desc: \"Cannot append null or empty scope to ScopeSet. Please check the stack trace for more info.\"\r\n },\r\n removeEmptyScopeError: {\r\n code: \"cannot_remove_empty_scope\",\r\n desc: \"Cannot remove null or empty scope from ScopeSet. Please check the stack trace for more info.\"\r\n },\r\n appendScopeSetError: {\r\n code: \"cannot_append_scopeset\",\r\n desc: \"Cannot append ScopeSet due to error.\"\r\n },\r\n emptyInputScopeSetError: {\r\n code: \"empty_input_scopeset\",\r\n desc: \"Empty input ScopeSet cannot be processed.\"\r\n },\r\n DeviceCodePollingCancelled: {\r\n code: \"device_code_polling_cancelled\",\r\n desc: \"Caller has cancelled token endpoint polling during device code flow by setting DeviceCodeRequest.cancel = true.\"\r\n },\r\n DeviceCodeExpired: {\r\n code: \"device_code_expired\",\r\n desc: \"Device code is expired.\"\r\n },\r\n DeviceCodeUnknownError: {\r\n code: \"device_code_unknown_error\",\r\n desc: \"Device code stopped polling for unknown reasons.\"\r\n },\r\n NoAccountInSilentRequest: {\r\n code: \"no_account_in_silent_request\",\r\n desc: \"Please pass an account object, silent flow is not supported without account information\"\r\n },\r\n invalidCacheRecord: {\r\n code: \"invalid_cache_record\",\r\n desc: \"Cache record object was null or undefined.\"\r\n },\r\n invalidCacheEnvironment: {\r\n code: \"invalid_cache_environment\",\r\n desc: \"Invalid environment when attempting to create cache entry\"\r\n },\r\n noAccountFound: {\r\n code: \"no_account_found\",\r\n desc: \"No account found in cache for given key.\"\r\n },\r\n CachePluginError: {\r\n code: \"no cache plugin set on CacheManager\",\r\n desc: \"ICachePlugin needs to be set before using readFromStorage or writeFromStorage\"\r\n },\r\n noCryptoObj: {\r\n code: \"no_crypto_object\",\r\n desc: \"No crypto object detected. This is required for the following operation: \"\r\n },\r\n invalidCacheType: {\r\n code: \"invalid_cache_type\",\r\n desc: \"Invalid cache type\"\r\n },\r\n unexpectedAccountType: {\r\n code: \"unexpected_account_type\",\r\n desc: \"Unexpected account type.\"\r\n },\r\n unexpectedCredentialType: {\r\n code: \"unexpected_credential_type\",\r\n desc: \"Unexpected credential type.\"\r\n },\r\n invalidAssertion: {\r\n code: \"invalid_assertion\",\r\n desc: \"Client assertion must meet requirements described in https://tools.ietf.org/html/rfc7515\"\r\n },\r\n invalidClientCredential: {\r\n code: \"invalid_client_credential\",\r\n desc: \"Client credential (secret, certificate, or assertion) must not be empty when creating a confidential client. An application should at most have one credential\"\r\n },\r\n tokenRefreshRequired: {\r\n code: \"token_refresh_required\",\r\n desc: \"Cannot return token from cache because it must be refreshed. This may be due to one of the following reasons: forceRefresh parameter is set to true, claims have been requested, there is no cached access token or it is expired.\"\r\n },\r\n userTimeoutReached: {\r\n code: \"user_timeout_reached\",\r\n desc: \"User defined timeout for device code polling reached\",\r\n },\r\n tokenClaimsRequired: {\r\n code: \"token_claims_cnf_required_for_signedjwt\",\r\n desc: \"Cannot generate a POP jwt if the token_claims are not populated\"\r\n },\r\n noAuthorizationCodeFromServer: {\r\n code: \"authorization_code_missing_from_server_response\",\r\n desc: \"Server response does not contain an authorization code to proceed\"\r\n },\r\n noAzureRegionDetected: {\r\n code: \"no_azure_region_detected\",\r\n desc: \"No azure region was detected and no fallback was made available\"\r\n },\r\n accessTokenEntityNullError: {\r\n code: \"access_token_entity_null\",\r\n desc: \"Access token entity is null, please check logs and cache to ensure a valid access token is present.\"\r\n },\r\n bindingKeyNotRemovedError: {\r\n code: \"binding_key_not_removed\",\r\n desc: \"Could not remove the credential's binding key from storage.\"\r\n },\r\n logoutNotSupported: {\r\n code: \"end_session_endpoint_not_supported\",\r\n desc: \"Provided authority does not support logout.\"\r\n },\r\n keyIdMissing: {\r\n code: \"key_id_missing\",\r\n desc: \"A keyId value is missing from the requested bound token's cache record and is required to match the token to it's stored binding key.\"\r\n },\r\n noNetworkConnectivity: {\r\n code: \"no_network_connectivity\",\r\n desc: \"No network connectivity. Check your internet connection.\"\r\n },\r\n userCanceledError: {\r\n code: \"user_canceled\",\r\n desc: \"User canceled the flow.\"\r\n }\r\n};\r\n\r\n/**\r\n * Error thrown when there is an error in the client code running on the browser.\r\n */\r\nexport class ClientAuthError extends AuthError {\r\n\r\n constructor(errorCode: string, errorMessage?: string) {\r\n super(errorCode, errorMessage);\r\n this.name = \"ClientAuthError\";\r\n\r\n Object.setPrototypeOf(this, ClientAuthError.prototype);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when client info object doesn't decode correctly.\r\n * @param caughtError\r\n */\r\n static createClientInfoDecodingError(caughtError: string): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.clientInfoDecodingError.code,\r\n `${ClientAuthErrorMessage.clientInfoDecodingError.desc} Failed with error: ${caughtError}`);\r\n }\r\n\r\n /**\r\n * Creates an error thrown if the client info is empty.\r\n * @param rawClientInfo\r\n */\r\n static createClientInfoEmptyError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.clientInfoEmptyError.code,\r\n `${ClientAuthErrorMessage.clientInfoEmptyError.desc}`);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the id token extraction errors out.\r\n * @param err\r\n */\r\n static createTokenParsingError(caughtExtractionError: string): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.tokenParsingError.code,\r\n `${ClientAuthErrorMessage.tokenParsingError.desc} Failed with error: ${caughtExtractionError}`);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the id token string is null or empty.\r\n * @param invalidRawTokenString\r\n */\r\n static createTokenNullOrEmptyError(invalidRawTokenString: string): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.nullOrEmptyToken.code,\r\n `${ClientAuthErrorMessage.nullOrEmptyToken.desc} Raw Token Value: ${invalidRawTokenString}`);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the endpoint discovery doesn't complete correctly.\r\n */\r\n static createEndpointDiscoveryIncompleteError(errDetail: string): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.endpointResolutionError.code,\r\n `${ClientAuthErrorMessage.endpointResolutionError.desc} Detail: ${errDetail}`);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the fetch client throws\r\n */\r\n static createNetworkError(endpoint: string, errDetail: string): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.networkError.code,\r\n `${ClientAuthErrorMessage.networkError.desc} | Fetch client threw: ${errDetail} | Attempted to reach: ${endpoint.split(\"?\")[0]}`);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the openid-configuration endpoint cannot be reached or does not contain the required data\r\n */\r\n static createUnableToGetOpenidConfigError(errDetail: string): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.unableToGetOpenidConfigError.code,\r\n `${ClientAuthErrorMessage.unableToGetOpenidConfigError.desc} Attempted to retrieve endpoints from: ${errDetail}`);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the hash cannot be deserialized.\r\n * @param hashParamObj\r\n */\r\n static createHashNotDeserializedError(hashParamObj: string): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.hashNotDeserialized.code,\r\n `${ClientAuthErrorMessage.hashNotDeserialized.desc} Given Object: ${hashParamObj}`);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the state cannot be parsed.\r\n * @param invalidState\r\n */\r\n static createInvalidStateError(invalidState: string, errorString?: string): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.invalidStateError.code,\r\n `${ClientAuthErrorMessage.invalidStateError.desc} Invalid State: ${invalidState}, Root Err: ${errorString}`);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when two states do not match.\r\n */\r\n static createStateMismatchError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.stateMismatchError.code,\r\n ClientAuthErrorMessage.stateMismatchError.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the state is not present\r\n * @param missingState\r\n */\r\n static createStateNotFoundError(missingState: string): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.stateNotFoundError.code,\r\n `${ClientAuthErrorMessage.stateNotFoundError.desc}: ${missingState}`);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the nonce does not match.\r\n */\r\n static createNonceMismatchError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.nonceMismatchError.code,\r\n ClientAuthErrorMessage.nonceMismatchError.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when max_age was provided in the request, but auth_time is not in the token claims\r\n * @param missingNonce\r\n */\r\n static createAuthTimeNotFoundError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.authTimeNotFoundError.code,\r\n ClientAuthErrorMessage.authTimeNotFoundError.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when too much time has elapsed since the last end-user authentication\r\n */\r\n static createMaxAgeTranspiredError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.maxAgeTranspiredError.code,\r\n ClientAuthErrorMessage.maxAgeTranspiredError.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the mnonce is not present\r\n * @param missingNonce\r\n */\r\n static createNonceNotFoundError(missingNonce: string): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.nonceNotFoundError.code,\r\n `${ClientAuthErrorMessage.nonceNotFoundError.desc}: ${missingNonce}`);\r\n }\r\n\r\n /**\r\n * Throws error when multiple tokens are in cache.\r\n */\r\n static createMultipleMatchingTokensInCacheError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.multipleMatchingTokens.code,\r\n `${ClientAuthErrorMessage.multipleMatchingTokens.desc}.`);\r\n }\r\n\r\n /**\r\n * Throws error when multiple accounts are in cache for the given params\r\n */\r\n static createMultipleMatchingAccountsInCacheError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.multipleMatchingAccounts.code,\r\n ClientAuthErrorMessage.multipleMatchingAccounts.desc);\r\n }\r\n\r\n /**\r\n * Throws error when multiple appMetada are in cache for the given clientId.\r\n */\r\n static createMultipleMatchingAppMetadataInCacheError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.multipleMatchingAppMetadata.code,\r\n ClientAuthErrorMessage.multipleMatchingAppMetadata.desc);\r\n }\r\n\r\n /**\r\n * Throws error when no auth code or refresh token is given to ServerTokenRequestParameters.\r\n */\r\n static createTokenRequestCannotBeMadeError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.tokenRequestCannotBeMade.code, ClientAuthErrorMessage.tokenRequestCannotBeMade.desc);\r\n }\r\n\r\n /**\r\n * Throws error when attempting to append a null, undefined or empty scope to a set\r\n * @param givenScope\r\n */\r\n static createAppendEmptyScopeToSetError(givenScope: string): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.appendEmptyScopeError.code, `${ClientAuthErrorMessage.appendEmptyScopeError.desc} Given Scope: ${givenScope}`);\r\n }\r\n\r\n /**\r\n * Throws error when attempting to append a null, undefined or empty scope to a set\r\n * @param givenScope\r\n */\r\n static createRemoveEmptyScopeFromSetError(givenScope: string): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.removeEmptyScopeError.code, `${ClientAuthErrorMessage.removeEmptyScopeError.desc} Given Scope: ${givenScope}`);\r\n }\r\n\r\n /**\r\n * Throws error when attempting to append null or empty ScopeSet.\r\n * @param appendError\r\n */\r\n static createAppendScopeSetError(appendError: string): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.appendScopeSetError.code, `${ClientAuthErrorMessage.appendScopeSetError.desc} Detail Error: ${appendError}`);\r\n }\r\n\r\n /**\r\n * Throws error if ScopeSet is null or undefined.\r\n * @param givenScopeSet\r\n */\r\n static createEmptyInputScopeSetError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.emptyInputScopeSetError.code, `${ClientAuthErrorMessage.emptyInputScopeSetError.desc}`);\r\n }\r\n\r\n /**\r\n * Throws error if user sets CancellationToken.cancel = true during polling of token endpoint during device code flow\r\n */\r\n static createDeviceCodeCancelledError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.DeviceCodePollingCancelled.code, `${ClientAuthErrorMessage.DeviceCodePollingCancelled.desc}`);\r\n }\r\n\r\n /**\r\n * Throws error if device code is expired\r\n */\r\n static createDeviceCodeExpiredError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.DeviceCodeExpired.code, `${ClientAuthErrorMessage.DeviceCodeExpired.desc}`);\r\n }\r\n\r\n /**\r\n * Throws error if device code is expired\r\n */\r\n static createDeviceCodeUnknownError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.DeviceCodeUnknownError.code, `${ClientAuthErrorMessage.DeviceCodeUnknownError.desc}`);\r\n }\r\n\r\n /**\r\n * Throws error when silent requests are made without an account object\r\n */\r\n static createNoAccountInSilentRequestError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.NoAccountInSilentRequest.code, `${ClientAuthErrorMessage.NoAccountInSilentRequest.desc}`);\r\n }\r\n\r\n /**\r\n * Throws error when cache record is null or undefined.\r\n */\r\n static createNullOrUndefinedCacheRecord(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.invalidCacheRecord.code, ClientAuthErrorMessage.invalidCacheRecord.desc);\r\n }\r\n\r\n /**\r\n * Throws error when provided environment is not part of the CloudDiscoveryMetadata object\r\n */\r\n static createInvalidCacheEnvironmentError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.invalidCacheEnvironment.code, ClientAuthErrorMessage.invalidCacheEnvironment.desc);\r\n }\r\n\r\n /**\r\n * Throws error when account is not found in cache.\r\n */\r\n static createNoAccountFoundError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.noAccountFound.code, ClientAuthErrorMessage.noAccountFound.desc);\r\n }\r\n\r\n /**\r\n * Throws error if ICachePlugin not set on CacheManager.\r\n */\r\n static createCachePluginError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.CachePluginError.code, `${ClientAuthErrorMessage.CachePluginError.desc}`);\r\n }\r\n\r\n /**\r\n * Throws error if crypto object not found.\r\n * @param operationName\r\n */\r\n static createNoCryptoObjectError(operationName: string): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.noCryptoObj.code, `${ClientAuthErrorMessage.noCryptoObj.desc}${operationName}`);\r\n }\r\n\r\n /**\r\n * Throws error if cache type is invalid.\r\n */\r\n static createInvalidCacheTypeError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.invalidCacheType.code, `${ClientAuthErrorMessage.invalidCacheType.desc}`);\r\n }\r\n\r\n /**\r\n * Throws error if unexpected account type.\r\n */\r\n static createUnexpectedAccountTypeError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.unexpectedAccountType.code, `${ClientAuthErrorMessage.unexpectedAccountType.desc}`);\r\n }\r\n\r\n /**\r\n * Throws error if unexpected credential type.\r\n */\r\n static createUnexpectedCredentialTypeError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.unexpectedCredentialType.code, `${ClientAuthErrorMessage.unexpectedCredentialType.desc}`);\r\n }\r\n\r\n /**\r\n * Throws error if client assertion is not valid.\r\n */\r\n static createInvalidAssertionError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.invalidAssertion.code, `${ClientAuthErrorMessage.invalidAssertion.desc}`);\r\n }\r\n\r\n /**\r\n * Throws error if client assertion is not valid.\r\n */\r\n static createInvalidCredentialError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.invalidClientCredential.code, `${ClientAuthErrorMessage.invalidClientCredential.desc}`);\r\n }\r\n\r\n /**\r\n * Throws error if token cannot be retrieved from cache due to refresh being required.\r\n */\r\n static createRefreshRequiredError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.tokenRefreshRequired.code, ClientAuthErrorMessage.tokenRefreshRequired.desc);\r\n }\r\n\r\n /**\r\n * Throws error if the user defined timeout is reached.\r\n */\r\n static createUserTimeoutReachedError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.userTimeoutReached.code, ClientAuthErrorMessage.userTimeoutReached.desc);\r\n }\r\n\r\n /*\r\n * Throws error if token claims are not populated for a signed jwt generation\r\n */\r\n static createTokenClaimsRequiredError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.tokenClaimsRequired.code, ClientAuthErrorMessage.tokenClaimsRequired.desc);\r\n }\r\n\r\n /**\r\n * Throws error when the authorization code is missing from the server response\r\n */\r\n static createNoAuthCodeInServerResponseError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.noAuthorizationCodeFromServer.code, ClientAuthErrorMessage.noAuthorizationCodeFromServer.desc);\r\n }\r\n\r\n static createBindingKeyNotRemovedError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.bindingKeyNotRemovedError.code, ClientAuthErrorMessage.bindingKeyNotRemovedError.desc);\r\n }\r\n\r\n /**\r\n * Thrown when logout is attempted for an authority that doesnt have an end_session_endpoint\r\n */\r\n static createLogoutNotSupportedError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.logoutNotSupported.code, ClientAuthErrorMessage.logoutNotSupported.desc);\r\n }\r\n\r\n /**\r\n * Create an error when kid attribute is missing from a PoP token's cache record\r\n */\r\n static createKeyIdMissingError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.keyIdMissing.code, ClientAuthErrorMessage.keyIdMissing.desc);\r\n }\r\n\r\n /**\r\n * Create an error when the client does not have network connectivity\r\n */\r\n static createNoNetworkConnectivityError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.noNetworkConnectivity.code, ClientAuthErrorMessage.noNetworkConnectivity.desc);\r\n }\r\n\r\n /**\r\n * Create an error when the user cancels the flow\r\n */\r\n static createUserCanceledError(): ClientAuthError {\r\n return new ClientAuthError(ClientAuthErrorMessage.userCanceledError.code, ClientAuthErrorMessage.userCanceledError.desc);\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { StringUtils } from \"../utils/StringUtils\";\r\nimport { LoggerOptions } from \"../config/ClientConfiguration\";\r\nimport { Constants } from \"../utils/Constants\";\r\n\r\n/**\r\n * Options for logger messages.\r\n */\r\nexport type LoggerMessageOptions = {\r\n logLevel: LogLevel,\r\n containsPii?: boolean,\r\n context?: string,\r\n correlationId?: string\r\n};\r\n\r\n/**\r\n * Log message level.\r\n */\r\nexport enum LogLevel {\r\n Error,\r\n Warning,\r\n Info,\r\n Verbose,\r\n Trace\r\n}\r\n\r\n/**\r\n * Callback to send the messages to.\r\n */\r\nexport interface ILoggerCallback {\r\n (level: LogLevel, message: string, containsPii: boolean): void;\r\n}\r\n\r\n/**\r\n * Class which facilitates logging of messages to a specific place.\r\n */\r\nexport class Logger {\r\n\r\n // Correlation ID for request, usually set by user.\r\n private correlationId: string;\r\n\r\n // Current log level, defaults to info.\r\n private level: LogLevel = LogLevel.Info;\r\n\r\n // Boolean describing whether PII logging is allowed.\r\n private piiLoggingEnabled: boolean;\r\n\r\n // Callback to send messages to.\r\n private localCallback: ILoggerCallback;\r\n\r\n // Package name implementing this logger\r\n private packageName: string;\r\n\r\n // Package version implementing this logger\r\n private packageVersion: string;\r\n\r\n constructor(loggerOptions: LoggerOptions, packageName?: string, packageVersion?: string) {\r\n const defaultLoggerCallback = () => {\r\n return;\r\n };\r\n const setLoggerOptions = loggerOptions || Logger.createDefaultLoggerOptions();\r\n this.localCallback = setLoggerOptions.loggerCallback || defaultLoggerCallback;\r\n this.piiLoggingEnabled = setLoggerOptions.piiLoggingEnabled || false;\r\n this.level = typeof(setLoggerOptions.logLevel) === \"number\" ? setLoggerOptions.logLevel : LogLevel.Info;\r\n this.correlationId = setLoggerOptions.correlationId || Constants.EMPTY_STRING;\r\n this.packageName = packageName || Constants.EMPTY_STRING;\r\n this.packageVersion = packageVersion || Constants.EMPTY_STRING;\r\n }\r\n \r\n private static createDefaultLoggerOptions(): LoggerOptions {\r\n return {\r\n loggerCallback: () => {\r\n // allow users to not set loggerCallback\r\n },\r\n piiLoggingEnabled: false,\r\n logLevel: LogLevel.Info\r\n };\r\n }\r\n\r\n /**\r\n * Create new Logger with existing configurations.\r\n */\r\n public clone(packageName: string, packageVersion: string, correlationId?: string): Logger {\r\n return new Logger({loggerCallback: this.localCallback, piiLoggingEnabled: this.piiLoggingEnabled, logLevel: this.level, correlationId: correlationId || this.correlationId}, packageName, packageVersion);\r\n }\r\n\r\n /**\r\n * Log message with required options.\r\n */\r\n private logMessage(logMessage: string, options: LoggerMessageOptions): void {\r\n if ((options.logLevel > this.level) || (!this.piiLoggingEnabled && options.containsPii)) {\r\n return;\r\n }\r\n const timestamp = new Date().toUTCString();\r\n\r\n // Add correlationId to logs if set, correlationId provided on log messages take precedence\r\n let logHeader: string;\r\n if (!StringUtils.isEmpty(options.correlationId)) {\r\n logHeader = `[${timestamp}] : [${options.correlationId}]`;\r\n } else if (!StringUtils.isEmpty(this.correlationId)) {\r\n logHeader = `[${timestamp}] : [${this.correlationId}]`;\r\n } else {\r\n logHeader = `[${timestamp}]`;\r\n }\r\n\r\n const log = `${logHeader} : ${this.packageName}@${this.packageVersion} : ${LogLevel[options.logLevel]} - ${logMessage}`;\r\n // debug(`msal:${LogLevel[options.logLevel]}${options.containsPii ? \"-Pii\": Constants.EMPTY_STRING}${options.context ? `:${options.context}` : Constants.EMPTY_STRING}`)(logMessage);\r\n this.executeCallback(options.logLevel, log, options.containsPii || false);\r\n }\r\n\r\n /**\r\n * Execute callback with message.\r\n */\r\n executeCallback(level: LogLevel, message: string, containsPii: boolean): void {\r\n if (this.localCallback) {\r\n this.localCallback(level, message, containsPii);\r\n }\r\n }\r\n\r\n /**\r\n * Logs error messages.\r\n */\r\n error(message: string, correlationId?: string): void {\r\n this.logMessage(message, {\r\n logLevel: LogLevel.Error,\r\n containsPii: false,\r\n correlationId: correlationId || Constants.EMPTY_STRING\r\n });\r\n }\r\n\r\n /**\r\n * Logs error messages with PII.\r\n */\r\n errorPii(message: string, correlationId?: string): void {\r\n this.logMessage(message, {\r\n logLevel: LogLevel.Error,\r\n containsPii: true,\r\n correlationId: correlationId || Constants.EMPTY_STRING\r\n });\r\n }\r\n\r\n /**\r\n * Logs warning messages.\r\n */\r\n warning(message: string, correlationId?: string): void {\r\n this.logMessage(message, {\r\n logLevel: LogLevel.Warning,\r\n containsPii: false,\r\n correlationId: correlationId || Constants.EMPTY_STRING\r\n });\r\n }\r\n\r\n /**\r\n * Logs warning messages with PII.\r\n */\r\n warningPii(message: string, correlationId?: string): void {\r\n this.logMessage(message, {\r\n logLevel: LogLevel.Warning,\r\n containsPii: true,\r\n correlationId: correlationId || Constants.EMPTY_STRING\r\n });\r\n }\r\n\r\n /**\r\n * Logs info messages.\r\n */\r\n info(message: string, correlationId?: string): void {\r\n this.logMessage(message, {\r\n logLevel: LogLevel.Info,\r\n containsPii: false,\r\n correlationId: correlationId || Constants.EMPTY_STRING\r\n });\r\n }\r\n\r\n /**\r\n * Logs info messages with PII.\r\n */\r\n infoPii(message: string, correlationId?: string): void {\r\n this.logMessage(message, {\r\n logLevel: LogLevel.Info,\r\n containsPii: true,\r\n correlationId: correlationId || Constants.EMPTY_STRING\r\n });\r\n }\r\n\r\n /**\r\n * Logs verbose messages.\r\n */\r\n verbose(message: string, correlationId?: string): void {\r\n this.logMessage(message, {\r\n logLevel: LogLevel.Verbose,\r\n containsPii: false,\r\n correlationId: correlationId || Constants.EMPTY_STRING\r\n });\r\n }\r\n\r\n /**\r\n * Logs verbose messages with PII.\r\n */\r\n verbosePii(message: string, correlationId?: string): void {\r\n this.logMessage(message, {\r\n logLevel: LogLevel.Verbose,\r\n containsPii: true,\r\n correlationId: correlationId || Constants.EMPTY_STRING\r\n });\r\n }\r\n\r\n /**\r\n * Logs trace messages.\r\n */\r\n trace(message: string, correlationId?: string): void {\r\n this.logMessage(message, {\r\n logLevel: LogLevel.Trace,\r\n containsPii: false,\r\n correlationId: correlationId || Constants.EMPTY_STRING\r\n });\r\n }\r\n\r\n /**\r\n * Logs trace messages with PII.\r\n */\r\n tracePii(message: string, correlationId?: string): void {\r\n this.logMessage(message, {\r\n logLevel: LogLevel.Trace,\r\n containsPii: true,\r\n correlationId: correlationId || Constants.EMPTY_STRING\r\n });\r\n }\r\n\r\n /**\r\n * Returns whether PII Logging is enabled or not.\r\n */\r\n isPiiLoggingEnabled(): boolean {\r\n return this.piiLoggingEnabled || false;\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { DecodedAuthToken } from \"../account/DecodedAuthToken\";\r\nimport { ClientAuthError } from \"../error/ClientAuthError\";\r\n\r\n/**\r\n * @hidden\r\n */\r\nexport class StringUtils {\r\n\r\n /**\r\n * decode a JWT\r\n *\r\n * @param authToken\r\n */\r\n static decodeAuthToken(authToken: string): DecodedAuthToken {\r\n if (StringUtils.isEmpty(authToken)) {\r\n throw ClientAuthError.createTokenNullOrEmptyError(authToken);\r\n }\r\n const tokenPartsRegex = /^([^\\.\\s]*)\\.([^\\.\\s]+)\\.([^\\.\\s]*)$/;\r\n const matches = tokenPartsRegex.exec(authToken);\r\n if (!matches || matches.length < 4) {\r\n throw ClientAuthError.createTokenParsingError(`Given token is malformed: ${JSON.stringify(authToken)}`);\r\n }\r\n const crackedToken: DecodedAuthToken = {\r\n header: matches[1],\r\n JWSPayload: matches[2],\r\n JWSSig: matches[3]\r\n };\r\n return crackedToken;\r\n }\r\n\r\n /**\r\n * Check if a string is empty.\r\n *\r\n * @param str\r\n */\r\n static isEmpty(str?: string): boolean {\r\n return (typeof str === \"undefined\" || !str || 0 === str.length);\r\n }\r\n\r\n /**\r\n * Check if stringified object is empty\r\n * @param strObj \r\n */\r\n static isEmptyObj(strObj?: string): boolean {\r\n if (strObj && !StringUtils.isEmpty(strObj)) {\r\n try {\r\n const obj = JSON.parse(strObj);\r\n return Object.keys(obj).length === 0;\r\n } catch (e) {}\r\n }\r\n return true;\r\n }\r\n\r\n static startsWith(str: string, search: string): boolean {\r\n return str.indexOf(search) === 0;\r\n }\r\n\r\n static endsWith(str: string, search: string): boolean {\r\n return (str.length >= search.length) && (str.lastIndexOf(search) === (str.length - search.length));\r\n }\r\n\r\n /**\r\n * Parses string into an object.\r\n *\r\n * @param query\r\n */\r\n static queryStringToObject(query: string): T {\r\n const obj: {} = {};\r\n const params = query.split(\"&\");\r\n const decode = (s: string) => decodeURIComponent(s.replace(/\\+/g, \" \"));\r\n params.forEach((pair) => {\r\n if (pair.trim()) {\r\n const [key, value] = pair.split(/=(.+)/g, 2); // Split on the first occurence of the '=' character\r\n if (key && value) {\r\n obj[decode(key)] = decode(value);\r\n }\r\n }\r\n });\r\n return obj as T;\r\n }\r\n\r\n /**\r\n * Trims entries in an array.\r\n *\r\n * @param arr\r\n */\r\n static trimArrayEntries(arr: Array): Array {\r\n return arr.map(entry => entry.trim());\r\n }\r\n\r\n /**\r\n * Removes empty strings from array\r\n * @param arr\r\n */\r\n static removeEmptyStringsFromArray(arr: Array): Array {\r\n return arr.filter(entry => {\r\n return !StringUtils.isEmpty(entry);\r\n });\r\n }\r\n\r\n /**\r\n * Attempts to parse a string into JSON\r\n * @param str\r\n */\r\n static jsonParseHelper(str: string): T | null {\r\n try {\r\n return JSON.parse(str) as T;\r\n } catch (e) {\r\n return null;\r\n }\r\n }\r\n\r\n /**\r\n * Tests if a given string matches a given pattern, with support for wildcards and queries.\r\n * @param pattern Wildcard pattern to string match. Supports \"*\" for wildcards and \"?\" for queries\r\n * @param input String to match against\r\n */\r\n static matchPattern(pattern: string, input: string): boolean {\r\n /**\r\n * Wildcard support: https://stackoverflow.com/a/3117248/4888559\r\n * Queries: replaces \"?\" in string with escaped \"\\?\" for regex test\r\n */\r\n const regex: RegExp = new RegExp(pattern.replace(/\\\\/g, \"\\\\\\\\\").replace(/\\*/g, \"[^ ]*\").replace(/\\?/g, \"\\\\\\?\")); // eslint-disable-line security/detect-non-literal-regexp\r\n\r\n return regex.test(input);\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nexport enum EventType {\r\n INITIALIZE_START = \"msal:initializeStart\",\r\n INITIALIZE_END = \"msal:initializeEnd\",\r\n ACCOUNT_ADDED = \"msal:accountAdded\",\r\n ACCOUNT_REMOVED = \"msal:accountRemoved\",\r\n LOGIN_START = \"msal:loginStart\",\r\n LOGIN_SUCCESS = \"msal:loginSuccess\",\r\n LOGIN_FAILURE = \"msal:loginFailure\",\r\n ACQUIRE_TOKEN_START = \"msal:acquireTokenStart\",\r\n ACQUIRE_TOKEN_SUCCESS = \"msal:acquireTokenSuccess\",\r\n ACQUIRE_TOKEN_FAILURE = \"msal:acquireTokenFailure\",\r\n ACQUIRE_TOKEN_NETWORK_START = \"msal:acquireTokenFromNetworkStart\",\r\n SSO_SILENT_START = \"msal:ssoSilentStart\",\r\n SSO_SILENT_SUCCESS = \"msal:ssoSilentSuccess\",\r\n SSO_SILENT_FAILURE = \"msal:ssoSilentFailure\",\r\n ACQUIRE_TOKEN_BY_CODE_START = \"msal:acquireTokenByCodeStart\",\r\n ACQUIRE_TOKEN_BY_CODE_SUCCESS = \"msal:acquireTokenByCodeSuccess\",\r\n ACQUIRE_TOKEN_BY_CODE_FAILURE = \"msal:acquireTokenByCodeFailure\",\r\n HANDLE_REDIRECT_START = \"msal:handleRedirectStart\",\r\n HANDLE_REDIRECT_END = \"msal:handleRedirectEnd\",\r\n POPUP_OPENED = \"msal:popupOpened\",\r\n LOGOUT_START = \"msal:logoutStart\",\r\n LOGOUT_SUCCESS = \"msal:logoutSuccess\",\r\n LOGOUT_FAILURE = \"msal:logoutFailure\",\r\n LOGOUT_END = \"msal:logoutEnd\",\r\n RESTORE_FROM_BFCACHE = \"msal:restoreFromBFCache\"\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { AuthenticationResult, AuthError, AccountInfo } from \"@azure/msal-common\";\r\nimport { EventType } from \"./EventType\";\r\nimport { InteractionStatus, InteractionType } from \"../utils/BrowserConstants\";\r\nimport { PopupRequest, RedirectRequest, SilentRequest, SsoSilentRequest, EndSessionRequest } from \"..\";\r\n\r\nexport type EventMessage = {\r\n eventType: EventType;\r\n interactionType: InteractionType | null;\r\n payload: EventPayload;\r\n error: EventError;\r\n timestamp: number;\r\n};\r\n\r\nexport type PopupEvent = {\r\n popupWindow: Window;\r\n};\r\n\r\nexport type EventPayload = AccountInfo | PopupRequest | RedirectRequest | SilentRequest | SsoSilentRequest | EndSessionRequest | AuthenticationResult | PopupEvent | null;\r\n\r\nexport type EventError = AuthError | Error | null;\r\n\r\nexport type EventCallbackFunction = (message: EventMessage) => void;\r\n\r\nexport class EventMessageUtils {\r\n\r\n /**\r\n * Gets interaction status from event message\r\n * @param message\r\n * @param currentStatus\r\n */\r\n static getInteractionStatusFromEvent(message: EventMessage, currentStatus?: InteractionStatus): InteractionStatus|null {\r\n switch (message.eventType) {\r\n case EventType.LOGIN_START:\r\n return InteractionStatus.Login;\r\n case EventType.SSO_SILENT_START:\r\n return InteractionStatus.SsoSilent;\r\n case EventType.ACQUIRE_TOKEN_START:\r\n if (message.interactionType === InteractionType.Redirect || message.interactionType === InteractionType.Popup) {\r\n return InteractionStatus.AcquireToken;\r\n }\r\n break;\r\n case EventType.HANDLE_REDIRECT_START:\r\n return InteractionStatus.HandleRedirect;\r\n case EventType.LOGOUT_START:\r\n return InteractionStatus.Logout;\r\n case EventType.SSO_SILENT_SUCCESS:\r\n case EventType.SSO_SILENT_FAILURE:\r\n if (currentStatus && currentStatus !== InteractionStatus.SsoSilent) {\r\n // Prevent this event from clearing any status other than ssoSilent\r\n break;\r\n }\r\n return InteractionStatus.None;\r\n case EventType.LOGOUT_END:\r\n if (currentStatus && currentStatus !== InteractionStatus.Logout) {\r\n // Prevent this event from clearing any status other than logout\r\n break;\r\n }\r\n return InteractionStatus.None;\r\n case EventType.HANDLE_REDIRECT_END:\r\n if (currentStatus && currentStatus !== InteractionStatus.HandleRedirect) {\r\n // Prevent this event from clearing any status other than handleRedirect\r\n break;\r\n }\r\n return InteractionStatus.None;\r\n case EventType.LOGIN_SUCCESS:\r\n case EventType.LOGIN_FAILURE:\r\n case EventType.ACQUIRE_TOKEN_SUCCESS:\r\n case EventType.ACQUIRE_TOKEN_FAILURE:\r\n case EventType.RESTORE_FROM_BFCACHE:\r\n if (message.interactionType === InteractionType.Redirect || message.interactionType === InteractionType.Popup) {\r\n if (currentStatus && currentStatus !== InteractionStatus.Login && currentStatus !== InteractionStatus.AcquireToken) {\r\n // Prevent this event from clearing any status other than login or acquireToken\r\n break;\r\n }\r\n return InteractionStatus.None;\r\n }\r\n break;\r\n default:\r\n break;\r\n }\r\n return null;\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\n/**\r\n * Authority types supported by MSAL.\r\n */\r\nexport enum AuthorityType {\r\n Default,\r\n Adfs,\r\n Dsts,\r\n Ciam\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\n/**\r\n * Protocol modes supported by MSAL.\r\n */\r\nexport enum ProtocolMode {\r\n AAD = \"AAD\",\r\n OIDC = \"OIDC\"\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { ClientAuthError } from \"../error/ClientAuthError\";\r\nimport { StringUtils } from \"../utils/StringUtils\";\r\nimport { ICrypto } from \"../crypto/ICrypto\";\r\nimport { Separators, Constants } from \"../utils/Constants\";\r\n\r\n/**\r\n * Client info object which consists of two IDs. Need to add more info here.\r\n */\r\nexport type ClientInfo = {\r\n uid: string,\r\n utid: string\r\n};\r\n\r\n/**\r\n * Function to build a client info object from server clientInfo string\r\n * @param rawClientInfo\r\n * @param crypto\r\n */\r\nexport function buildClientInfo(rawClientInfo: string, crypto: ICrypto): ClientInfo {\r\n if (StringUtils.isEmpty(rawClientInfo)) {\r\n throw ClientAuthError.createClientInfoEmptyError();\r\n }\r\n\r\n try {\r\n const decodedClientInfo: string = crypto.base64Decode(rawClientInfo);\r\n return JSON.parse(decodedClientInfo) as ClientInfo;\r\n } catch (e) {\r\n throw ClientAuthError.createClientInfoDecodingError((e as ClientAuthError).message);\r\n }\r\n}\r\n\r\n/**\r\n * Function to build a client info object from cached homeAccountId string\r\n * @param homeAccountId \r\n */\r\nexport function buildClientInfoFromHomeAccountId(homeAccountId: string): ClientInfo {\r\n if (StringUtils.isEmpty(homeAccountId)) {\r\n throw ClientAuthError.createClientInfoDecodingError(\"Home account ID was empty.\");\r\n }\r\n const clientInfoParts: string[] = homeAccountId.split(Separators.CLIENT_INFO_SEPARATOR, 2);\r\n return {\r\n uid: clientInfoParts[0],\r\n utid: clientInfoParts.length < 2 ? Constants.EMPTY_STRING : clientInfoParts[1]\r\n };\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport {\r\n Separators,\r\n CacheAccountType,\r\n Constants,\r\n} from \"../../utils/Constants\";\r\nimport { Authority } from \"../../authority/Authority\";\r\nimport { ICrypto } from \"../../crypto/ICrypto\";\r\nimport { buildClientInfo } from \"../../account/ClientInfo\";\r\nimport { StringUtils } from \"../../utils/StringUtils\";\r\nimport { AccountInfo } from \"../../account/AccountInfo\";\r\nimport { ClientAuthError } from \"../../error/ClientAuthError\";\r\nimport { AuthorityType } from \"../../authority/AuthorityType\";\r\nimport { Logger } from \"../../logger/Logger\";\r\nimport { TokenClaims } from \"../../account/TokenClaims\";\r\nimport { ProtocolMode } from \"../../authority/ProtocolMode\";\r\n\r\n/**\r\n * Type that defines required and optional parameters for an Account field (based on universal cache schema implemented by all MSALs).\r\n *\r\n * Key : Value Schema\r\n *\r\n * Key: --\r\n *\r\n * Value Schema:\r\n * {\r\n * homeAccountId: home account identifier for the auth scheme,\r\n * environment: entity that issued the token, represented as a full host\r\n * realm: Full tenant or organizational identifier that the account belongs to\r\n * localAccountId: Original tenant-specific accountID, usually used for legacy cases\r\n * username: primary username that represents the user, usually corresponds to preferred_username in the v2 endpt\r\n * authorityType: Accounts authority type as a string\r\n * clientInfo: Full base64 encoded client info received from ESTS\r\n * name: Full name for the account, including given name and family name\r\n * lastModificationTime: last time this entity was modified in the cache\r\n * lastModificationApp:\r\n * idTokenClaims: Object containing claims parsed from ID token\r\n * nativeAccountId: Account identifier on the native device\r\n * }\r\n */\r\nexport class AccountEntity {\r\n homeAccountId: string;\r\n environment: string;\r\n realm: string;\r\n localAccountId: string;\r\n username: string;\r\n authorityType: string;\r\n clientInfo?: string;\r\n name?: string;\r\n lastModificationTime?: string;\r\n lastModificationApp?: string;\r\n cloudGraphHostName?: string;\r\n msGraphHost?: string;\r\n idTokenClaims?: TokenClaims;\r\n nativeAccountId?: string;\r\n\r\n /**\r\n * Generate Account Id key component as per the schema: -\r\n */\r\n generateAccountId(): string {\r\n const accountId: Array = [this.homeAccountId, this.environment];\r\n return accountId.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();\r\n }\r\n\r\n /**\r\n * Generate Account Cache Key as per the schema: --\r\n */\r\n generateAccountKey(): string {\r\n return AccountEntity.generateAccountCacheKey({\r\n homeAccountId: this.homeAccountId,\r\n environment: this.environment,\r\n tenantId: this.realm,\r\n username: this.username,\r\n localAccountId: this.localAccountId\r\n });\r\n }\r\n\r\n /**\r\n * Returns the AccountInfo interface for this account.\r\n */\r\n getAccountInfo(): AccountInfo {\r\n return {\r\n homeAccountId: this.homeAccountId,\r\n environment: this.environment,\r\n tenantId: this.realm,\r\n username: this.username,\r\n localAccountId: this.localAccountId,\r\n name: this.name,\r\n idTokenClaims: this.idTokenClaims,\r\n nativeAccountId: this.nativeAccountId,\r\n authorityType: this.authorityType\r\n };\r\n }\r\n\r\n /**\r\n * Generates account key from interface\r\n * @param accountInterface\r\n */\r\n static generateAccountCacheKey(accountInterface: AccountInfo): string {\r\n const accountKey = [\r\n accountInterface.homeAccountId,\r\n accountInterface.environment || Constants.EMPTY_STRING,\r\n accountInterface.tenantId || Constants.EMPTY_STRING,\r\n ];\r\n\r\n return accountKey.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();\r\n }\r\n\r\n /**\r\n * Build Account cache from account properties.\r\n * @param accountDetails\r\n * @param authority\r\n */\r\n static createAccount(\r\n accountDetails: {\r\n homeAccountId: string,\r\n idTokenClaims: TokenClaims,\r\n clientInfo?: string,\r\n cloudGraphHostName?: string,\r\n msGraphHost?: string,\r\n environment?: string,\r\n nativeAccountId?: string\r\n },\r\n authority: Authority\r\n ): AccountEntity {\r\n const account: AccountEntity = new AccountEntity();\r\n\r\n if (authority.authorityType === AuthorityType.Adfs) {\r\n account.authorityType = CacheAccountType.ADFS_ACCOUNT_TYPE;\r\n } else if (authority.protocolMode === ProtocolMode.AAD) {\r\n account.authorityType = CacheAccountType.MSSTS_ACCOUNT_TYPE;\r\n } else {\r\n account.authorityType = CacheAccountType.GENERIC_ACCOUNT_TYPE;\r\n }\r\n\r\n account.clientInfo = accountDetails.clientInfo;\r\n account.homeAccountId = accountDetails.homeAccountId;\r\n account.nativeAccountId = accountDetails.nativeAccountId;\r\n\r\n const env = accountDetails.environment || (authority && authority.getPreferredCache());\r\n\r\n if (!env) {\r\n throw ClientAuthError.createInvalidCacheEnvironmentError();\r\n }\r\n\r\n account.environment = env;\r\n // non AAD scenarios can have empty realm\r\n account.realm = accountDetails.idTokenClaims.tid || Constants.EMPTY_STRING;\r\n\r\n account.idTokenClaims = accountDetails.idTokenClaims;\r\n\r\n // How do you account for MSA CID here?\r\n account.localAccountId = accountDetails.idTokenClaims.oid || accountDetails.idTokenClaims.sub || Constants.EMPTY_STRING;\r\n\r\n /*\r\n * In B2C scenarios the emails claim is used instead of preferred_username and it is an array.\r\n * In most cases it will contain a single email. This field should not be relied upon if a custom \r\n * policy is configured to return more than 1 email.\r\n */\r\n if (account.authorityType === CacheAccountType.MSSTS_ACCOUNT_TYPE) {\r\n const preferredUsername = accountDetails.idTokenClaims.preferred_username;\r\n const email = (accountDetails.idTokenClaims.emails) ? accountDetails.idTokenClaims.emails[0] : null;\r\n \r\n account.username = preferredUsername || email || \"\";\r\n } else {\r\n account.username = accountDetails.idTokenClaims.upn || \"\";\r\n }\r\n account.name = accountDetails.idTokenClaims.name;\r\n\r\n account.cloudGraphHostName = accountDetails.cloudGraphHostName;\r\n account.msGraphHost = accountDetails.msGraphHost;\r\n\r\n return account;\r\n }\r\n\r\n /**\r\n * Creates an account object from AccountInfo\r\n * @param accountInfo\r\n * @param cloudGraphHostName\r\n * @param msGraphHost\r\n * @returns AccountEntity\r\n */\r\n static createFromAccountInfo(\r\n accountInfo: AccountInfo,\r\n cloudGraphHostName?: string,\r\n msGraphHost?: string\r\n ): AccountEntity {\r\n const account: AccountEntity = new AccountEntity();\r\n\r\n account.authorityType =\r\n accountInfo.authorityType || CacheAccountType.GENERIC_ACCOUNT_TYPE;\r\n account.homeAccountId = accountInfo.homeAccountId;\r\n account.localAccountId = accountInfo.localAccountId;\r\n account.nativeAccountId = accountInfo.nativeAccountId;\r\n \r\n account.realm = accountInfo.tenantId;\r\n account.environment = accountInfo.environment;\r\n\r\n account.username = accountInfo.username;\r\n account.name = accountInfo.name;\r\n account.idTokenClaims = accountInfo.idTokenClaims;\r\n\r\n account.cloudGraphHostName = cloudGraphHostName;\r\n account.msGraphHost = msGraphHost;\r\n\r\n return account;\r\n }\r\n\r\n /**\r\n * Generate HomeAccountId from server response\r\n * @param serverClientInfo\r\n * @param authType\r\n */\r\n static generateHomeAccountId(\r\n serverClientInfo: string,\r\n authType: AuthorityType,\r\n logger: Logger,\r\n cryptoObj: ICrypto,\r\n idTokenClaims?: TokenClaims\r\n ): string {\r\n\r\n const accountId = idTokenClaims?.sub ? idTokenClaims.sub : Constants.EMPTY_STRING;\r\n\r\n // since ADFS does not have tid and does not set client_info\r\n if (authType === AuthorityType.Adfs || authType === AuthorityType.Dsts) {\r\n return accountId;\r\n }\r\n\r\n // for cases where there is clientInfo\r\n if (serverClientInfo) {\r\n try {\r\n const clientInfo = buildClientInfo(serverClientInfo, cryptoObj);\r\n if (!StringUtils.isEmpty(clientInfo.uid) && !StringUtils.isEmpty(clientInfo.utid)) {\r\n return `${clientInfo.uid}${Separators.CLIENT_INFO_SEPARATOR}${clientInfo.utid}`;\r\n }\r\n } catch (e) {}\r\n }\r\n\r\n // default to \"sub\" claim\r\n logger.verbose(\"No client info in response\");\r\n return accountId;\r\n }\r\n\r\n /**\r\n * Validates an entity: checks for all expected params\r\n * @param entity\r\n */\r\n static isAccountEntity(entity: object): boolean {\r\n\r\n if (!entity) {\r\n return false;\r\n }\r\n\r\n return (\r\n entity.hasOwnProperty(\"homeAccountId\") &&\r\n entity.hasOwnProperty(\"environment\") &&\r\n entity.hasOwnProperty(\"realm\") &&\r\n entity.hasOwnProperty(\"localAccountId\") &&\r\n entity.hasOwnProperty(\"username\") &&\r\n entity.hasOwnProperty(\"authorityType\")\r\n );\r\n }\r\n\r\n /**\r\n * Helper function to determine whether 2 accountInfo objects represent the same account\r\n * @param accountA\r\n * @param accountB\r\n * @param compareClaims - If set to true idTokenClaims will also be compared to determine account equality\r\n */\r\n static accountInfoIsEqual(accountA: AccountInfo | null, accountB: AccountInfo | null, compareClaims?: boolean): boolean {\r\n if (!accountA || !accountB) {\r\n return false;\r\n }\r\n\r\n let claimsMatch = true; // default to true so as to not fail comparison below if compareClaims: false\r\n if (compareClaims) {\r\n const accountAClaims = (accountA.idTokenClaims || {}) as TokenClaims;\r\n const accountBClaims = (accountB.idTokenClaims || {}) as TokenClaims;\r\n\r\n // issued at timestamp and nonce are expected to change each time a new id token is acquired\r\n claimsMatch = (accountAClaims.iat === accountBClaims.iat) &&\r\n (accountAClaims.nonce === accountBClaims.nonce);\r\n }\r\n\r\n return (accountA.homeAccountId === accountB.homeAccountId) &&\r\n (accountA.localAccountId === accountB.localAccountId) &&\r\n (accountA.username === accountB.username) &&\r\n (accountA.tenantId === accountB.tenantId) &&\r\n (accountA.environment === accountB.environment) &&\r\n (accountA.nativeAccountId === accountB.nativeAccountId) &&\r\n claimsMatch;\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { Constants } from \"../utils/Constants\";\r\nimport { AuthError } from \"./AuthError\";\r\n\r\n/**\r\n * InteractionRequiredServerErrorMessage contains string constants used by error codes and messages returned by the server indicating interaction is required\r\n */\r\nexport const InteractionRequiredServerErrorMessage = [\r\n \"interaction_required\",\r\n \"consent_required\",\r\n \"login_required\"\r\n];\r\n\r\nexport const InteractionRequiredAuthSubErrorMessage = [\r\n \"message_only\",\r\n \"additional_action\",\r\n \"basic_action\",\r\n \"user_password_expired\",\r\n \"consent_required\"\r\n];\r\n\r\n/**\r\n * Interaction required errors defined by the SDK\r\n */\r\nexport const InteractionRequiredAuthErrorMessage = {\r\n noTokensFoundError: {\r\n code: \"no_tokens_found\",\r\n desc: \"No refresh token found in the cache. Please sign-in.\"\r\n },\r\n native_account_unavailable: {\r\n code: \"native_account_unavailable\",\r\n desc: \"The requested account is not available in the native broker. It may have been deleted or logged out. Please sign-in again using an interactive API.\"\r\n }\r\n};\r\n\r\n/**\r\n * Error thrown when user interaction is required.\r\n */\r\nexport class InteractionRequiredAuthError extends AuthError {\r\n /**\r\n * The time the error occured at\r\n */\r\n timestamp: string;\r\n\r\n /**\r\n * TraceId associated with the error\r\n */\r\n traceId: string;\r\n\r\n /**\r\n * https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-common/docs/claims-challenge.md\r\n * \r\n * A string with extra claims needed for the token request to succeed\r\n * web site: redirect the user to the authorization page and set the extra claims\r\n * web api: include the claims in the WWW-Authenticate header that are sent back to the client so that it knows to request a token with the extra claims\r\n * desktop application or browser context: include the claims when acquiring the token interactively\r\n * app to app context (client_credentials): include the claims in the AcquireTokenByClientCredential request\r\n */\r\n claims: string;\r\n\r\n constructor(errorCode?: string, errorMessage?: string, subError?: string, timestamp?: string, traceId?: string, correlationId?: string, claims?: string) {\r\n super(errorCode, errorMessage, subError);\r\n Object.setPrototypeOf(this, InteractionRequiredAuthError.prototype);\r\n \r\n this.timestamp = timestamp || Constants.EMPTY_STRING;\r\n this.traceId = traceId || Constants.EMPTY_STRING;\r\n this.correlationId = correlationId || Constants.EMPTY_STRING;\r\n this.claims = claims || Constants.EMPTY_STRING;\r\n this.name = \"InteractionRequiredAuthError\";\r\n }\r\n\r\n /**\r\n * Helper function used to determine if an error thrown by the server requires interaction to resolve\r\n * @param errorCode \r\n * @param errorString \r\n * @param subError \r\n */\r\n static isInteractionRequiredError(errorCode?: string, errorString?: string, subError?: string): boolean {\r\n const isInteractionRequiredErrorCode = !!errorCode && InteractionRequiredServerErrorMessage.indexOf(errorCode) > -1;\r\n const isInteractionRequiredSubError = !!subError && InteractionRequiredAuthSubErrorMessage.indexOf(subError) > -1;\r\n const isInteractionRequiredErrorDesc = !!errorString && InteractionRequiredServerErrorMessage.some((irErrorCode) => {\r\n return errorString.indexOf(irErrorCode) > -1;\r\n });\r\n\r\n return isInteractionRequiredErrorCode || isInteractionRequiredErrorDesc || isInteractionRequiredSubError;\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the authorization code required for a token request is null or empty.\r\n */\r\n static createNoTokensFoundError(): InteractionRequiredAuthError {\r\n return new InteractionRequiredAuthError(InteractionRequiredAuthErrorMessage.noTokensFoundError.code, InteractionRequiredAuthErrorMessage.noTokensFoundError.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the native broker returns ACCOUNT_UNAVAILABLE status, indicating that the account was removed and interactive sign-in is required\r\n * @returns \r\n */\r\n static createNativeAccountUnavailableError(): InteractionRequiredAuthError {\r\n return new InteractionRequiredAuthError(InteractionRequiredAuthErrorMessage.native_account_unavailable.code, InteractionRequiredAuthErrorMessage.native_account_unavailable.desc);\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport * as React from \"react\";\r\nimport { IPublicClientApplication, stubbedPublicClientApplication, Logger, InteractionStatus, AccountInfo } from \"@azure/msal-browser\";\r\n\r\nexport interface IMsalContext {\r\n instance: IPublicClientApplication;\r\n inProgress: InteractionStatus;\r\n accounts: AccountInfo[];\r\n logger: Logger;\r\n}\r\n\r\n/*\r\n * Stubbed context implementation\r\n * Only used when there is no provider, which is an unsupported scenario\r\n */\r\nconst defaultMsalContext: IMsalContext = {\r\n instance: stubbedPublicClientApplication,\r\n inProgress: InteractionStatus.None,\r\n accounts: [],\r\n logger: new Logger({})\r\n};\r\n\r\nexport const MsalContext = React.createContext(\r\n defaultMsalContext\r\n);\r\nexport const MsalConsumer = MsalContext.Consumer;\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { AccountIdentifiers } from \"../types/AccountIdentifiers\";\r\nimport { AccountInfo } from \"@azure/msal-browser\";\r\n\r\ntype FaaCFunction = (args: T) => React.ReactNode;\r\n\r\nexport function getChildrenOrFunction(\r\n children: React.ReactNode | FaaCFunction,\r\n args: T\r\n): React.ReactNode {\r\n if (typeof children === \"function\") {\r\n return children(args);\r\n }\r\n return children;\r\n}\r\n\r\n/*\r\n * Utility types\r\n * Reference: https://github.com/piotrwitek/utility-types\r\n */\r\ntype SetDifference = A extends B ? never : A;\r\ntype SetComplement = SetDifference;\r\nexport type Subtract = Pick>;\r\n\r\n/**\r\n * Helper function to determine whether 2 arrays are equal\r\n * Used to avoid unnecessary state updates\r\n * @param arrayA \r\n * @param arrayB \r\n */\r\nexport function accountArraysAreEqual(arrayA: Array, arrayB: Array): boolean {\r\n if (arrayA.length !== arrayB.length) {\r\n return false;\r\n }\r\n\r\n const comparisonArray = [...arrayB];\r\n\r\n return arrayA.every((elementA) => {\r\n const elementB = comparisonArray.shift();\r\n if (!elementA || !elementB) {\r\n return false;\r\n }\r\n\r\n return (elementA.homeAccountId === elementB.homeAccountId) && \r\n (elementA.localAccountId === elementB.localAccountId) &&\r\n (elementA.username === elementB.username);\r\n });\r\n}\r\n\r\nexport function getAccountByIdentifiers(allAccounts: AccountInfo[], accountIdentifiers: AccountIdentifiers): AccountInfo | null {\r\n if (allAccounts.length > 0 && (accountIdentifiers.homeAccountId || accountIdentifiers.localAccountId || accountIdentifiers.username)) {\r\n const matchedAccounts = allAccounts.filter(accountObj => {\r\n if (accountIdentifiers.username && accountIdentifiers.username.toLowerCase() !== accountObj.username.toLowerCase()) {\r\n return false;\r\n }\r\n if (accountIdentifiers.homeAccountId && accountIdentifiers.homeAccountId.toLowerCase() !== accountObj.homeAccountId.toLowerCase()) {\r\n return false;\r\n }\r\n if (accountIdentifiers.localAccountId && accountIdentifiers.localAccountId.toLowerCase() !== accountObj.localAccountId.toLowerCase()) {\r\n return false;\r\n }\r\n\r\n return true;\r\n });\r\n\r\n return matchedAccounts[0] || null;\r\n } else {\r\n return null;\r\n }\r\n}\r\n","/* eslint-disable header/header */\nexport const name = \"@azure/msal-react\";\nexport const version = \"1.5.13\";\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport React, { useEffect, useReducer, PropsWithChildren, useMemo} from \"react\";\r\nimport {\r\n IPublicClientApplication,\r\n EventMessage,\r\n EventMessageUtils,\r\n InteractionStatus,\r\n Logger,\r\n WrapperSKU,\r\n AccountInfo\r\n} from \"@azure/msal-browser\";\r\nimport { MsalContext, IMsalContext } from \"./MsalContext\";\r\nimport { accountArraysAreEqual } from \"./utils/utilities\";\r\nimport { name as SKU, version } from \"./packageMetadata\";\r\n\r\nexport type MsalProviderProps = PropsWithChildren<{\r\n instance: IPublicClientApplication;\r\n}>;\r\n\r\ntype MsalState = {\r\n inProgress: InteractionStatus;\r\n accounts: AccountInfo[];\r\n};\r\n\r\nenum MsalProviderActionType {\r\n UNBLOCK_INPROGRESS = \"UNBLOCK_INPROGRESS\",\r\n EVENT = \"EVENT\"\r\n}\r\n\r\ntype MsalProviderReducerAction = {\r\n type: MsalProviderActionType,\r\n payload: {\r\n logger: Logger;\r\n instance: IPublicClientApplication;\r\n message?: EventMessage;\r\n };\r\n};\r\n\r\n/**\r\n * Returns the next inProgress and accounts state based on event message\r\n * @param previousState \r\n * @param action \r\n */\r\nconst reducer = (previousState: MsalState, action: MsalProviderReducerAction): MsalState => {\r\n const { type, payload } = action;\r\n let newInProgress = previousState.inProgress;\r\n\r\n switch (type) {\r\n case MsalProviderActionType.UNBLOCK_INPROGRESS:\r\n if (previousState.inProgress === InteractionStatus.Startup){\r\n newInProgress = InteractionStatus.None;\r\n payload.logger.info(\"MsalProvider - handleRedirectPromise resolved, setting inProgress to 'none'\");\r\n }\r\n break;\r\n case MsalProviderActionType.EVENT:\r\n const message = payload.message as EventMessage;\r\n const status = EventMessageUtils.getInteractionStatusFromEvent(message, previousState.inProgress);\r\n if (status) {\r\n payload.logger.info(`MsalProvider - ${message.eventType} results in setting inProgress from ${previousState.inProgress} to ${status}`);\r\n newInProgress = status;\r\n }\r\n break;\r\n default:\r\n throw new Error(`Unknown action type: ${type}`);\r\n }\r\n \r\n const currentAccounts = payload.instance.getAllAccounts();\r\n if (newInProgress !== previousState.inProgress && \r\n !accountArraysAreEqual(currentAccounts, previousState.accounts)) {\r\n // Both inProgress and accounts changed\r\n return {\r\n ...previousState,\r\n inProgress: newInProgress,\r\n accounts: currentAccounts\r\n };\r\n } else if (newInProgress !== previousState.inProgress) {\r\n // Only only inProgress changed\r\n return {\r\n ...previousState,\r\n inProgress: newInProgress\r\n };\r\n } else if (!accountArraysAreEqual(currentAccounts, previousState.accounts)) {\r\n // Only accounts changed\r\n return {\r\n ...previousState,\r\n accounts: currentAccounts\r\n };\r\n } else {\r\n // Nothing changed\r\n return previousState;\r\n }\r\n};\r\n\r\n/**\r\n * MSAL context provider component. This must be rendered above any other components that use MSAL.\r\n */\r\nexport function MsalProvider({instance, children}: MsalProviderProps): React.ReactElement {\r\n useEffect(() => {\r\n instance.initializeWrapperLibrary(WrapperSKU.React, version);\r\n }, [instance]);\r\n // Create a logger instance for msal-react with the same options as PublicClientApplication\r\n const logger = useMemo(() => {\r\n return instance.getLogger().clone(SKU, version);\r\n }, [instance]);\r\n\r\n const [state, updateState] = useReducer(reducer, undefined, () => {\r\n // Lazy initialization of the initial state\r\n return {\r\n inProgress: InteractionStatus.Startup,\r\n accounts: instance.getAllAccounts()\r\n };\r\n });\r\n \r\n useEffect(() => {\r\n const callbackId = instance.addEventCallback((message: EventMessage) => {\r\n updateState({\r\n payload: {\r\n instance,\r\n logger,\r\n message\r\n }, \r\n type: MsalProviderActionType.EVENT\r\n });\r\n });\r\n logger.verbose(`MsalProvider - Registered event callback with id: ${callbackId}`);\r\n\r\n instance.initialize().then(() => {\r\n instance.handleRedirectPromise().catch(() => {\r\n // Errors should be handled by listening to the LOGIN_FAILURE event\r\n return;\r\n }).finally(() => {\r\n /*\r\n * If handleRedirectPromise returns a cached promise the necessary events may not be fired\r\n * This is a fallback to prevent inProgress from getting stuck in 'startup'\r\n */\r\n updateState({\r\n payload: {\r\n instance,\r\n logger\r\n },\r\n type: MsalProviderActionType.UNBLOCK_INPROGRESS \r\n });\r\n });\r\n });\r\n\r\n return () => {\r\n // Remove callback when component unmounts or accounts change\r\n if (callbackId) {\r\n logger.verbose(`MsalProvider - Removing event callback ${callbackId}`);\r\n instance.removeEventCallback(callbackId);\r\n }\r\n };\r\n }, [instance, logger]);\r\n\r\n const contextValue: IMsalContext = {\r\n instance,\r\n inProgress: state.inProgress,\r\n accounts: state.accounts,\r\n logger\r\n };\r\n\r\n return (\r\n \r\n {children}\r\n \r\n );\r\n}\r\n\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { useContext } from \"react\";\r\nimport { IMsalContext, MsalContext } from \"../MsalContext\";\r\n\r\n/**\r\n * Returns Msal Context values\r\n */\r\nexport const useMsal = (): IMsalContext => useContext(MsalContext);\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { useState, useEffect } from \"react\";\r\nimport { useMsal } from \"./useMsal\";\r\nimport { AccountIdentifiers } from \"../types/AccountIdentifiers\";\r\nimport { AccountInfo, InteractionStatus } from \"@azure/msal-browser\";\r\nimport { getAccountByIdentifiers } from \"../utils/utilities\";\r\n\r\nfunction isAuthenticated(allAccounts: AccountInfo[], matchAccount?: AccountIdentifiers): boolean {\r\n if(matchAccount && (matchAccount.username || matchAccount.homeAccountId || matchAccount.localAccountId)) {\r\n return !!getAccountByIdentifiers(allAccounts, matchAccount);\r\n } \r\n\r\n return allAccounts.length > 0;\r\n}\r\n\r\n/**\r\n * Returns whether or not a user is currently signed-in. Optionally provide 1 or more accountIdentifiers to determine if a specific user is signed-in\r\n * @param matchAccount \r\n */\r\nexport function useIsAuthenticated(matchAccount?: AccountIdentifiers): boolean {\r\n const { accounts: allAccounts, inProgress } = useMsal();\r\n\r\n const [hasAuthenticated, setHasAuthenticated] = useState(() => {\r\n if (inProgress === InteractionStatus.Startup) {\r\n return false;\r\n }\r\n return isAuthenticated(allAccounts, matchAccount);\r\n });\r\n\r\n useEffect(() => {\r\n setHasAuthenticated(isAuthenticated(allAccounts, matchAccount));\r\n }, [allAccounts, matchAccount]);\r\n\r\n return hasAuthenticated;\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport React, { PropsWithChildren, useMemo } from \"react\";\r\nimport { AccountIdentifiers } from \"../types/AccountIdentifiers\";\r\nimport { getChildrenOrFunction } from \"../utils/utilities\";\r\nimport { useMsal } from \"../hooks/useMsal\";\r\nimport { useIsAuthenticated } from \"../hooks/useIsAuthenticated\";\r\nimport { InteractionStatus } from \"@azure/msal-browser\";\r\n\r\nexport type AuthenticatedTemplateProps = PropsWithChildren;\r\n\r\n/**\r\n * Renders child components if user is authenticated\r\n * @param props \r\n */\r\nexport function AuthenticatedTemplate({ username, homeAccountId, localAccountId, children }: AuthenticatedTemplateProps): React.ReactElement|null {\r\n const context = useMsal();\r\n const accountIdentifier: AccountIdentifiers = useMemo(() => {\r\n return {\r\n username,\r\n homeAccountId,\r\n localAccountId\r\n };\r\n }, [username, homeAccountId, localAccountId]);\r\n const isAuthenticated = useIsAuthenticated(accountIdentifier);\r\n\r\n if (isAuthenticated && context.inProgress !== InteractionStatus.Startup) {\r\n return (\r\n \r\n {getChildrenOrFunction(children, context)}\r\n \r\n );\r\n }\r\n return null;\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport React, { PropsWithChildren, useMemo } from \"react\";\r\nimport { useMsal } from \"../hooks/useMsal\";\r\nimport { useIsAuthenticated } from \"../hooks/useIsAuthenticated\";\r\nimport { getChildrenOrFunction } from \"../utils/utilities\";\r\nimport { AccountIdentifiers } from \"../types/AccountIdentifiers\";\r\nimport { InteractionStatus } from \"@azure/msal-browser\";\r\n\r\nexport type UnauthenticatedTemplateProps = PropsWithChildren;\r\n\r\n/**\r\n * Renders child components if user is unauthenticated\r\n * @param props \r\n */\r\nexport function UnauthenticatedTemplate({ username, homeAccountId, localAccountId, children }: UnauthenticatedTemplateProps): React.ReactElement|null {\r\n const context = useMsal();\r\n const accountIdentifier: AccountIdentifiers = useMemo(() => {\r\n return {\r\n username,\r\n homeAccountId,\r\n localAccountId\r\n };\r\n }, [username, homeAccountId, localAccountId]);\r\n const isAuthenticated = useIsAuthenticated(accountIdentifier);\r\n\r\n if (!isAuthenticated && context.inProgress !== InteractionStatus.Startup && context.inProgress !== InteractionStatus.HandleRedirect) {\r\n return (\r\n \r\n {getChildrenOrFunction(children, context)}\r\n \r\n );\r\n }\r\n return null;\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { useState, useEffect } from \"react\";\r\nimport { AccountInfo, IPublicClientApplication, AccountEntity } from \"@azure/msal-browser\";\r\nimport { useMsal } from \"./useMsal\";\r\nimport { AccountIdentifiers } from \"../types/AccountIdentifiers\";\r\nimport { getAccountByIdentifiers } from \"../utils/utilities\";\r\n\r\nfunction getAccount(instance: IPublicClientApplication, accountIdentifiers?: AccountIdentifiers): AccountInfo | null {\r\n if (!accountIdentifiers || (!accountIdentifiers.homeAccountId && !accountIdentifiers.localAccountId && !accountIdentifiers.username)) {\r\n // If no account identifiers are provided, return active account\r\n return instance.getActiveAccount();\r\n }\r\n\r\n return getAccountByIdentifiers(instance.getAllAccounts(), accountIdentifiers);\r\n}\r\n\r\n/**\r\n * Given 1 or more accountIdentifiers, returns the Account object if the user is signed-in\r\n * @param accountIdentifiers \r\n */\r\nexport function useAccount(accountIdentifiers?: AccountIdentifiers): AccountInfo | null {\r\n const { instance, inProgress, logger } = useMsal();\r\n\r\n const [account, setAccount] = useState(() => getAccount(instance, accountIdentifiers));\r\n\r\n useEffect(() => {\r\n setAccount((currentAccount: AccountInfo | null) => {\r\n const nextAccount = getAccount(instance, accountIdentifiers);\r\n if (!AccountEntity.accountInfoIsEqual(currentAccount, nextAccount, true)) {\r\n logger.info(\"useAccount - Updating account\");\r\n return nextAccount;\r\n }\r\n\r\n return currentAccount;\r\n });\r\n }, [inProgress, accountIdentifiers, instance, logger]);\r\n\r\n return account;\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { AuthError } from \"@azure/msal-browser\";\r\n\r\nexport const ReactAuthErrorMessage = {\r\n invalidInteractionType: {\r\n code: \"invalid_interaction_type\",\r\n desc: \"The provided interaction type is invalid.\"\r\n },\r\n unableToFallbackToInteraction: {\r\n code: \"unable_to_fallback_to_interaction\",\r\n desc: \"Interaction is required but another interaction is already in progress. Please try again when the current interaction is complete.\"\r\n }\r\n};\r\n\r\nexport class ReactAuthError extends AuthError {\r\n constructor(errorCode: string, errorMessage?: string) {\r\n super(errorCode, errorMessage);\r\n\r\n Object.setPrototypeOf(this, ReactAuthError.prototype);\r\n this.name = \"ReactAuthError\";\r\n }\r\n\r\n static createInvalidInteractionTypeError(): ReactAuthError {\r\n return new ReactAuthError(ReactAuthErrorMessage.invalidInteractionType.code, ReactAuthErrorMessage.invalidInteractionType.desc);\r\n }\r\n\r\n static createUnableToFallbackToInteractionError(): ReactAuthError {\r\n return new ReactAuthError(ReactAuthErrorMessage.unableToFallbackToInteraction.code, ReactAuthErrorMessage.unableToFallbackToInteraction.desc);\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { useCallback, useEffect, useState, useRef } from \"react\";\r\nimport { PopupRequest, RedirectRequest, SsoSilentRequest, InteractionType, AuthenticationResult, AuthError, EventMessage, EventType, InteractionStatus, SilentRequest, InteractionRequiredAuthError, OIDC_DEFAULT_SCOPES } from \"@azure/msal-browser\";\r\nimport { useIsAuthenticated } from \"./useIsAuthenticated\";\r\nimport { AccountIdentifiers } from \"../types/AccountIdentifiers\";\r\nimport { useMsal } from \"./useMsal\";\r\nimport { useAccount } from \"./useAccount\";\r\nimport { ReactAuthError } from \"../error/ReactAuthError\";\r\n\r\nexport type MsalAuthenticationResult = {\r\n login: (callbackInteractionType?: InteractionType | undefined, callbackRequest?: PopupRequest | RedirectRequest | SilentRequest) => Promise; \r\n acquireToken: (callbackInteractionType?: InteractionType | undefined, callbackRequest?: SilentRequest | undefined) => Promise;\r\n result: AuthenticationResult|null;\r\n error: AuthError|null;\r\n};\r\n\r\n/**\r\n * If a user is not currently signed in this hook invokes a login. Failed logins can be retried using the login callback returned.\r\n * If a user is currently signed in this hook attempts to acquire a token. Subsequent token requests can use the acquireToken callback returned.\r\n * Optionally provide a request object to be used in the login/acquireToken call.\r\n * Optionally provide a specific user that should be logged in.\r\n * @param interactionType \r\n * @param authenticationRequest \r\n * @param accountIdentifiers \r\n */\r\nexport function useMsalAuthentication(\r\n interactionType: InteractionType, \r\n authenticationRequest?: PopupRequest|RedirectRequest|SsoSilentRequest, \r\n accountIdentifiers?: AccountIdentifiers\r\n): MsalAuthenticationResult {\r\n const { instance, inProgress, logger } = useMsal();\r\n const isAuthenticated = useIsAuthenticated(accountIdentifiers);\r\n const account = useAccount(accountIdentifiers);\r\n const [[result, error], setResponse] = useState<[AuthenticationResult|null, AuthError|null]>([null, null]);\r\n\r\n // Used to prevent state updates after unmount\r\n const mounted = useRef(true);\r\n useEffect(() => {\r\n return () => {\r\n mounted.current = false;\r\n };\r\n },[]);\r\n\r\n // Boolean used to check if interaction is in progress in acquireTokenSilent fallback. Use Ref instead of state to prevent acquireToken function from being regenerated on each change to interactionInProgress value\r\n const interactionInProgress = useRef(inProgress !== InteractionStatus.None);\r\n useEffect(() => {\r\n interactionInProgress.current = inProgress !== InteractionStatus.None;\r\n }, [inProgress]);\r\n\r\n // Flag used to control when the hook calls login/acquireToken\r\n const shouldAcquireToken = useRef(true);\r\n useEffect(() => {\r\n if (!!error) {\r\n // Errors should be handled by consuming component\r\n shouldAcquireToken.current = false;\r\n return;\r\n }\r\n\r\n if (!!result) {\r\n // Token has already been acquired, consuming component/application is responsible for renewing\r\n shouldAcquireToken.current = false;\r\n return;\r\n }\r\n }, [error, result]);\r\n\r\n const login = useCallback(async (callbackInteractionType?: InteractionType, callbackRequest?: PopupRequest|RedirectRequest|SsoSilentRequest): Promise => {\r\n const loginType = callbackInteractionType || interactionType;\r\n const loginRequest = callbackRequest || authenticationRequest;\r\n switch (loginType) {\r\n case InteractionType.Popup:\r\n logger.verbose(\"useMsalAuthentication - Calling loginPopup\");\r\n return instance.loginPopup(loginRequest as PopupRequest);\r\n case InteractionType.Redirect:\r\n // This promise is not expected to resolve due to full frame redirect\r\n logger.verbose(\"useMsalAuthentication - Calling loginRedirect\");\r\n return instance.loginRedirect(loginRequest as RedirectRequest).then(null);\r\n case InteractionType.Silent:\r\n logger.verbose(\"useMsalAuthentication - Calling ssoSilent\");\r\n return instance.ssoSilent(loginRequest as SsoSilentRequest);\r\n default:\r\n throw ReactAuthError.createInvalidInteractionTypeError();\r\n }\r\n }, [instance, interactionType, authenticationRequest, logger]);\r\n\r\n const acquireToken = useCallback(async (callbackInteractionType?: InteractionType, callbackRequest?: SilentRequest): Promise => {\r\n const fallbackInteractionType = callbackInteractionType || interactionType;\r\n\r\n let tokenRequest: SilentRequest;\r\n\r\n if (callbackRequest) {\r\n logger.trace(\"useMsalAuthentication - acquireToken - Using request provided in the callback\");\r\n tokenRequest = {\r\n ...callbackRequest\r\n };\r\n } else if (authenticationRequest) {\r\n logger.trace(\"useMsalAuthentication - acquireToken - Using request provided in the hook\");\r\n tokenRequest = {\r\n ...authenticationRequest,\r\n scopes: authenticationRequest.scopes || OIDC_DEFAULT_SCOPES\r\n };\r\n } else {\r\n logger.trace(\"useMsalAuthentication - acquireToken - No request object provided, using default request.\");\r\n tokenRequest = {\r\n scopes: OIDC_DEFAULT_SCOPES\r\n };\r\n }\r\n \r\n if (!tokenRequest.account && account) {\r\n logger.trace(\"useMsalAuthentication - acquireToken - Attaching account to request\");\r\n tokenRequest.account = account;\r\n }\r\n\r\n const getToken = async (): Promise => {\r\n logger.verbose(\"useMsalAuthentication - Calling acquireTokenSilent\");\r\n return instance.acquireTokenSilent(tokenRequest).catch(async (e: AuthError) => {\r\n if (e instanceof InteractionRequiredAuthError) {\r\n if (!interactionInProgress.current) {\r\n logger.error(\"useMsalAuthentication - Interaction required, falling back to interaction\");\r\n return login(fallbackInteractionType, tokenRequest);\r\n } else {\r\n logger.error(\"useMsalAuthentication - Interaction required but is already in progress. Please try again, if needed, after interaction completes.\");\r\n throw ReactAuthError.createUnableToFallbackToInteractionError();\r\n }\r\n }\r\n\r\n throw e;\r\n });\r\n };\r\n\r\n return getToken().then((response: AuthenticationResult|null) => {\r\n if (mounted.current) {\r\n setResponse([response, null]);\r\n }\r\n return response;\r\n }).catch((e: AuthError) => {\r\n if (mounted.current) {\r\n setResponse([null, e]);\r\n }\r\n throw e;\r\n });\r\n }, [instance, interactionType, authenticationRequest, logger, account, login]);\r\n\r\n useEffect(() => {\r\n const callbackId = instance.addEventCallback((message: EventMessage) => {\r\n switch(message.eventType) {\r\n case EventType.LOGIN_SUCCESS:\r\n case EventType.SSO_SILENT_SUCCESS:\r\n if (message.payload) {\r\n setResponse([message.payload as AuthenticationResult, null]);\r\n }\r\n break;\r\n case EventType.LOGIN_FAILURE:\r\n case EventType.SSO_SILENT_FAILURE:\r\n if (message.error) {\r\n setResponse([null, message.error as AuthError]);\r\n }\r\n break;\r\n }\r\n });\r\n logger.verbose(`useMsalAuthentication - Registered event callback with id: ${callbackId}`);\r\n\r\n return () => {\r\n if (callbackId) {\r\n logger.verbose(`useMsalAuthentication - Removing event callback ${callbackId}`);\r\n instance.removeEventCallback(callbackId);\r\n }\r\n };\r\n }, [instance, logger]);\r\n\r\n useEffect(() => {\r\n if (shouldAcquireToken.current && inProgress === InteractionStatus.None) {\r\n shouldAcquireToken.current = false;\r\n if (!isAuthenticated) {\r\n logger.info(\"useMsalAuthentication - No user is authenticated, attempting to login\");\r\n login().catch(() => {\r\n // Errors are saved in state above\r\n return;\r\n });\r\n } else if (account) {\r\n logger.info(\"useMsalAuthentication - User is authenticated, attempting to acquire token\");\r\n acquireToken().catch(() => {\r\n // Errors are saved in state above\r\n return;\r\n });\r\n }\r\n }\r\n }, [isAuthenticated, account, inProgress, login, acquireToken, logger]);\r\n\r\n return { \r\n login, \r\n acquireToken, \r\n result, \r\n error\r\n };\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\n/**\r\n * Enumeration of operations that are instrumented by have their performance measured by the PerformanceClient.\r\n *\r\n * @export\r\n * @enum {number}\r\n */\r\nexport enum PerformanceEvents {\r\n\r\n /**\r\n * acquireTokenByCode API (msal-browser and msal-node).\r\n * Used to acquire tokens by trading an authorization code against the token endpoint.\r\n */\r\n AcquireTokenByCode = \"acquireTokenByCode\",\r\n\r\n /**\r\n * acquireTokenByRefreshToken API (msal-browser and msal-node).\r\n * Used to renew an access token using a refresh token against the token endpoint.\r\n */\r\n AcquireTokenByRefreshToken = \"acquireTokenByRefreshToken\",\r\n\r\n /**\r\n * acquireTokenSilent API (msal-browser and msal-node).\r\n * Used to silently acquire a new access token (from the cache or the network).\r\n */\r\n AcquireTokenSilent = \"acquireTokenSilent\",\r\n\r\n /**\r\n * acquireTokenSilentAsync (msal-browser).\r\n * Internal API for acquireTokenSilent.\r\n */\r\n AcquireTokenSilentAsync = \"acquireTokenSilentAsync\",\r\n\r\n /**\r\n * acquireTokenPopup (msal-browser).\r\n * Used to acquire a new access token interactively through pop ups\r\n */\r\n AcquireTokenPopup = \"acquireTokenPopup\",\r\n\r\n /**\r\n * getPublicKeyThumbprint API in CryptoOpts class (msal-browser).\r\n * Used to generate a public/private keypair and generate a public key thumbprint for pop requests.\r\n */\r\n CryptoOptsGetPublicKeyThumbprint = \"cryptoOptsGetPublicKeyThumbprint\",\r\n\r\n /**\r\n * signJwt API in CryptoOpts class (msal-browser).\r\n * Used to signed a pop token.\r\n */\r\n CryptoOptsSignJwt = \"cryptoOptsSignJwt\",\r\n\r\n /**\r\n * acquireToken API in the SilentCacheClient class (msal-browser).\r\n * Used to read access tokens from the cache.\r\n */\r\n SilentCacheClientAcquireToken = \"silentCacheClientAcquireToken\",\r\n\r\n /**\r\n * acquireToken API in the SilentIframeClient class (msal-browser).\r\n * Used to acquire a new set of tokens from the authorize endpoint in a hidden iframe.\r\n */\r\n SilentIframeClientAcquireToken = \"silentIframeClientAcquireToken\",\r\n\r\n /**\r\n * acquireToken API in SilentRereshClient (msal-browser).\r\n * Used to acquire a new set of tokens from the token endpoint using a refresh token.\r\n */\r\n SilentRefreshClientAcquireToken = \"silentRefreshClientAcquireToken\",\r\n\r\n /**\r\n * ssoSilent API (msal-browser).\r\n * Used to silently acquire an authorization code and set of tokens using a hidden iframe.\r\n */\r\n SsoSilent = \"ssoSilent\",\r\n\r\n /**\r\n * getDiscoveredAuthority API in StandardInteractionClient class (msal-browser).\r\n * Used to load authority metadata for a request.\r\n */\r\n StandardInteractionClientGetDiscoveredAuthority = \"standardInteractionClientGetDiscoveredAuthority\",\r\n\r\n /**\r\n * acquireToken APIs in msal-browser.\r\n * Used to make an /authorize endpoint call with native brokering enabled.\r\n */\r\n FetchAccountIdWithNativeBroker = \"fetchAccountIdWithNativeBroker\",\r\n\r\n /**\r\n * acquireToken API in NativeInteractionClient class (msal-browser).\r\n * Used to acquire a token from Native component when native brokering is enabled.\r\n */\r\n NativeInteractionClientAcquireToken = \"nativeInteractionClientAcquireToken\",\r\n /**\r\n * Time spent creating default headers for requests to token endpoint\r\n */\r\n BaseClientCreateTokenRequestHeaders = \"baseClientCreateTokenRequestHeaders\",\r\n /**\r\n * Used to measure the time taken for completing embedded-broker handshake (PW-Broker).\r\n */\r\n BrokerHandhshake = \"brokerHandshake\",\r\n /**\r\n * acquireTokenByRefreshToken API in BrokerClientApplication (PW-Broker) .\r\n */\r\n AcquireTokenByRefreshTokenInBroker = \"acquireTokenByRefreshTokenInBroker\",\r\n /**\r\n * Time taken for token acquisition by broker\r\n */\r\n AcquireTokenByBroker = \"acquireTokenByBroker\",\r\n\r\n /**\r\n * Time spent on the network for refresh token acquisition\r\n */\r\n RefreshTokenClientExecuteTokenRequest = \"refreshTokenClientExecuteTokenRequest\",\r\n\r\n /**\r\n * Time taken for acquiring refresh token , records RT size\r\n */\r\n RefreshTokenClientAcquireToken = \"refreshTokenClientAcquireToken\",\r\n\r\n /**\r\n * Time taken for acquiring cached refresh token\r\n */\r\n RefreshTokenClientAcquireTokenWithCachedRefreshToken = \"refreshTokenClientAcquireTokenWithCachedRefreshToken\",\r\n\r\n /**\r\n * acquireTokenByRefreshToken API in RefreshTokenClient (msal-common).\r\n */\r\n RefreshTokenClientAcquireTokenByRefreshToken = \"refreshTokenClientAcquireTokenByRefreshToken\",\r\n\r\n /**\r\n * Helper function to create token request body in RefreshTokenClient (msal-common).\r\n */\r\n RefreshTokenClientCreateTokenRequestBody = \"refreshTokenClientCreateTokenRequestBody\",\r\n\r\n /**\r\n * acquireTokenFromCache (msal-browser).\r\n * Internal API for acquiring token from cache\r\n */\r\n AcquireTokenFromCache = \"acquireTokenFromCache\",\r\n\r\n /**\r\n * acquireTokenBySilentIframe (msal-browser).\r\n * Internal API for acquiring token by silent Iframe\r\n */\r\n AcquireTokenBySilentIframe = \"acquireTokenBySilentIframe\",\r\n\r\n /**\r\n * Internal API for initializing base request in BaseInteractionClient (msal-browser)\r\n */\r\n InitializeBaseRequest = \"initializeBaseRequest\",\r\n\r\n /**\r\n * Internal API for initializing silent request in SilentCacheClient (msal-browser)\r\n */\r\n InitializeSilentRequest = \"initializeSilentRequest\",\r\n\r\n InitializeClientApplication = \"initializeClientApplication\",\r\n\r\n /**\r\n * Helper function in SilentIframeClient class (msal-browser).\r\n */\r\n SilentIframeClientTokenHelper = \"silentIframeClientTokenHelper\",\r\n\r\n /**\r\n * SilentHandler\r\n */\r\n SilentHandlerInitiateAuthRequest = \"silentHandlerInitiateAuthRequest\",\r\n SilentHandlerMonitorIframeForHash = \"silentHandlerMonitorIframeForHash\",\r\n SilentHandlerLoadFrame = \"silentHandlerLoadFrame\",\r\n\r\n /**\r\n * Helper functions in StandardInteractionClient class (msal-browser)\r\n */\r\n StandardInteractionClientCreateAuthCodeClient = \"standardInteractionClientCreateAuthCodeClient\",\r\n StandardInteractionClientGetClientConfiguration = \"standardInteractionClientGetClientConfiguration\",\r\n StandardInteractionClientInitializeAuthorizationRequest = \"standardInteractionClientInitializeAuthorizationRequest\",\r\n StandardInteractionClientInitializeAuthorizationCodeRequest = \"standardInteractionClientInitializeAuthorizationCodeRequest\",\r\n\r\n /**\r\n * getAuthCodeUrl API (msal-browser and msal-node).\r\n */\r\n GetAuthCodeUrl = \"getAuthCodeUrl\",\r\n\r\n /**\r\n * Functions from InteractionHandler (msal-browser)\r\n */\r\n HandleCodeResponseFromServer = \"handleCodeResponseFromServer\",\r\n HandleCodeResponseFromHash = \"handleCodeResponseFromHash\",\r\n UpdateTokenEndpointAuthority = \"updateTokenEndpointAuthority\",\r\n\r\n /**\r\n * APIs in Authorization Code Client (msal-common)\r\n */\r\n AuthClientAcquireToken = \"authClientAcquireToken\",\r\n AuthClientExecuteTokenRequest = \"authClientExecuteTokenRequest\",\r\n AuthClientCreateTokenRequestBody = \"authClientCreateTokenRequestBody\",\r\n AuthClientCreateQueryString = \"authClientCreateQueryString\",\r\n\r\n /**\r\n * Generate functions in PopTokenGenerator (msal-common)\r\n */\r\n PopTokenGenerateCnf = \"popTokenGenerateCnf\",\r\n PopTokenGenerateKid = \"popTokenGenerateKid\",\r\n\r\n /**\r\n * handleServerTokenResponse API in ResponseHandler (msal-common)\r\n */\r\n HandleServerTokenResponse = \"handleServerTokenResponse\",\r\n\r\n /**\r\n * Authority functions\r\n */\r\n AuthorityFactoryCreateDiscoveredInstance = \"authorityFactoryCreateDiscoveredInstance\",\r\n AuthorityResolveEndpointsAsync = \"authorityResolveEndpointsAsync\",\r\n AuthorityGetCloudDiscoveryMetadataFromNetwork = \"authorityGetCloudDiscoveryMetadataFromNetwork\",\r\n AuthorityUpdateCloudDiscoveryMetadata = \"authorityUpdateCloudDiscoveryMetadata\",\r\n AuthorityGetEndpointMetadataFromNetwork = \"authorityGetEndpointMetadataFromNetwork\",\r\n AuthorityUpdateEndpointMetadata = \"authorityUpdateEndpointMetadata\",\r\n AuthorityUpdateMetadataWithRegionalInformation = \"authorityUpdateMetadataWithRegionalInformation\",\r\n\r\n /**\r\n * Region Discovery functions\r\n */\r\n RegionDiscoveryDetectRegion = \"regionDiscoveryDetectRegion\",\r\n RegionDiscoveryGetRegionFromIMDS = \"regionDiscoveryGetRegionFromIMDS\",\r\n RegionDiscoveryGetCurrentVersion = \"regionDiscoveryGetCurrentVersion\",\r\n\r\n AcquireTokenByCodeAsync = \"acquireTokenByCodeAsync\",\r\n\r\n GetEndpointMetadataFromNetwork = \"getEndpointMetadataFromNetwork\",\r\n GetCloudDiscoveryMetadataFromNetworkMeasurement = \"getCloudDiscoveryMetadataFromNetworkMeasurement\",\r\n\r\n HandleRedirectPromiseMeasurement= \"handleRedirectPromiseMeasurement\",\r\n\r\n UpdateCloudDiscoveryMetadataMeasurement = \"updateCloudDiscoveryMetadataMeasurement\",\r\n\r\n UsernamePasswordClientAcquireToken = \"usernamePasswordClientAcquireToken\",\r\n\r\n NativeMessageHandlerHandshake = \"nativeMessageHandlerHandshake\",\r\n\r\n /**\r\n * Cache operations\r\n */\r\n ClearTokensAndKeysWithClaims = \"clearTokensAndKeysWithClaims\",\r\n}\r\n\r\n/**\r\n * State of the performance event.\r\n *\r\n * @export\r\n * @enum {number}\r\n */\r\nexport enum PerformanceEventStatus {\r\n NotStarted,\r\n InProgress,\r\n Completed\r\n}\r\n\r\n/**\r\n * Fields whose value will not change throughout a request\r\n */\r\nexport type StaticFields = {\r\n /**\r\n * The Silent Token Cache Lookup Policy\r\n *\r\n * @type {?(number | undefined)}\r\n */\r\n cacheLookupPolicy?: number | undefined,\r\n\r\n /**\r\n * Size of the id token\r\n *\r\n * @type {number}\r\n */\r\n idTokenSize?: number,\r\n\r\n /**\r\n *\r\n * Size of the access token\r\n *\r\n * @type {number}\r\n */\r\n\r\n accessTokenSize?: number,\r\n\r\n /**\r\n *\r\n * Size of the refresh token\r\n *\r\n * @type {number}\r\n */\r\n\r\n refreshTokenSize?: number | undefined,\r\n\r\n /**\r\n * Application name as specified by the app.\r\n *\r\n * @type {?string}\r\n */\r\n appName?: string,\r\n\r\n /**\r\n * Application version as specified by the app.\r\n *\r\n * @type {?string}\r\n */\r\n appVersion?: string,\r\n\r\n /**\r\n * The following are fields that may be emitted in native broker scenarios\r\n */\r\n extensionId?: string,\r\n extensionVersion?: string\r\n matsBrokerVersion?: string;\r\n matsAccountJoinOnStart?: string;\r\n matsAccountJoinOnEnd?: string;\r\n matsDeviceJoin?: string;\r\n matsPromptBehavior?: string;\r\n matsApiErrorCode?: number;\r\n matsUiVisible?: boolean;\r\n matsSilentCode?: number;\r\n matsSilentBiSubCode?: number;\r\n matsSilentMessage?: string;\r\n matsSilentStatus?: number;\r\n matsHttpStatus?: number\r\n matsHttpEventCount?: number;\r\n httpVerToken?: string;\r\n httpVerAuthority?: string;\r\n\r\n /**\r\n * Native broker fields\r\n */\r\n allowNativeBroker?: boolean;\r\n extensionInstalled?: boolean;\r\n extensionHandshakeTimeoutMs?: number;\r\n extensionHandshakeTimedOut?: boolean;\r\n};\r\n\r\n/**\r\n * Fields whose value may change throughout a request\r\n */\r\nexport type Counters = {\r\n visibilityChangeCount?: number;\r\n incompleteSubsCount?: number;\r\n /**\r\n * Amount of times queued in the JS event queue.\r\n *\r\n * @type {?number}\r\n */\r\n queuedCount?: number\r\n /**\r\n * Amount of manually completed queue events.\r\n *\r\n * @type {?number}\r\n */\r\n queuedManuallyCompletedCount?: number;\r\n};\r\n\r\nexport type SubMeasurement = {\r\n name: PerformanceEvents,\r\n startTimeMs: number\r\n};\r\n\r\n/**\r\n * Performance measurement taken by the library, including metadata about the request and application.\r\n *\r\n * @export\r\n * @typedef {PerformanceEvent}\r\n */\r\nexport type PerformanceEvent = StaticFields & Counters & {\r\n /**\r\n * Unique id for the event\r\n *\r\n * @type {string}\r\n */\r\n eventId: string,\r\n\r\n /**\r\n * State of the perforance measure.\r\n *\r\n * @type {PerformanceEventStatus}\r\n */\r\n status: PerformanceEventStatus,\r\n\r\n /**\r\n * Login authority used for the request\r\n *\r\n * @type {string}\r\n */\r\n authority: string,\r\n\r\n /**\r\n * Client id for the application\r\n *\r\n * @type {string}\r\n */\r\n clientId: string\r\n\r\n /**\r\n * Correlation ID used for the request\r\n *\r\n * @type {string}\r\n */\r\n correlationId: string,\r\n\r\n /**\r\n * End-to-end duration in milliseconds.\r\n * @date 3/22/2022 - 3:40:05 PM\r\n *\r\n * @type {number}\r\n */\r\n durationMs?: number,\r\n\r\n /**\r\n * Visibility of the page when the event completed.\r\n * Read from: https://developer.mozilla.org/docs/Web/API/Page_Visibility_API\r\n *\r\n * @type {?(string | null)}\r\n */\r\n endPageVisibility?: string | null,\r\n\r\n /**\r\n * Whether the result was retrieved from the cache.\r\n *\r\n * @type {(boolean | null)}\r\n */\r\n fromCache?: boolean | null,\r\n\r\n /**\r\n * Event name (usually in the form of classNameFunctionName)\r\n *\r\n * @type {PerformanceEvents}\r\n */\r\n name: PerformanceEvents,\r\n\r\n /**\r\n * Visibility of the page when the event completed.\r\n * Read from: https://developer.mozilla.org/docs/Web/API/Page_Visibility_API\r\n *\r\n * @type {?(string | null)}\r\n */\r\n startPageVisibility?: string | null,\r\n\r\n /**\r\n * Unix millisecond timestamp when the event was initiated.\r\n *\r\n * @type {number}\r\n */\r\n startTimeMs: number,\r\n\r\n /**\r\n * Whether or the operation completed successfully.\r\n *\r\n * @type {(boolean | null)}\r\n */\r\n success?: boolean | null,\r\n\r\n /**\r\n * Add specific error code in case of failure\r\n *\r\n * @type {string}\r\n */\r\n errorCode?: string,\r\n\r\n /**\r\n * Add specific sub error code in case of failure\r\n *\r\n * @type {string}\r\n */\r\n subErrorCode?: string,\r\n\r\n /**\r\n * Name of the library used for the operation.\r\n *\r\n * @type {string}\r\n */\r\n libraryName: string,\r\n\r\n /**\r\n * Version of the library used for the operation.\r\n *\r\n * @type {string}\r\n */\r\n libraryVersion: string,\r\n\r\n /**\r\n * Whether the response is from a native component (e.g., WAM)\r\n *\r\n * @type {?boolean}\r\n */\r\n isNativeBroker?: boolean,\r\n\r\n /**\r\n * Request ID returned from the response\r\n *\r\n * @type {?string}\r\n */\r\n requestId?: string\r\n\r\n /**\r\n * Cache lookup policy\r\n *\r\n * @type {?number}\r\n */\r\n cacheLookupPolicy?: number | undefined,\r\n\r\n /**\r\n * Amount of time spent in the JS queue in milliseconds.\r\n *\r\n * @type {?number}\r\n */\r\n queuedTimeMs?: number,\r\n\r\n /**\r\n * Sub-measurements for internal use. To be deleted before flushing.\r\n */\r\n incompleteSubMeasurements?: Map\r\n};\r\n\r\nexport const IntFields: ReadonlySet = new Set([\r\n \"accessTokenSize\",\r\n \"durationMs\",\r\n \"idTokenSize\",\r\n \"matsSilentStatus\",\r\n \"matsHttpStatus\",\r\n \"refreshTokenSize\",\r\n \"queuedTimeMs\",\r\n \"startTimeMs\",\r\n \"status\",\r\n]);\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { Logger } from \"@azure/msal-common\";\r\nimport { CachedKeyPair } from \"../crypto/CryptoOps\";\r\nimport { AsyncMemoryStorage } from \"./AsyncMemoryStorage\";\r\n\r\nexport enum CryptoKeyStoreNames {\r\n asymmetricKeys = \"asymmetricKeys\",\r\n symmetricKeys = \"symmetricKeys\"\r\n}\r\n/**\r\n * MSAL CryptoKeyStore DB Version 2\r\n */\r\nexport class CryptoKeyStore {\r\n public asymmetricKeys: AsyncMemoryStorage;\r\n public symmetricKeys: AsyncMemoryStorage;\r\n public logger: Logger;\r\n\r\n constructor(logger: Logger){\r\n this.logger = logger;\r\n this.asymmetricKeys = new AsyncMemoryStorage(this.logger, CryptoKeyStoreNames.asymmetricKeys);\r\n this.symmetricKeys = new AsyncMemoryStorage(this.logger, CryptoKeyStoreNames.symmetricKeys);\r\n }\r\n\r\n async clear(): Promise {\r\n // Delete in-memory keystores\r\n this.asymmetricKeys.clearInMemory();\r\n\t this.symmetricKeys.clearInMemory();\r\n\t\t\r\n /**\r\n * There is only one database, so calling clearPersistent on asymmetric keystore takes care of\r\n * every persistent keystore\r\n */\r\n try {\r\n await this.asymmetricKeys.clearPersistent();\r\n return true;\r\n } catch (e) {\r\n if (e instanceof Error) {\r\n this.logger.error(`Clearing keystore failed with error: ${e.message}`);\r\n } else {\r\n this.logger.error(\"Clearing keystore failed with unknown error\");\r\n }\r\n \r\n return false;\r\n }\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { AuthError } from \"./AuthError\";\r\n\r\n/**\r\n * Error thrown when there is an error with the server code, for example, unavailability.\r\n */\r\nexport class ServerError extends AuthError {\r\n\r\n constructor(errorCode?: string, errorMessage?: string, subError?: string) {\r\n super(errorCode, errorMessage, subError);\r\n this.name = \"ServerError\";\r\n\r\n Object.setPrototypeOf(this, ServerError.prototype);\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { AuthError } from \"./AuthError\";\r\n\r\n/**\r\n * ClientAuthErrorMessage class containing string constants used by error codes and messages.\r\n */\r\nexport const JoseHeaderErrorMessage = {\r\n missingKidError: {\r\n code: \"missing_kid_error\",\r\n desc: \"The JOSE Header for the requested JWT, JWS or JWK object requires a keyId to be configured as the 'kid' header claim. No 'kid' value was provided.\"\r\n },\r\n missingAlgError: {\r\n code: \"missing_alg_error\",\r\n desc: \"The JOSE Header for the requested JWT, JWS or JWK object requires an algorithm to be specified as the 'alg' header claim. No 'alg' value was provided.\"\r\n },\r\n};\r\n\r\n/**\r\n * Error thrown when there is an error in the client code running on the browser.\r\n */\r\nexport class JoseHeaderError extends AuthError {\r\n constructor(errorCode: string, errorMessage?: string) {\r\n super(errorCode, errorMessage);\r\n this.name = \"JoseHeaderError\";\r\n\r\n Object.setPrototypeOf(this, JoseHeaderError.prototype);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when keyId isn't set on JOSE header.\r\n */\r\n static createMissingKidError(): JoseHeaderError {\r\n return new JoseHeaderError(JoseHeaderErrorMessage.missingKidError.code, JoseHeaderErrorMessage.missingKidError.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when algorithm isn't set on JOSE header.\r\n */\r\n static createMissingAlgError(): JoseHeaderError {\r\n return new JoseHeaderError(JoseHeaderErrorMessage.missingAlgError.code, JoseHeaderErrorMessage.missingAlgError.desc);\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { JoseHeaderError } from \"../error/JoseHeaderError\";\r\nimport { JsonTypes } from \"../utils/Constants\";\r\n\r\nexport type JoseHeaderOptions = {\r\n typ?: JsonTypes,\r\n alg?: string,\r\n kid?: string\r\n};\r\n\r\nexport class JoseHeader {\r\n public typ?: JsonTypes;\r\n public alg?: string;\r\n public kid?: string;\r\n\r\n constructor (options: JoseHeaderOptions) {\r\n this.typ = options.typ;\r\n this.alg = options.alg;\r\n this.kid = options.kid;\r\n }\r\n\r\n /**\r\n * Builds SignedHttpRequest formatted JOSE Header from the\r\n * JOSE Header options provided or previously set on the object and returns\r\n * the stringified header object.\r\n * Throws if keyId or algorithm aren't provided since they are required for Access Token Binding.\r\n * @param shrHeaderOptions \r\n * @returns \r\n */\r\n static getShrHeaderString(shrHeaderOptions: JoseHeaderOptions): string {\r\n // KeyID is required on the SHR header\r\n if (!shrHeaderOptions.kid) {\r\n throw JoseHeaderError.createMissingKidError();\r\n }\r\n\r\n // Alg is required on the SHR header\r\n if (!shrHeaderOptions.alg) {\r\n throw JoseHeaderError.createMissingAlgError();\r\n }\r\n\r\n const shrHeader = new JoseHeader({\r\n // Access Token PoP headers must have type pop, but the type header can be overriden for special cases\r\n typ: shrHeaderOptions.typ || JsonTypes.Pop,\r\n kid: shrHeaderOptions.kid,\r\n alg: shrHeaderOptions.alg\r\n });\r\n\r\n return JSON.stringify(shrHeader);\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\n/**\r\n * Utility class for math specific functions in browser.\r\n */\r\nexport class MathUtils {\r\n\r\n /**\r\n * Decimal to Hex\r\n *\r\n * @param num\r\n */\r\n static decimalToHex(num: number): string {\r\n let hex: string = num.toString(16);\r\n while (hex.length < 2) {\r\n hex = \"0\" + hex;\r\n }\r\n return hex;\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { Constants , IGuidGenerator } from \"@azure/msal-common\";\r\nimport { MathUtils } from \"../utils/MathUtils\";\r\nimport { BrowserCrypto } from \"./BrowserCrypto\";\r\nexport class GuidGenerator implements IGuidGenerator {\r\n\r\n // browser crypto object used to generate random values\r\n private cryptoObj: BrowserCrypto;\r\n\r\n constructor(cryptoObj: BrowserCrypto) {\r\n this.cryptoObj = cryptoObj;\r\n }\r\n\r\n /*\r\n * RFC4122: The version 4 UUID is meant for generating UUIDs from truly-random or\r\n * pseudo-random numbers.\r\n * The algorithm is as follows:\r\n * Set the two most significant bits (bits 6 and 7) of the\r\n * clock_seq_hi_and_reserved to zero and one, respectively.\r\n * Set the four most significant bits (bits 12 through 15) of the\r\n * time_hi_and_version field to the 4-bit version number from\r\n * Section 4.1.3. Version4\r\n * Set all the other bits to randomly (or pseudo-randomly) chosen\r\n * values.\r\n * UUID = time-low \"-\" time-mid \"-\"time-high-and-version \"-\"clock-seq-reserved and low(2hexOctet)\"-\" node\r\n * time-low = 4hexOctet\r\n * time-mid = 2hexOctet\r\n * time-high-and-version = 2hexOctet\r\n * clock-seq-and-reserved = hexOctet:\r\n * clock-seq-low = hexOctet\r\n * node = 6hexOctet\r\n * Format: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\r\n * y could be 1000, 1001, 1010, 1011 since most significant two bits needs to be 10\r\n * y values are 8, 9, A, B\r\n */\r\n generateGuid(): string {\r\n try {\r\n const buffer: Uint8Array = new Uint8Array(16);\r\n this.cryptoObj.getRandomValues(buffer);\r\n\r\n // buffer[6] and buffer[7] represents the time_hi_and_version field. We will set the four most significant bits (4 through 7) of buffer[6] to represent decimal number 4 (UUID version number).\r\n buffer[6] |= 0x40; // buffer[6] | 01000000 will set the 6 bit to 1.\r\n buffer[6] &= 0x4f; // buffer[6] & 01001111 will set the 4, 5, and 7 bit to 0 such that bits 4-7 == 0100 = \"4\".\r\n\r\n // buffer[8] represents the clock_seq_hi_and_reserved field. We will set the two most significant bits (6 and 7) of the clock_seq_hi_and_reserved to zero and one, respectively.\r\n buffer[8] |= 0x80; // buffer[8] | 10000000 will set the 7 bit to 1.\r\n buffer[8] &= 0xbf; // buffer[8] & 10111111 will set the 6 bit to 0.\r\n\r\n return MathUtils.decimalToHex(buffer[0]) + MathUtils.decimalToHex(buffer[1])\r\n + MathUtils.decimalToHex(buffer[2]) + MathUtils.decimalToHex(buffer[3])\r\n + \"-\" + MathUtils.decimalToHex(buffer[4]) + MathUtils.decimalToHex(buffer[5])\r\n + \"-\" + MathUtils.decimalToHex(buffer[6]) + MathUtils.decimalToHex(buffer[7])\r\n + \"-\" + MathUtils.decimalToHex(buffer[8]) + MathUtils.decimalToHex(buffer[9])\r\n + \"-\" + MathUtils.decimalToHex(buffer[10]) + MathUtils.decimalToHex(buffer[11])\r\n + MathUtils.decimalToHex(buffer[12]) + MathUtils.decimalToHex(buffer[13])\r\n + MathUtils.decimalToHex(buffer[14]) + MathUtils.decimalToHex(buffer[15]);\r\n }\r\n catch (err) {\r\n const guidHolder: string = \"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\";\r\n const hex: string = \"0123456789abcdef\";\r\n let r: number = 0;\r\n let guidResponse: string = Constants.EMPTY_STRING;\r\n for (let i: number = 0; i < 36; i++) {\r\n if (guidHolder[i] !== \"-\" && guidHolder[i] !== \"4\") {\r\n // each x and y needs to be random\r\n r = Math.random() * 16 | 0;\r\n }\r\n if (guidHolder[i] === \"x\") {\r\n guidResponse += hex[r];\r\n } else if (guidHolder[i] === \"y\") {\r\n // clock-seq-and-reserved first hex is filtered and remaining hex values are random\r\n r &= 0x3; // bit and with 0011 to set pos 2 to zero ?0??\r\n r |= 0x8; // set pos 3 to 1 as 1???\r\n guidResponse += hex[r];\r\n } else {\r\n guidResponse += guidHolder[i];\r\n }\r\n }\r\n return guidResponse;\r\n }\r\n }\r\n\r\n /**\r\n * verifies if a string is GUID\r\n * @param guid\r\n */\r\n isGuid(guid: string): boolean {\r\n const regexGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;\r\n return regexGuid.test(guid);\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { Constants } from \"@azure/msal-common\";\r\n\r\n/**\r\n * Utility functions for strings in a browser. See here for implementation details:\r\n * https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#Solution_2_%E2%80%93_JavaScript's_UTF-16_%3E_UTF-8_%3E_base64\r\n */\r\nexport class BrowserStringUtils {\r\n\r\n /**\r\n * Converts string to Uint8Array\r\n * @param sDOMStr \r\n */\r\n static stringToUtf8Arr (sDOMStr: string): Uint8Array {\r\n let nChr;\r\n let nArrLen = 0;\r\n const nStrLen = sDOMStr.length;\r\n /* mapping... */\r\n for (let nMapIdx = 0; nMapIdx < nStrLen; nMapIdx++) {\r\n nChr = sDOMStr.charCodeAt(nMapIdx);\r\n nArrLen += nChr < 0x80 ? 1 : nChr < 0x800 ? 2 : nChr < 0x10000 ? 3 : nChr < 0x200000 ? 4 : nChr < 0x4000000 ? 5 : 6;\r\n }\r\n\r\n const aBytes = new Uint8Array(nArrLen);\r\n\r\n /* transcription... */\r\n\r\n for (let nIdx = 0, nChrIdx = 0; nIdx < nArrLen; nChrIdx++) {\r\n nChr = sDOMStr.charCodeAt(nChrIdx);\r\n if (nChr < 128) {\r\n /* one byte */\r\n aBytes[nIdx++] = nChr;\r\n } else if (nChr < 0x800) {\r\n /* two bytes */\r\n aBytes[nIdx++] = 192 + (nChr >>> 6);\r\n aBytes[nIdx++] = 128 + (nChr & 63);\r\n } else if (nChr < 0x10000) {\r\n /* three bytes */\r\n aBytes[nIdx++] = 224 + (nChr >>> 12);\r\n aBytes[nIdx++] = 128 + (nChr >>> 6 & 63);\r\n aBytes[nIdx++] = 128 + (nChr & 63);\r\n } else if (nChr < 0x200000) {\r\n /* four bytes */\r\n aBytes[nIdx++] = 240 + (nChr >>> 18);\r\n aBytes[nIdx++] = 128 + (nChr >>> 12 & 63);\r\n aBytes[nIdx++] = 128 + (nChr >>> 6 & 63);\r\n aBytes[nIdx++] = 128 + (nChr & 63);\r\n } else if (nChr < 0x4000000) {\r\n /* five bytes */\r\n aBytes[nIdx++] = 248 + (nChr >>> 24);\r\n aBytes[nIdx++] = 128 + (nChr >>> 18 & 63);\r\n aBytes[nIdx++] = 128 + (nChr >>> 12 & 63);\r\n aBytes[nIdx++] = 128 + (nChr >>> 6 & 63);\r\n aBytes[nIdx++] = 128 + (nChr & 63);\r\n } else /* if (nChr <= 0x7fffffff) */ {\r\n /* six bytes */\r\n aBytes[nIdx++] = 252 + (nChr >>> 30);\r\n aBytes[nIdx++] = 128 + (nChr >>> 24 & 63);\r\n aBytes[nIdx++] = 128 + (nChr >>> 18 & 63);\r\n aBytes[nIdx++] = 128 + (nChr >>> 12 & 63);\r\n aBytes[nIdx++] = 128 + (nChr >>> 6 & 63);\r\n aBytes[nIdx++] = 128 + (nChr & 63);\r\n }\r\n }\r\n\r\n return aBytes; \r\n }\r\n\r\n /**\r\n * Converst string to ArrayBuffer\r\n * @param dataString \r\n */\r\n static stringToArrayBuffer(dataString: string): ArrayBuffer {\r\n const data = new ArrayBuffer(dataString.length);\r\n const dataView = new Uint8Array(data);\r\n for (let i: number = 0; i < dataString.length; i++) {\r\n dataView[i] = dataString.charCodeAt(i);\r\n }\r\n return data;\r\n }\r\n\r\n /**\r\n * Converts Uint8Array to a string\r\n * @param aBytes \r\n */\r\n static utf8ArrToString (aBytes: Uint8Array): string {\r\n let sView = Constants.EMPTY_STRING;\r\n for (let nPart, nLen = aBytes.length, nIdx = 0; nIdx < nLen; nIdx++) {\r\n nPart = aBytes[nIdx];\r\n sView += String.fromCharCode(\r\n nPart > 251 && nPart < 254 && nIdx + 5 < nLen ? /* six bytes */\r\n /* (nPart - 252 << 30) may be not so safe in ECMAScript! So...: */\r\n (nPart - 252) * 1073741824 + (aBytes[++nIdx] - 128 << 24) + (aBytes[++nIdx] - 128 << 18) + (aBytes[++nIdx] - 128 << 12) + (aBytes[++nIdx] - 128 << 6) + aBytes[++nIdx] - 128\r\n : nPart > 247 && nPart < 252 && nIdx + 4 < nLen ? /* five bytes */\r\n (nPart - 248 << 24) + (aBytes[++nIdx] - 128 << 18) + (aBytes[++nIdx] - 128 << 12) + (aBytes[++nIdx] - 128 << 6) + aBytes[++nIdx] - 128\r\n : nPart > 239 && nPart < 248 && nIdx + 3 < nLen ? /* four bytes */\r\n (nPart - 240 << 18) + (aBytes[++nIdx] - 128 << 12) + (aBytes[++nIdx] - 128 << 6) + aBytes[++nIdx] - 128\r\n : nPart > 223 && nPart < 240 && nIdx + 2 < nLen ? /* three bytes */\r\n (nPart - 224 << 12) + (aBytes[++nIdx] - 128 << 6) + aBytes[++nIdx] - 128\r\n : nPart > 191 && nPart < 224 && nIdx + 1 < nLen ? /* two bytes */\r\n (nPart - 192 << 6) + aBytes[++nIdx] - 128\r\n : /* nPart < 127 ? */ /* one byte */\r\n nPart\r\n );\r\n }\r\n return sView;\r\n }\r\n\r\n /**\r\n * Returns stringified jwk.\r\n * @param jwk \r\n */\r\n static getSortedObjectString(obj: object): string {\r\n return JSON.stringify(obj, Object.keys(obj).sort());\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { Constants } from \"@azure/msal-common\";\r\nimport { BrowserStringUtils } from \"../utils/BrowserStringUtils\";\r\n\r\n/**\r\n * Class which exposes APIs to encode plaintext to base64 encoded string. See here for implementation details:\r\n * https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#Solution_2_%E2%80%93_JavaScript's_UTF-16_%3E_UTF-8_%3E_base64\r\n */\r\nexport class Base64Encode {\r\n \r\n /**\r\n * Returns URL Safe b64 encoded string from a plaintext string.\r\n * @param input \r\n */\r\n urlEncode(input: string): string {\r\n return encodeURIComponent(this.encode(input)\r\n .replace(/=/g, Constants.EMPTY_STRING)\r\n .replace(/\\+/g, \"-\")\r\n .replace(/\\//g, \"_\"));\r\n }\r\n\r\n /**\r\n * Returns URL Safe b64 encoded string from an int8Array.\r\n * @param inputArr \r\n */\r\n urlEncodeArr(inputArr: Uint8Array): string {\r\n return this.base64EncArr(inputArr)\r\n .replace(/=/g, Constants.EMPTY_STRING)\r\n .replace(/\\+/g, \"-\")\r\n .replace(/\\//g, \"_\");\r\n }\r\n\r\n /**\r\n * Returns b64 encoded string from plaintext string.\r\n * @param input \r\n */\r\n encode(input: string): string {\r\n const inputUtf8Arr = BrowserStringUtils.stringToUtf8Arr(input);\r\n return this.base64EncArr(inputUtf8Arr);\r\n }\r\n\r\n /**\r\n * Base64 encode byte array\r\n * @param aBytes \r\n */\r\n private base64EncArr(aBytes: Uint8Array): string { \r\n const eqLen = (3 - (aBytes.length % 3)) % 3;\r\n let sB64Enc = Constants.EMPTY_STRING;\r\n \r\n for (let nMod3, nLen = aBytes.length, nUint24 = 0, nIdx = 0; nIdx < nLen; nIdx++) {\r\n nMod3 = nIdx % 3;\r\n /* Uncomment the following line in order to split the output in lines 76-character long: */\r\n /*\r\n *if (nIdx > 0 && (nIdx * 4 / 3) % 76 === 0) { sB64Enc += \"\\r\\n\"; }\r\n */\r\n nUint24 |= aBytes[nIdx] << (16 >>> nMod3 & 24);\r\n if (nMod3 === 2 || aBytes.length - nIdx === 1) {\r\n sB64Enc += String.fromCharCode(\r\n this.uint6ToB64(nUint24 >>> 18 & 63), \r\n this.uint6ToB64(nUint24 >>> 12 & 63), \r\n this.uint6ToB64(nUint24 >>> 6 & 63), \r\n this.uint6ToB64(nUint24 & 63)\r\n );\r\n nUint24 = 0;\r\n }\r\n }\r\n\r\n return eqLen === 0 ? sB64Enc : sB64Enc.substring(0, sB64Enc.length - eqLen) + (eqLen === 1 ? \"=\" : \"==\");\r\n }\r\n\r\n /**\r\n * Base64 string to array encoding helper\r\n * @param nUint6 \r\n */\r\n private uint6ToB64 (nUint6: number): number {\r\n return nUint6 < 26 ?\r\n nUint6 + 65\r\n : nUint6 < 52 ?\r\n nUint6 + 71\r\n : nUint6 < 62 ?\r\n nUint6 - 4\r\n : nUint6 === 62 ?\r\n 43\r\n : nUint6 === 63 ?\r\n 47\r\n :\r\n 65;\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { Constants } from \"@azure/msal-common\";\r\nimport { BrowserStringUtils } from \"../utils/BrowserStringUtils\";\r\n\r\n/**\r\n * Class which exposes APIs to decode base64 strings to plaintext. See here for implementation details:\r\n * https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#Solution_2_%E2%80%93_JavaScript's_UTF-16_%3E_UTF-8_%3E_base64\r\n */\r\nexport class Base64Decode {\r\n\r\n /**\r\n * Returns a URL-safe plaintext decoded string from b64 encoded input.\r\n * @param input \r\n */\r\n decode(input: string): string {\r\n let encodedString = input.replace(/-/g, \"+\").replace(/_/g, \"/\");\r\n switch (encodedString.length % 4) {\r\n case 0:\r\n break;\r\n case 2:\r\n encodedString += \"==\";\r\n break;\r\n case 3:\r\n encodedString += \"=\";\r\n break;\r\n default:\r\n throw new Error(\"Invalid base64 string\");\r\n }\r\n\r\n const inputUtf8Arr = this.base64DecToArr(encodedString);\r\n return BrowserStringUtils.utf8ArrToString(inputUtf8Arr);\r\n }\r\n\r\n /**\r\n * Decodes base64 into Uint8Array\r\n * @param base64String \r\n * @param nBlockSize \r\n */\r\n private base64DecToArr(base64String: string, nBlockSize?: number): Uint8Array {\r\n const sB64Enc = base64String.replace(/[^A-Za-z0-9\\+\\/]/g, Constants.EMPTY_STRING);\r\n const nInLen = sB64Enc.length;\r\n const nOutLen = nBlockSize ? Math.ceil((nInLen * 3 + 1 >>> 2) / nBlockSize) * nBlockSize : nInLen * 3 + 1 >>> 2;\r\n const aBytes = new Uint8Array(nOutLen);\r\n\r\n for (let nMod3, nMod4, nUint24 = 0, nOutIdx = 0, nInIdx = 0; nInIdx < nInLen; nInIdx++) {\r\n nMod4 = nInIdx & 3;\r\n nUint24 |= this.b64ToUint6(sB64Enc.charCodeAt(nInIdx)) << 18 - 6 * nMod4;\r\n if (nMod4 === 3 || nInLen - nInIdx === 1) {\r\n for (nMod3 = 0; nMod3 < 3 && nOutIdx < nOutLen; nMod3++, nOutIdx++) {\r\n aBytes[nOutIdx] = nUint24 >>> (16 >>> nMod3 & 24) & 255;\r\n }\r\n nUint24 = 0;\r\n }\r\n }\r\n\r\n return aBytes;\r\n }\r\n\r\n /**\r\n * Base64 string to array decoding helper\r\n * @param charNum \r\n */\r\n private b64ToUint6(charNum: number): number {\r\n return charNum > 64 && charNum < 91 ?\r\n charNum - 65\r\n : charNum > 96 && charNum < 123 ? \r\n charNum - 71\r\n : charNum > 47 && charNum < 58 ?\r\n charNum + 4\r\n : charNum === 43 ?\r\n 62\r\n : charNum === 47 ?\r\n 63\r\n :\r\n 0;\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { AuthError, StringUtils } from \"@azure/msal-common\";\r\n\r\n/**\r\n * BrowserAuthErrorMessage class containing string constants used by error codes and messages.\r\n */\r\nexport const BrowserAuthErrorMessage = {\r\n pkceNotGenerated: {\r\n code: \"pkce_not_created\",\r\n desc: \"The PKCE code challenge and verifier could not be generated.\"\r\n },\r\n cryptoDoesNotExist: {\r\n code: \"crypto_nonexistent\",\r\n desc: \"The crypto object or function is not available.\"\r\n },\r\n httpMethodNotImplementedError: {\r\n code: \"http_method_not_implemented\",\r\n desc: \"The HTTP method given has not been implemented in this library.\"\r\n },\r\n emptyNavigateUriError: {\r\n code: \"empty_navigate_uri\",\r\n desc: \"Navigation URI is empty. Please check stack trace for more info.\"\r\n },\r\n hashEmptyError: {\r\n code: \"hash_empty_error\",\r\n desc: \"Hash value cannot be processed because it is empty. Please verify that your redirectUri is not clearing the hash. For more visit: aka.ms/msaljs/browser-errors.\"\r\n },\r\n hashDoesNotContainStateError: {\r\n code: \"no_state_in_hash\",\r\n desc: \"Hash does not contain state. Please verify that the request originated from msal.\"\r\n },\r\n hashDoesNotContainKnownPropertiesError: {\r\n code: \"hash_does_not_contain_known_properties\",\r\n desc: \"Hash does not contain known properites. Please verify that your redirectUri is not changing the hash. For more visit: aka.ms/msaljs/browser-errors.\"\r\n },\r\n unableToParseStateError: {\r\n code: \"unable_to_parse_state\",\r\n desc: \"Unable to parse state. Please verify that the request originated from msal.\"\r\n },\r\n stateInteractionTypeMismatchError: {\r\n code: \"state_interaction_type_mismatch\",\r\n desc: \"Hash contains state but the interaction type does not match the caller.\"\r\n },\r\n interactionInProgress: {\r\n code: \"interaction_in_progress\",\r\n desc: \"Interaction is currently in progress. Please ensure that this interaction has been completed before calling an interactive API. For more visit: aka.ms/msaljs/browser-errors.\"\r\n },\r\n popupWindowError: {\r\n code: \"popup_window_error\",\r\n desc: \"Error opening popup window. This can happen if you are using IE or if popups are blocked in the browser.\"\r\n },\r\n emptyWindowError: {\r\n code: \"empty_window_error\",\r\n desc: \"window.open returned null or undefined window object.\"\r\n },\r\n userCancelledError: {\r\n code: \"user_cancelled\",\r\n desc: \"User cancelled the flow.\"\r\n },\r\n monitorPopupTimeoutError: {\r\n code: \"monitor_window_timeout\",\r\n desc: \"Token acquisition in popup failed due to timeout. For more visit: aka.ms/msaljs/browser-errors.\"\r\n },\r\n monitorIframeTimeoutError: {\r\n code: \"monitor_window_timeout\",\r\n desc: \"Token acquisition in iframe failed due to timeout. For more visit: aka.ms/msaljs/browser-errors.\"\r\n },\r\n redirectInIframeError: {\r\n code: \"redirect_in_iframe\",\r\n desc: \"Redirects are not supported for iframed or brokered applications. Please ensure you are using MSAL.js in a top frame of the window if using the redirect APIs, or use the popup APIs.\"\r\n },\r\n blockTokenRequestsInHiddenIframeError: {\r\n code: \"block_iframe_reload\",\r\n desc: \"Request was blocked inside an iframe because MSAL detected an authentication response. For more visit: aka.ms/msaljs/browser-errors\"\r\n },\r\n blockAcquireTokenInPopupsError: {\r\n code: \"block_nested_popups\",\r\n desc: \"Request was blocked inside a popup because MSAL detected it was running in a popup.\"\r\n },\r\n iframeClosedPrematurelyError: {\r\n code: \"iframe_closed_prematurely\",\r\n desc: \"The iframe being monitored was closed prematurely.\"\r\n },\r\n silentLogoutUnsupportedError: {\r\n code: \"silent_logout_unsupported\",\r\n desc: \"Silent logout not supported. Please call logoutRedirect or logoutPopup instead.\"\r\n },\r\n noAccountError: {\r\n code: \"no_account_error\",\r\n desc: \"No account object provided to acquireTokenSilent and no active account has been set. Please call setActiveAccount or provide an account on the request.\"\r\n },\r\n silentPromptValueError: {\r\n code: \"silent_prompt_value_error\",\r\n desc: \"The value given for the prompt value is not valid for silent requests - must be set to 'none' or 'no_session'.\"\r\n },\r\n noTokenRequestCacheError: {\r\n code: \"no_token_request_cache_error\",\r\n desc: \"No token request found in cache.\"\r\n },\r\n unableToParseTokenRequestCacheError: {\r\n code: \"unable_to_parse_token_request_cache_error\",\r\n desc: \"The cached token request could not be parsed.\"\r\n },\r\n noCachedAuthorityError: {\r\n code: \"no_cached_authority_error\",\r\n desc: \"No cached authority found.\"\r\n },\r\n authRequestNotSet: {\r\n code: \"auth_request_not_set_error\",\r\n desc: \"Auth Request not set. Please ensure initiateAuthRequest was called from the InteractionHandler\"\r\n },\r\n invalidCacheType: {\r\n code: \"invalid_cache_type\",\r\n desc: \"Invalid cache type\"\r\n },\r\n notInBrowserEnvironment: {\r\n code: \"non_browser_environment\",\r\n desc: \"Login and token requests are not supported in non-browser environments.\"\r\n },\r\n databaseNotOpen: {\r\n code: \"database_not_open\",\r\n desc: \"Database is not open!\"\r\n },\r\n noNetworkConnectivity: {\r\n code: \"no_network_connectivity\",\r\n desc: \"No network connectivity. Check your internet connection.\"\r\n },\r\n postRequestFailed: {\r\n code: \"post_request_failed\",\r\n desc: \"Network request failed: If the browser threw a CORS error, check that the redirectUri is registered in the Azure App Portal as type 'SPA'\"\r\n },\r\n getRequestFailed: {\r\n code: \"get_request_failed\",\r\n desc: \"Network request failed. Please check the network trace to determine root cause.\"\r\n },\r\n failedToParseNetworkResponse: {\r\n code: \"failed_to_parse_response\",\r\n desc: \"Failed to parse network response. Check network trace.\"\r\n },\r\n unableToLoadTokenError: {\r\n code: \"unable_to_load_token\",\r\n desc: \"Error loading token to cache.\"\r\n },\r\n signingKeyNotFoundInStorage: {\r\n code: \"crypto_key_not_found\",\r\n desc: \"Cryptographic Key or Keypair not found in browser storage.\"\r\n },\r\n authCodeRequired: {\r\n code: \"auth_code_required\",\r\n desc: \"An authorization code must be provided (as the `code` property on the request) to this flow.\"\r\n },\r\n authCodeOrNativeAccountRequired: {\r\n code: \"auth_code_or_nativeAccountId_required\",\r\n desc: \"An authorization code or nativeAccountId must be provided to this flow.\"\r\n },\r\n spaCodeAndNativeAccountPresent: {\r\n code: \"spa_code_and_nativeAccountId_present\",\r\n desc: \"Request cannot contain both spa code and native account id.\"\r\n },\r\n databaseUnavailable: {\r\n code: \"database_unavailable\",\r\n desc: \"IndexedDB, which is required for persistent cryptographic key storage, is unavailable. This may be caused by browser privacy features which block persistent storage in third-party contexts.\"\r\n },\r\n unableToAcquireTokenFromNativePlatform: {\r\n code: \"unable_to_acquire_token_from_native_platform\",\r\n desc: \"Unable to acquire token from native platform. For a list of possible reasons visit aka.ms/msaljs/browser-errors.\"\r\n },\r\n nativeHandshakeTimeout: {\r\n code: \"native_handshake_timeout\",\r\n desc: \"Timed out while attempting to establish connection to browser extension\"\r\n },\r\n nativeExtensionNotInstalled: {\r\n code: \"native_extension_not_installed\",\r\n desc: \"Native extension is not installed. If you think this is a mistake call the initialize function.\"\r\n },\r\n nativeConnectionNotEstablished: {\r\n code: \"native_connection_not_established\",\r\n desc: \"Connection to native platform has not been established. Please install a compatible browser extension and run initialize(). For more please visit aka.ms/msaljs/browser-errors.\"\r\n },\r\n nativeBrokerCalledBeforeInitialize: {\r\n code: \"native_broker_called_before_initialize\",\r\n desc: \"You must call and await the initialize function before attempting to call any other MSAL API when native brokering is enabled. For more please visit aka.ms/msaljs/browser-errors.\"\r\n },\r\n nativePromptNotSupported: {\r\n code: \"native_prompt_not_supported\",\r\n desc: \"The provided prompt is not supported by the native platform. This request should be routed to the web based flow.\"\r\n }\r\n};\r\n\r\n/**\r\n * Browser library error class thrown by the MSAL.js library for SPAs\r\n */\r\nexport class BrowserAuthError extends AuthError {\r\n\r\n constructor(errorCode: string, errorMessage?: string) {\r\n super(errorCode, errorMessage);\r\n\r\n Object.setPrototypeOf(this, BrowserAuthError.prototype);\r\n this.name = \"BrowserAuthError\";\r\n }\r\n\r\n /**\r\n * Creates an error thrown when PKCE is not implemented.\r\n * @param errDetail\r\n */\r\n static createPkceNotGeneratedError(errDetail: string): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.pkceNotGenerated.code,\r\n `${BrowserAuthErrorMessage.pkceNotGenerated.desc} Detail:${errDetail}`);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the crypto object is unavailable.\r\n * @param errDetail\r\n */\r\n static createCryptoNotAvailableError(errDetail: string): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.cryptoDoesNotExist.code,\r\n `${BrowserAuthErrorMessage.cryptoDoesNotExist.desc} Detail:${errDetail}`);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when an HTTP method hasn't been implemented by the browser class.\r\n * @param method\r\n */\r\n static createHttpMethodNotImplementedError(method: string): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.httpMethodNotImplementedError.code,\r\n `${BrowserAuthErrorMessage.httpMethodNotImplementedError.desc} Given Method: ${method}`);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the navigation URI is empty.\r\n */\r\n static createEmptyNavigationUriError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.emptyNavigateUriError.code, BrowserAuthErrorMessage.emptyNavigateUriError.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the hash string value is unexpectedly empty.\r\n * @param hashValue\r\n */\r\n static createEmptyHashError(hashValue: string): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.hashEmptyError.code, `${BrowserAuthErrorMessage.hashEmptyError.desc} Given Url: ${hashValue}`);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the hash string value is unexpectedly empty.\r\n */\r\n static createHashDoesNotContainStateError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.hashDoesNotContainStateError.code, BrowserAuthErrorMessage.hashDoesNotContainStateError.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the hash string value does not contain known properties\r\n */\r\n static createHashDoesNotContainKnownPropertiesError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.hashDoesNotContainKnownPropertiesError.code, BrowserAuthErrorMessage.hashDoesNotContainKnownPropertiesError.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the hash string value is unexpectedly empty.\r\n */\r\n static createUnableToParseStateError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.unableToParseStateError.code, BrowserAuthErrorMessage.unableToParseStateError.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the state value in the hash does not match the interaction type of the API attempting to consume it.\r\n */\r\n static createStateInteractionTypeMismatchError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.stateInteractionTypeMismatchError.code, BrowserAuthErrorMessage.stateInteractionTypeMismatchError.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when a browser interaction (redirect or popup) is in progress.\r\n */\r\n static createInteractionInProgressError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.interactionInProgress.code, BrowserAuthErrorMessage.interactionInProgress.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the popup window could not be opened.\r\n * @param errDetail\r\n */\r\n static createPopupWindowError(errDetail?: string): BrowserAuthError {\r\n let errorMessage = BrowserAuthErrorMessage.popupWindowError.desc;\r\n errorMessage = !StringUtils.isEmpty(errDetail) ? `${errorMessage} Details: ${errDetail}` : errorMessage;\r\n return new BrowserAuthError(BrowserAuthErrorMessage.popupWindowError.code, errorMessage);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when window.open returns an empty window object.\r\n * @param errDetail\r\n */\r\n static createEmptyWindowCreatedError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.emptyWindowError.code, BrowserAuthErrorMessage.emptyWindowError.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the user closes a popup.\r\n */\r\n static createUserCancelledError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.userCancelledError.code,\r\n BrowserAuthErrorMessage.userCancelledError.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when monitorPopupFromHash times out for a given popup.\r\n */\r\n static createMonitorPopupTimeoutError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.monitorPopupTimeoutError.code,\r\n BrowserAuthErrorMessage.monitorPopupTimeoutError.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when monitorIframeFromHash times out for a given iframe.\r\n */\r\n static createMonitorIframeTimeoutError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.monitorIframeTimeoutError.code,\r\n BrowserAuthErrorMessage.monitorIframeTimeoutError.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when navigateWindow is called inside an iframe or brokered applications.\r\n * @param windowParentCheck\r\n */\r\n static createRedirectInIframeError(windowParentCheck: boolean): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.redirectInIframeError.code,\r\n `${BrowserAuthErrorMessage.redirectInIframeError.desc} (window.parent !== window) => ${windowParentCheck}`);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when an auth reload is done inside an iframe.\r\n */\r\n static createBlockReloadInHiddenIframeError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.blockTokenRequestsInHiddenIframeError.code,\r\n BrowserAuthErrorMessage.blockTokenRequestsInHiddenIframeError.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when a popup attempts to call an acquireToken API\r\n * @returns\r\n */\r\n static createBlockAcquireTokenInPopupsError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.blockAcquireTokenInPopupsError.code,\r\n BrowserAuthErrorMessage.blockAcquireTokenInPopupsError.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when an iframe is found to be closed before the timeout is reached.\r\n */\r\n static createIframeClosedPrematurelyError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.iframeClosedPrematurelyError.code, BrowserAuthErrorMessage.iframeClosedPrematurelyError.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the logout API is called on any of the silent interaction clients\r\n */\r\n static createSilentLogoutUnsupportedError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.silentLogoutUnsupportedError.code, BrowserAuthErrorMessage.silentLogoutUnsupportedError.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the account object is not provided in the acquireTokenSilent API.\r\n */\r\n static createNoAccountError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.noAccountError.code, BrowserAuthErrorMessage.noAccountError.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when a given prompt value is invalid for silent requests.\r\n */\r\n static createSilentPromptValueError(givenPrompt: string): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.silentPromptValueError.code, `${BrowserAuthErrorMessage.silentPromptValueError.desc} Given value: ${givenPrompt}`);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the cached token request could not be retrieved from the cache\r\n */\r\n static createUnableToParseTokenRequestCacheError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.unableToParseTokenRequestCacheError.code,\r\n BrowserAuthErrorMessage.unableToParseTokenRequestCacheError.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the token request could not be retrieved from the cache\r\n */\r\n static createNoTokenRequestCacheError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.noTokenRequestCacheError.code,\r\n BrowserAuthErrorMessage.noTokenRequestCacheError.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when handleCodeResponse is called before initiateAuthRequest (InteractionHandler)\r\n */\r\n static createAuthRequestNotSetError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.authRequestNotSet.code,\r\n BrowserAuthErrorMessage.authRequestNotSet.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the authority could not be retrieved from the cache\r\n */\r\n static createNoCachedAuthorityError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.noCachedAuthorityError.code,\r\n BrowserAuthErrorMessage.noCachedAuthorityError.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown if cache type is invalid.\r\n */\r\n static createInvalidCacheTypeError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.invalidCacheType.code, `${BrowserAuthErrorMessage.invalidCacheType.desc}`);\r\n }\r\n\r\n /**\r\n * Create an error thrown when login and token requests are made from a non-browser environment\r\n */\r\n static createNonBrowserEnvironmentError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.notInBrowserEnvironment.code, BrowserAuthErrorMessage.notInBrowserEnvironment.desc);\r\n }\r\n\r\n /**\r\n * Create an error thrown when indexDB database is not open\r\n */\r\n static createDatabaseNotOpenError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.databaseNotOpen.code, BrowserAuthErrorMessage.databaseNotOpen.desc);\r\n }\r\n\r\n /**\r\n * Create an error thrown when token fetch fails due to no internet\r\n */\r\n static createNoNetworkConnectivityError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.noNetworkConnectivity.code, BrowserAuthErrorMessage.noNetworkConnectivity.desc);\r\n }\r\n\r\n /**\r\n * Create an error thrown when token fetch fails due to reasons other than internet connectivity\r\n */\r\n static createPostRequestFailedError(errorDesc: string, endpoint: string): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.postRequestFailed.code, `${BrowserAuthErrorMessage.postRequestFailed.desc} | Network client threw: ${errorDesc} | Attempted to reach: ${endpoint.split(\"?\")[0]}`);\r\n }\r\n\r\n /**\r\n * Create an error thrown when get request fails due to reasons other than internet connectivity\r\n */\r\n static createGetRequestFailedError(errorDesc: string, endpoint: string): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.getRequestFailed.code, `${BrowserAuthErrorMessage.getRequestFailed.desc} | Network client threw: ${errorDesc} | Attempted to reach: ${endpoint.split(\"?\")[0]}`);\r\n }\r\n\r\n /**\r\n * Create an error thrown when network client fails to parse network response\r\n */\r\n static createFailedToParseNetworkResponseError(endpoint: string): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.failedToParseNetworkResponse.code, `${BrowserAuthErrorMessage.failedToParseNetworkResponse.desc} | Attempted to reach: ${endpoint.split(\"?\")[0]}`);\r\n }\r\n\r\n /**\r\n * Create an error thrown when the necessary information is not available to sideload tokens\r\n */\r\n static createUnableToLoadTokenError(errorDetail: string): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.unableToLoadTokenError.code, `${BrowserAuthErrorMessage.unableToLoadTokenError.desc} | ${errorDetail}`);\r\n }\r\n\r\n /**\r\n * Create an error thrown when the queried cryptographic key is not found in IndexedDB\r\n */\r\n static createSigningKeyNotFoundInStorageError(keyId: string): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.signingKeyNotFoundInStorage.code, `${BrowserAuthErrorMessage.signingKeyNotFoundInStorage.desc} | No match found for KeyId: ${keyId}`);\r\n }\r\n\r\n /**\r\n * Create an error when an authorization code is required but not provided\r\n */\r\n static createAuthCodeRequiredError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.authCodeRequired.code, BrowserAuthErrorMessage.authCodeRequired.desc);\r\n }\r\n\r\n /**\r\n * Create an error when an authorization code or native account ID is required but not provided\r\n */\r\n static createAuthCodeOrNativeAccountIdRequiredError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.authCodeOrNativeAccountRequired.code, BrowserAuthErrorMessage.authCodeOrNativeAccountRequired.desc);\r\n }\r\n\r\n /**\r\n * Create an error when both authorization code and native account ID are provided\r\n */\r\n static createSpaCodeAndNativeAccountIdPresentError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.spaCodeAndNativeAccountPresent.code, BrowserAuthErrorMessage.spaCodeAndNativeAccountPresent.desc);\r\n }\r\n\r\n /**\r\n * Create an error when IndexedDB is unavailable\r\n */\r\n static createDatabaseUnavailableError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.databaseUnavailable.code, BrowserAuthErrorMessage.databaseUnavailable.desc);\r\n }\r\n\r\n /**\r\n * Create an error when native token acquisition is not possible\r\n */\r\n static createUnableToAcquireTokenFromNativePlatformError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.unableToAcquireTokenFromNativePlatform.code, BrowserAuthErrorMessage.unableToAcquireTokenFromNativePlatform.desc);\r\n }\r\n\r\n /**\r\n * Create an error thrown when Handshake with browser extension times out\r\n */\r\n static createNativeHandshakeTimeoutError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.nativeHandshakeTimeout.code, BrowserAuthErrorMessage.nativeHandshakeTimeout.desc);\r\n }\r\n\r\n /**\r\n * Create an error thrown when browser extension is not installed\r\n */\r\n static createNativeExtensionNotInstalledError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.nativeExtensionNotInstalled.code, BrowserAuthErrorMessage.nativeExtensionNotInstalled.desc);\r\n }\r\n\r\n /**\r\n * Create an error when native connection has not been established\r\n * @returns\r\n */\r\n static createNativeConnectionNotEstablishedError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.nativeConnectionNotEstablished.code, BrowserAuthErrorMessage.nativeConnectionNotEstablished.desc);\r\n }\r\n\r\n /**\r\n * Create an error thrown when the initialize function hasn't been called\r\n */\r\n static createNativeBrokerCalledBeforeInitialize(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.nativeBrokerCalledBeforeInitialize.code, BrowserAuthErrorMessage.nativeBrokerCalledBeforeInitialize.desc);\r\n }\r\n\r\n /**\r\n * Create an error thrown when requesting a token directly from the native platform with an unsupported prompt parameter e.g. select_account, login or create\r\n * These requests must go through eSTS to ensure eSTS is aware of the new account\r\n */\r\n static createNativePromptParameterNotSupportedError(): BrowserAuthError {\r\n return new BrowserAuthError(BrowserAuthErrorMessage.nativePromptNotSupported.code, BrowserAuthErrorMessage.nativePromptNotSupported.desc);\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { PkceCodes } from \"@azure/msal-common\";\r\nimport { BrowserAuthError } from \"../error/BrowserAuthError\";\r\nimport { Base64Encode } from \"../encode/Base64Encode\";\r\nimport { BrowserCrypto } from \"./BrowserCrypto\";\r\n\r\n// Constant byte array length\r\nconst RANDOM_BYTE_ARR_LENGTH = 32;\r\n\r\n/**\r\n * Class which exposes APIs to generate PKCE codes and code verifiers.\r\n */\r\nexport class PkceGenerator {\r\n\r\n private base64Encode: Base64Encode;\r\n private cryptoObj: BrowserCrypto;\r\n\r\n constructor(cryptoObj: BrowserCrypto) {\r\n this.base64Encode = new Base64Encode();\r\n this.cryptoObj = cryptoObj;\r\n }\r\n\r\n /**\r\n * Generates PKCE Codes. See the RFC for more information: https://tools.ietf.org/html/rfc7636\r\n */\r\n async generateCodes(): Promise {\r\n const codeVerifier = this.generateCodeVerifier();\r\n const codeChallenge = await this.generateCodeChallengeFromVerifier(codeVerifier);\r\n return {\r\n verifier: codeVerifier,\r\n challenge: codeChallenge\r\n };\r\n }\r\n\r\n /**\r\n * Generates a random 32 byte buffer and returns the base64\r\n * encoded string to be used as a PKCE Code Verifier\r\n */\r\n private generateCodeVerifier(): string {\r\n try {\r\n // Generate random values as utf-8\r\n const buffer: Uint8Array = new Uint8Array(RANDOM_BYTE_ARR_LENGTH);\r\n this.cryptoObj.getRandomValues(buffer);\r\n // encode verifier as base64\r\n const pkceCodeVerifierB64: string = this.base64Encode.urlEncodeArr(buffer);\r\n return pkceCodeVerifierB64;\r\n } catch (e) {\r\n throw BrowserAuthError.createPkceNotGeneratedError(e);\r\n }\r\n }\r\n\r\n /**\r\n * Creates a base64 encoded PKCE Code Challenge string from the\r\n * hash created from the PKCE Code Verifier supplied\r\n */\r\n private async generateCodeChallengeFromVerifier(pkceCodeVerifier: string): Promise {\r\n try {\r\n // hashed verifier\r\n const pkceHashedCodeVerifier = await this.cryptoObj.sha256Digest(pkceCodeVerifier);\r\n // encode hash as base64\r\n return this.base64Encode.urlEncodeArr(new Uint8Array(pkceHashedCodeVerifier));\r\n } catch (e) {\r\n throw BrowserAuthError.createPkceNotGeneratedError(e);\r\n }\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { KEY_FORMAT_JWK } from \"../utils/BrowserConstants\";\r\nimport { ISubtleCrypto } from \"./ISubtleCrypto\";\r\n\r\nexport class ModernBrowserCrypto implements ISubtleCrypto {\r\n getRandomValues(dataBuffer: Uint8Array): Uint8Array {\r\n return window.crypto.getRandomValues(dataBuffer);\r\n }\r\n\r\n async generateKey(algorithm: RsaHashedKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise {\r\n return window.crypto.subtle.generateKey(algorithm, extractable, keyUsages) as Promise;\r\n }\r\n\r\n async exportKey(key: CryptoKey): Promise {\r\n return window.crypto.subtle.exportKey(KEY_FORMAT_JWK, key) as Promise;\r\n }\r\n\r\n async importKey(keyData: JsonWebKey, algorithm: RsaHashedImportParams, extractable: boolean, keyUsages: KeyUsage[]): Promise {\r\n return window.crypto.subtle.importKey(KEY_FORMAT_JWK, keyData, algorithm, extractable, keyUsages) as Promise;\r\n }\r\n\r\n async sign(algorithm: AlgorithmIdentifier, key: CryptoKey, data: ArrayBuffer): Promise {\r\n return window.crypto.subtle.sign(algorithm, key, data) as Promise;\r\n }\r\n\r\n async digest(algorithm: AlgorithmIdentifier, data: Uint8Array): Promise {\r\n return window.crypto.subtle.digest(algorithm, data) as Promise;\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { KEY_FORMAT_JWK } from \"../utils/BrowserConstants\";\r\nimport { ISubtleCrypto } from \"./ISubtleCrypto\";\r\n\r\ndeclare global {\r\n interface Window {\r\n msrCrypto: Crypto & {\r\n initPrng: (entropy: Uint8Array | number[]) => void\r\n }\r\n }\r\n}\r\n\r\nexport class MsrBrowserCrypto implements ISubtleCrypto {\r\n initPrng(entropy : Uint8Array): void {\r\n // Turn into array, as initPrng seems to not always like Uint8Array (even though it should support both)\r\n return window.msrCrypto.initPrng([...entropy]);\r\n }\r\n\r\n getRandomValues(dataBuffer: Uint8Array): Uint8Array {\r\n return window.msrCrypto.getRandomValues(dataBuffer);\r\n }\r\n\r\n async generateKey(algorithm: RsaHashedKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise {\r\n return window.msrCrypto.subtle.generateKey(algorithm, extractable, keyUsages) as Promise;\r\n }\r\n\r\n async exportKey(key: CryptoKey): Promise {\r\n return window.msrCrypto.subtle.exportKey(KEY_FORMAT_JWK, key) as Promise as Promise;\r\n }\r\n\r\n async importKey(keyData: JsonWebKey, algorithm: RsaHashedImportParams, extractable: boolean, keyUsages: KeyUsage[]): Promise {\r\n return window.msrCrypto.subtle.importKey(KEY_FORMAT_JWK, keyData, algorithm, extractable, keyUsages) as Promise;\r\n }\r\n\r\n async sign(algorithm: AlgorithmIdentifier, key: CryptoKey, data: ArrayBuffer): Promise {\r\n return window.msrCrypto.subtle.sign(algorithm, key, data) as Promise;\r\n }\r\n\r\n async digest(algorithm: AlgorithmIdentifier, data: Uint8Array): Promise {\r\n return window.msrCrypto.subtle.digest(algorithm, data) as Promise; \r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { Constants } from \"@azure/msal-common\";\r\nimport { KEY_FORMAT_JWK } from \"../utils/BrowserConstants\";\r\nimport { BrowserStringUtils } from \"../utils/BrowserStringUtils\";\r\nimport { ISubtleCrypto } from \"./ISubtleCrypto\";\r\n\r\nexport class MsBrowserCrypto implements ISubtleCrypto {\r\n getRandomValues(dataBuffer: Uint8Array): Uint8Array {\r\n return window[\"msCrypto\"].getRandomValues(dataBuffer);\r\n }\r\n\r\n async generateKey(algorithm: RsaHashedKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise {\r\n return new Promise((resolve: Function, reject: Function) => {\r\n const msGenerateKey = window[\"msCrypto\"].subtle.generateKey(algorithm, extractable, keyUsages);\r\n msGenerateKey.addEventListener(\"complete\", (e: { target: { result: CryptoKeyPair | PromiseLike; }; }) => {\r\n resolve(e.target.result);\r\n });\r\n\r\n msGenerateKey.addEventListener(\"error\", (error: string) => {\r\n reject(error);\r\n });\r\n });\r\n }\r\n\r\n async exportKey(key: CryptoKey): Promise {\r\n return new Promise((resolve: Function, reject: Function) => {\r\n const msExportKey = window[\"msCrypto\"].subtle.exportKey(KEY_FORMAT_JWK, key);\r\n msExportKey.addEventListener(\"complete\", (e: { target: { result: ArrayBuffer; }; }) => {\r\n const resultBuffer: ArrayBuffer = e.target.result;\r\n\r\n const resultString = BrowserStringUtils.utf8ArrToString(new Uint8Array(resultBuffer))\r\n .replace(/\\r/g, Constants.EMPTY_STRING)\r\n .replace(/\\n/g, Constants.EMPTY_STRING)\r\n .replace(/\\t/g, Constants.EMPTY_STRING)\r\n .split(\" \").join(Constants.EMPTY_STRING)\r\n .replace(\"\\u0000\", Constants.EMPTY_STRING);\r\n\r\n try {\r\n resolve(JSON.parse(resultString));\r\n } catch (e) {\r\n reject(e);\r\n }\r\n });\r\n\r\n msExportKey.addEventListener(\"error\", (error: string) => {\r\n reject(error);\r\n });\r\n });\r\n }\r\n\r\n async importKey(keyData: JsonWebKey, algorithm: RsaHashedImportParams, extractable: boolean, keyUsages: KeyUsage[]): Promise {\r\n const keyString = BrowserStringUtils.getSortedObjectString(keyData);\r\n const keyBuffer = BrowserStringUtils.stringToArrayBuffer(keyString);\r\n\r\n return new Promise((resolve: Function, reject: Function) => {\r\n const msImportKey = window[\"msCrypto\"].subtle.importKey(KEY_FORMAT_JWK, keyBuffer, algorithm, extractable, keyUsages);\r\n msImportKey.addEventListener(\"complete\", (e: { target: { result: CryptoKey | PromiseLike; }; }) => {\r\n resolve(e.target.result);\r\n });\r\n\r\n msImportKey.addEventListener(\"error\", (error: string) => {\r\n reject(error);\r\n });\r\n });\r\n }\r\n\r\n async sign(algorithm: AlgorithmIdentifier, key: CryptoKey, data: ArrayBuffer): Promise {\r\n return new Promise((resolve: Function, reject: Function) => {\r\n const msSign = window[\"msCrypto\"].subtle.sign(algorithm, key, data);\r\n msSign.addEventListener(\"complete\", (e: { target: { result: ArrayBuffer | PromiseLike; }; }) => {\r\n resolve(e.target.result);\r\n });\r\n\r\n msSign.addEventListener(\"error\", (error: string) => {\r\n reject(error);\r\n });\r\n });\r\n }\r\n \r\n async digest(algorithm: AlgorithmIdentifier, data: Uint8Array): Promise {\r\n return new Promise((resolve, reject) => {\r\n const digestOperation = window[\"msCrypto\"].subtle.digest(algorithm, data.buffer);\r\n digestOperation.addEventListener(\"complete\", (e: { target: { result: ArrayBuffer | PromiseLike; }; }) => {\r\n resolve(e.target.result);\r\n });\r\n digestOperation.addEventListener(\"error\", (error: string) => {\r\n reject(error);\r\n });\r\n });\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { BrowserStringUtils } from \"../utils/BrowserStringUtils\";\r\nimport { BrowserAuthError } from \"../error/BrowserAuthError\";\r\nimport { ISubtleCrypto } from \"./ISubtleCrypto\";\r\nimport { ModernBrowserCrypto } from \"./ModernBrowserCrypto\";\r\nimport { MsrBrowserCrypto } from \"./MsrBrowserCrypto\";\r\nimport { MsBrowserCrypto } from \"./MsBrowserCrypto\";\r\nimport { Logger } from \"@azure/msal-common\";\r\nimport { BrowserConfigurationAuthError } from \"../error/BrowserConfigurationAuthError\";\r\nimport { CryptoOptions } from \"../config/Configuration\";\r\n/**\r\n * See here for more info on RsaHashedKeyGenParams: https://developer.mozilla.org/en-US/docs/Web/API/RsaHashedKeyGenParams\r\n */\r\n// RSA KeyGen Algorithm\r\nconst PKCS1_V15_KEYGEN_ALG = \"RSASSA-PKCS1-v1_5\";\r\n// SHA-256 hashing algorithm\r\nconst S256_HASH_ALG = \"SHA-256\";\r\n// MOD length for PoP tokens\r\nconst MODULUS_LENGTH = 2048;\r\n// Public Exponent\r\nconst PUBLIC_EXPONENT: Uint8Array = new Uint8Array([0x01, 0x00, 0x01]);\r\n\r\n/**\r\n * This class implements functions used by the browser library to perform cryptography operations such as\r\n * hashing and encoding. It also has helper functions to validate the availability of specific APIs.\r\n */\r\nexport class BrowserCrypto {\r\n\r\n private keygenAlgorithmOptions: RsaHashedKeyGenParams;\r\n private subtleCrypto: ISubtleCrypto;\r\n private logger: Logger;\r\n private cryptoOptions?: CryptoOptions;\r\n\r\n constructor(logger: Logger, cryptoOptions?: CryptoOptions) {\r\n this.logger = logger;\r\n this.cryptoOptions = cryptoOptions;\r\n\r\n if (this.hasBrowserCrypto()) {\r\n // Use standard modern web crypto if available\r\n this.logger.verbose(\"BrowserCrypto: modern crypto interface available\");\r\n this.subtleCrypto = new ModernBrowserCrypto();\r\n } else if (this.hasIECrypto()) {\r\n // For IE11, use msCrypto interface\r\n this.logger.verbose(\"BrowserCrypto: MS crypto interface available\");\r\n this.subtleCrypto = new MsBrowserCrypto();\r\n } else if (this.hasMsrCrypto() && this.cryptoOptions?.useMsrCrypto) {\r\n // For other browsers, use MSR Crypto if found\r\n this.logger.verbose(\"BrowserCrypto: MSR crypto interface available\");\r\n this.subtleCrypto = new MsrBrowserCrypto();\r\n } else {\r\n if (this.hasMsrCrypto()) {\r\n this.logger.info(\"BrowserCrypto: MSR Crypto interface available but system.cryptoOptions.useMsrCrypto not enabled\");\r\n }\r\n this.logger.error(\"BrowserCrypto: No crypto interfaces available.\");\r\n throw BrowserAuthError.createCryptoNotAvailableError(\"Browser crypto, msCrypto, or msrCrypto interfaces not available.\");\r\n }\r\n\r\n // Mainly needed for MSR Crypto: https://github.com/microsoft/MSR-JavaScript-Crypto#random-number-generator-prng\r\n if (this.subtleCrypto.initPrng) {\r\n this.logger.verbose(\"BrowserCrypto: Interface requires entropy\");\r\n\r\n if (!this.cryptoOptions?.entropy) {\r\n this.logger.error(\"BrowserCrypto: Interface requires entropy but none provided.\");\r\n throw BrowserConfigurationAuthError.createEntropyNotProvided();\r\n }\r\n\r\n this.logger.verbose(\"BrowserCrypto: Entropy provided\");\r\n this.subtleCrypto.initPrng(this.cryptoOptions.entropy);\r\n }\r\n\r\n this.keygenAlgorithmOptions = {\r\n name: PKCS1_V15_KEYGEN_ALG,\r\n hash: S256_HASH_ALG,\r\n modulusLength: MODULUS_LENGTH,\r\n publicExponent: PUBLIC_EXPONENT\r\n };\r\n }\r\n\r\n /**\r\n * Check whether IE crypto or other browser cryptography is available.\r\n */\r\n private hasIECrypto(): boolean {\r\n return \"msCrypto\" in window;\r\n }\r\n\r\n /**\r\n * Check whether browser crypto is available.\r\n */\r\n private hasBrowserCrypto(): boolean {\r\n return \"crypto\" in window;\r\n }\r\n\r\n /**\r\n * Check whether MSR crypto polyfill is available\r\n */\r\n private hasMsrCrypto(): boolean {\r\n return \"msrCrypto\" in window;\r\n }\r\n\r\n /**\r\n * Returns a sha-256 hash of the given dataString as an ArrayBuffer.\r\n * @param dataString \r\n */\r\n async sha256Digest(dataString: string): Promise {\r\n const data = BrowserStringUtils.stringToUtf8Arr(dataString);\r\n // MSR Crypto wants object with name property, instead of string\r\n return this.subtleCrypto.digest({ name: S256_HASH_ALG }, data);\r\n }\r\n\r\n /**\r\n * Populates buffer with cryptographically random values.\r\n * @param dataBuffer \r\n */\r\n getRandomValues(dataBuffer: Uint8Array): Uint8Array {\r\n return this.subtleCrypto.getRandomValues(dataBuffer);\r\n }\r\n\r\n /**\r\n * Generates a keypair based on current keygen algorithm config.\r\n * @param extractable \r\n * @param usages \r\n */\r\n async generateKeyPair(extractable: boolean, usages: Array): Promise {\r\n return this.subtleCrypto.generateKey(this.keygenAlgorithmOptions, extractable, usages);\r\n }\r\n\r\n /**\r\n * Export key as Json Web Key (JWK)\r\n * @param key \r\n * @param format \r\n */\r\n async exportJwk(key: CryptoKey): Promise {\r\n return this.subtleCrypto.exportKey(key);\r\n }\r\n\r\n /**\r\n * Imports key as Json Web Key (JWK), can set extractable and usages.\r\n * @param key \r\n * @param format \r\n * @param extractable \r\n * @param usages \r\n */\r\n async importJwk(key: JsonWebKey, extractable: boolean, usages: Array): Promise {\r\n return this.subtleCrypto.importKey(key, this.keygenAlgorithmOptions, extractable, usages);\r\n }\r\n\r\n /**\r\n * Signs given data with given key\r\n * @param key \r\n * @param data \r\n */\r\n async sign(key: CryptoKey, data: ArrayBuffer): Promise {\r\n return this.subtleCrypto.sign(this.keygenAlgorithmOptions, key, data);\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { BrowserAuthError } from \"../error/BrowserAuthError\";\r\nimport { DB_NAME, DB_TABLE_NAME, DB_VERSION } from \"../utils/BrowserConstants\";\r\nimport { IAsyncStorage } from \"./IAsyncMemoryStorage\";\r\n\r\ninterface IDBOpenDBRequestEvent extends Event {\r\n target: IDBOpenDBRequest & EventTarget;\r\n}\r\n\r\ninterface IDBOpenOnUpgradeNeededEvent extends IDBVersionChangeEvent {\r\n target: IDBOpenDBRequest & EventTarget;\r\n}\r\n\r\ninterface IDBRequestEvent extends Event {\r\n target: IDBRequest & EventTarget;\r\n}\r\n\r\n/**\r\n * Storage wrapper for IndexedDB storage in browsers: https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API\r\n */\r\nexport class DatabaseStorage implements IAsyncStorage {\r\n private db: IDBDatabase|undefined;\r\n private dbName: string;\r\n private tableName: string;\r\n private version: number;\r\n private dbOpen: boolean;\r\n\r\n constructor() {\r\n this.dbName = DB_NAME;\r\n this.version = DB_VERSION;\r\n this.tableName = DB_TABLE_NAME;\r\n this.dbOpen = false;\r\n }\r\n\r\n /**\r\n * Opens IndexedDB instance.\r\n */\r\n async open(): Promise {\r\n return new Promise((resolve, reject) => {\r\n const openDB = window.indexedDB.open(this.dbName, this.version);\r\n openDB.addEventListener(\"upgradeneeded\", (e: IDBVersionChangeEvent) => {\r\n const event = e as IDBOpenOnUpgradeNeededEvent;\r\n event.target.result.createObjectStore(this.tableName);\r\n });\r\n openDB.addEventListener(\"success\", (e: Event) => {\r\n const event = e as IDBOpenDBRequestEvent;\r\n this.db = event.target.result;\r\n this.dbOpen = true;\r\n resolve();\r\n });\r\n openDB.addEventListener(\"error\", () => reject(BrowserAuthError.createDatabaseUnavailableError()));\r\n });\r\n }\r\n\r\n /**\r\n * Closes the connection to IndexedDB database when all pending transactions\r\n * complete.\r\n */\r\n closeConnection(): void {\r\n const db = this.db;\r\n if (db && this.dbOpen) {\r\n db.close();\r\n this.dbOpen = false;\r\n }\r\n }\r\n\r\n /**\r\n * Opens database if it's not already open\r\n */\r\n private async validateDbIsOpen(): Promise {\r\n if (!this.dbOpen) {\r\n return await this.open();\r\n }\r\n }\r\n\r\n /**\r\n * Retrieves item from IndexedDB instance.\r\n * @param key \r\n */\r\n async getItem(key: string): Promise {\r\n await this.validateDbIsOpen();\r\n return new Promise((resolve, reject) => {\r\n // TODO: Add timeouts?\r\n if (!this.db) {\r\n return reject(BrowserAuthError.createDatabaseNotOpenError());\r\n }\r\n const transaction = this.db.transaction([this.tableName], \"readonly\");\r\n const objectStore = transaction.objectStore(this.tableName);\r\n const dbGet = objectStore.get(key);\r\n \r\n dbGet.addEventListener(\"success\", (e: Event) => {\r\n const event = e as IDBRequestEvent;\r\n this.closeConnection();\r\n resolve(event.target.result);\r\n });\r\n\r\n dbGet.addEventListener(\"error\", (e: Event) => {\r\n this.closeConnection();\r\n reject(e);\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Adds item to IndexedDB under given key\r\n * @param key \r\n * @param payload \r\n */\r\n async setItem(key: string, payload: T): Promise {\r\n await this.validateDbIsOpen();\r\n return new Promise((resolve: Function, reject: Function) => {\r\n // TODO: Add timeouts?\r\n if (!this.db) {\r\n return reject(BrowserAuthError.createDatabaseNotOpenError());\r\n }\r\n const transaction = this.db.transaction([this.tableName], \"readwrite\");\r\n\r\n const objectStore = transaction.objectStore(this.tableName);\r\n\r\n const dbPut = objectStore.put(payload, key);\r\n\r\n dbPut.addEventListener(\"success\", () => {\r\n this.closeConnection();\r\n resolve();\r\n });\r\n\r\n dbPut.addEventListener(\"error\", (e) => {\r\n this.closeConnection();\r\n reject(e);\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Removes item from IndexedDB under given key\r\n * @param key\r\n */\r\n async removeItem(key: string): Promise {\r\n await this.validateDbIsOpen();\r\n return new Promise((resolve: Function, reject: Function) => {\r\n if (!this.db) {\r\n return reject(BrowserAuthError.createDatabaseNotOpenError());\r\n }\r\n\r\n const transaction = this.db.transaction([this.tableName], \"readwrite\");\r\n const objectStore = transaction.objectStore(this.tableName);\r\n const dbDelete = objectStore.delete(key);\r\n\r\n dbDelete.addEventListener(\"success\", () => {\r\n this.closeConnection();\r\n resolve();\r\n });\r\n\r\n dbDelete.addEventListener(\"error\", (e) => {\r\n this.closeConnection();\r\n reject(e);\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Get all the keys from the storage object as an iterable array of strings.\r\n */\r\n async getKeys(): Promise {\r\n await this.validateDbIsOpen();\r\n return new Promise((resolve: Function, reject: Function) => {\r\n if (!this.db) {\r\n return reject(BrowserAuthError.createDatabaseNotOpenError());\r\n }\r\n\r\n const transaction = this.db.transaction([this.tableName], \"readonly\");\r\n const objectStore = transaction.objectStore(this.tableName);\r\n const dbGetKeys = objectStore.getAllKeys();\r\n\r\n dbGetKeys.addEventListener(\"success\", (e: Event) => {\r\n const event = e as IDBRequestEvent;\r\n this.closeConnection();\r\n resolve(event.target.result);\r\n });\r\n\r\n dbGetKeys.addEventListener(\"error\", (e: Event) => {\r\n this.closeConnection();\r\n reject(e);\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * \r\n * Checks whether there is an object under the search key in the object store\r\n */\r\n async containsKey(key: string): Promise {\r\n await this.validateDbIsOpen();\r\n\r\n return new Promise((resolve: Function, reject: Function) => {\r\n if (!this.db) {\r\n return reject(BrowserAuthError.createDatabaseNotOpenError());\r\n }\r\n\r\n const transaction = this.db.transaction([this.tableName], \"readonly\");\r\n const objectStore = transaction.objectStore(this.tableName);\r\n const dbContainsKey = objectStore.count(key);\r\n\r\n dbContainsKey.addEventListener(\"success\", (e: Event) => {\r\n const event = e as IDBRequestEvent;\r\n this.closeConnection();\r\n resolve(event.target.result === 1);\r\n });\r\n\r\n dbContainsKey.addEventListener(\"error\", (e: Event) => {\r\n this.closeConnection();\r\n reject(e);\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Deletes the MSAL database. The database is deleted rather than cleared to make it possible\r\n * for client applications to downgrade to a previous MSAL version without worrying about forward compatibility issues\r\n * with IndexedDB database versions.\r\n */\r\n async deleteDatabase(): Promise {\r\n // Check if database being deleted exists\r\n\r\n if (this.db && this.dbOpen) {\r\n this.closeConnection();\r\n }\r\n\r\n return new Promise((resolve: Function, reject: Function) => {\r\n const deleteDbRequest = window.indexedDB.deleteDatabase(DB_NAME);\r\n deleteDbRequest.addEventListener(\"success\", () => resolve(true));\r\n deleteDbRequest.addEventListener(\"blocked\", () => resolve(true));\r\n deleteDbRequest.addEventListener(\"error\", () => reject(false));\r\n });\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { IWindowStorage } from \"./IWindowStorage\";\r\n\r\nexport class MemoryStorage implements IWindowStorage {\r\n\r\n private cache: Map;\r\n\r\n constructor() {\r\n this.cache = new Map();\r\n }\r\n\r\n getItem(key: string): T | null {\r\n return this.cache.get(key) || null;\r\n }\r\n\r\n setItem(key: string, value: T): void {\r\n this.cache.set(key, value);\r\n }\r\n\r\n removeItem(key: string): void {\r\n this.cache.delete(key);\r\n }\r\n\r\n getKeys(): string[] {\r\n const cacheKeys: string[] = [];\r\n this.cache.forEach((value: T, key: string) => {\r\n cacheKeys.push(key);\r\n });\r\n return cacheKeys;\r\n }\r\n\r\n containsKey(key: string): boolean {\r\n return this.cache.has(key);\r\n }\r\n\r\n clear() :void {\r\n this.cache.clear();\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { Logger } from \"@azure/msal-common\";\r\nimport { BrowserAuthError, BrowserAuthErrorMessage } from \"../error/BrowserAuthError\";\r\nimport { DatabaseStorage } from \"./DatabaseStorage\";\r\nimport { IAsyncStorage } from \"./IAsyncMemoryStorage\";\r\nimport { MemoryStorage } from \"./MemoryStorage\";\r\n\r\n/**\r\n * This class allows MSAL to store artifacts asynchronously using the DatabaseStorage IndexedDB wrapper,\r\n * backed up with the more volatile MemoryStorage object for cases in which IndexedDB may be unavailable.\r\n */\r\nexport class AsyncMemoryStorage implements IAsyncStorage {\r\n private inMemoryCache: MemoryStorage;\r\n private indexedDBCache: DatabaseStorage;\r\n private logger: Logger;\r\n private storeName: string;\r\n\r\n constructor(logger: Logger, storeName: string) {\r\n this.inMemoryCache = new MemoryStorage();\r\n this.indexedDBCache = new DatabaseStorage();\r\n this.logger = logger;\r\n this.storeName = storeName;\r\n }\r\n\r\n private handleDatabaseAccessError(error: unknown): void {\r\n if (error instanceof BrowserAuthError && error.errorCode === BrowserAuthErrorMessage.databaseUnavailable.code) {\r\n this.logger.error(\"Could not access persistent storage. This may be caused by browser privacy features which block persistent storage in third-party contexts.\");\r\n } else {\r\n throw error;\r\n }\r\n }\r\n /**\r\n * Get the item matching the given key. Tries in-memory cache first, then in the asynchronous\r\n * storage object if item isn't found in-memory.\r\n * @param key \r\n */\r\n async getItem(key: string): Promise {\r\n const item = this.inMemoryCache.getItem(key);\r\n if(!item) {\r\n try {\r\n this.logger.verbose(\"Queried item not found in in-memory cache, now querying persistent storage.\");\r\n return await this.indexedDBCache.getItem(key);\r\n } catch (e) {\r\n this.handleDatabaseAccessError(e);\r\n }\r\n }\r\n return item;\r\n }\r\n\r\n /**\r\n * Sets the item in the in-memory cache and then tries to set it in the asynchronous\r\n * storage object with the given key.\r\n * @param key \r\n * @param value \r\n */\r\n async setItem(key: string, value: T): Promise {\r\n this.inMemoryCache.setItem(key, value);\r\n try {\r\n await this.indexedDBCache.setItem(key, value);\r\n } catch (e) {\r\n this.handleDatabaseAccessError(e);\r\n }\r\n }\r\n\r\n /**\r\n * Removes the item matching the key from the in-memory cache, then tries to remove it from the asynchronous storage object.\r\n * @param key \r\n */\r\n async removeItem(key: string): Promise {\r\n this.inMemoryCache.removeItem(key);\r\n try {\r\n await this.indexedDBCache.removeItem(key);\r\n } catch (e) {\r\n this.handleDatabaseAccessError(e);\r\n }\r\n }\r\n\r\n /**\r\n * Get all the keys from the in-memory cache as an iterable array of strings. If no keys are found, query the keys in the \r\n * asynchronous storage object.\r\n */\r\n async getKeys(): Promise {\r\n const cacheKeys = this.inMemoryCache.getKeys();\r\n if (cacheKeys.length === 0) {\r\n try {\r\n this.logger.verbose(\"In-memory cache is empty, now querying persistent storage.\");\r\n return await this.indexedDBCache.getKeys();\r\n } catch (e) {\r\n this.handleDatabaseAccessError(e);\r\n }\r\n }\r\n return cacheKeys;\r\n }\r\n\r\n /**\r\n * Returns true or false if the given key is present in the cache.\r\n * @param key \r\n */\r\n async containsKey(key: string): Promise {\r\n const containsKey = this.inMemoryCache.containsKey(key);\r\n if(!containsKey) {\r\n try {\r\n this.logger.verbose(\"Key not found in in-memory cache, now querying persistent storage.\");\r\n return await this.indexedDBCache.containsKey(key);\r\n } catch (e) {\r\n this.handleDatabaseAccessError(e);\r\n }\r\n }\r\n return containsKey;\r\n }\r\n\r\n /**\r\n * Clears in-memory Map\r\n */\r\n clearInMemory(): void {\r\n // InMemory cache is a Map instance, clear is straightforward\r\n this.logger.verbose(`Deleting in-memory keystore ${this.storeName}`);\r\n this.inMemoryCache.clear();\r\n this.logger.verbose(`In-memory keystore ${this.storeName} deleted`);\r\n }\r\n\r\n /**\r\n * Tries to delete the IndexedDB database\r\n * @returns\r\n */\r\n async clearPersistent(): Promise {\r\n try {\r\n this.logger.verbose(\"Deleting persistent keystore\");\r\n const dbDeleted = await this.indexedDBCache.deleteDatabase();\r\n if (dbDeleted) {\r\n this.logger.verbose(\"Persistent keystore deleted\");\r\n }\r\n \r\n return dbDeleted;\r\n } catch (e) {\r\n this.handleDatabaseAccessError(e);\r\n return false;\r\n }\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nexport type CcsCredential = {\r\n credential: string,\r\n type: CcsCredentialType\r\n};\r\n\r\nexport enum CcsCredentialType {\r\n HOME_ACCOUNT_ID = \"home_account_id\",\r\n UPN = \"UPN\"\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { ICrypto, IPerformanceClient, JoseHeader, Logger, PerformanceEvents, PkceCodes, SignedHttpRequest, SignedHttpRequestParameters } from \"@azure/msal-common\";\r\nimport { GuidGenerator } from \"./GuidGenerator\";\r\nimport { Base64Encode } from \"../encode/Base64Encode\";\r\nimport { Base64Decode } from \"../encode/Base64Decode\";\r\nimport { PkceGenerator } from \"./PkceGenerator\";\r\nimport { BrowserCrypto } from \"./BrowserCrypto\";\r\nimport { BrowserStringUtils } from \"../utils/BrowserStringUtils\";\r\nimport { BrowserAuthError } from \"../error/BrowserAuthError\";\r\nimport { CryptoKeyStore } from \"../cache/CryptoKeyStore\";\r\nimport { CryptoOptions } from \"../config/Configuration\";\r\n\r\nexport type CachedKeyPair = {\r\n publicKey: CryptoKey,\r\n privateKey: CryptoKey,\r\n requestMethod?: string,\r\n requestUri?: string\r\n};\r\n\r\n/**\r\n * This class implements MSAL's crypto interface, which allows it to perform base64 encoding and decoding, generating cryptographically random GUIDs and \r\n * implementing Proof Key for Code Exchange specs for the OAuth Authorization Code Flow using PKCE (rfc here: https://tools.ietf.org/html/rfc7636).\r\n */\r\nexport class CryptoOps implements ICrypto {\r\n\r\n private browserCrypto: BrowserCrypto;\r\n private guidGenerator: GuidGenerator;\r\n private b64Encode: Base64Encode;\r\n private b64Decode: Base64Decode;\r\n private pkceGenerator: PkceGenerator;\r\n private logger: Logger;\r\n\r\n /**\r\n * CryptoOps can be used in contexts outside a PCA instance,\r\n * meaning there won't be a performance manager available.\r\n */\r\n private performanceClient: IPerformanceClient | undefined;\r\n\r\n private static POP_KEY_USAGES: Array = [\"sign\", \"verify\"];\r\n private static EXTRACTABLE: boolean = true;\r\n private cache: CryptoKeyStore;\r\n\r\n constructor(logger: Logger, performanceClient?: IPerformanceClient, cryptoConfig?: CryptoOptions) {\r\n this.logger = logger;\r\n // Browser crypto needs to be validated first before any other classes can be set.\r\n this.browserCrypto = new BrowserCrypto(this.logger, cryptoConfig);\r\n this.b64Encode = new Base64Encode();\r\n this.b64Decode = new Base64Decode();\r\n this.guidGenerator = new GuidGenerator(this.browserCrypto);\r\n this.pkceGenerator = new PkceGenerator(this.browserCrypto);\r\n this.cache = new CryptoKeyStore(this.logger);\r\n this.performanceClient = performanceClient;\r\n }\r\n\r\n /**\r\n * Creates a new random GUID - used to populate state and nonce.\r\n * @returns string (GUID)\r\n */\r\n createNewGuid(): string {\r\n return this.guidGenerator.generateGuid();\r\n }\r\n\r\n /**\r\n * Encodes input string to base64.\r\n * @param input \r\n */\r\n base64Encode(input: string): string {\r\n return this.b64Encode.encode(input);\r\n } \r\n \r\n /**\r\n * Decodes input string from base64.\r\n * @param input \r\n */\r\n base64Decode(input: string): string {\r\n return this.b64Decode.decode(input);\r\n }\r\n\r\n /**\r\n * Generates PKCE codes used in Authorization Code Flow.\r\n */\r\n async generatePkceCodes(): Promise {\r\n return this.pkceGenerator.generateCodes();\r\n }\r\n\r\n /**\r\n * Generates a keypair, stores it and returns a thumbprint\r\n * @param request\r\n */\r\n async getPublicKeyThumbprint(request: SignedHttpRequestParameters): Promise {\r\n const publicKeyThumbMeasurement = this.performanceClient?.startMeasurement(PerformanceEvents.CryptoOptsGetPublicKeyThumbprint, request.correlationId);\r\n\r\n // Generate Keypair\r\n const keyPair: CryptoKeyPair = await this.browserCrypto.generateKeyPair(CryptoOps.EXTRACTABLE, CryptoOps.POP_KEY_USAGES);\r\n\r\n // Generate Thumbprint for Public Key\r\n const publicKeyJwk: JsonWebKey = await this.browserCrypto.exportJwk(keyPair.publicKey);\r\n \r\n const pubKeyThumprintObj: JsonWebKey = {\r\n e: publicKeyJwk.e,\r\n kty: publicKeyJwk.kty,\r\n n: publicKeyJwk.n\r\n };\r\n \r\n const publicJwkString: string = BrowserStringUtils.getSortedObjectString(pubKeyThumprintObj);\r\n const publicJwkHash = await this.hashString(publicJwkString);\r\n\r\n // Generate Thumbprint for Private Key\r\n const privateKeyJwk: JsonWebKey = await this.browserCrypto.exportJwk(keyPair.privateKey);\r\n // Re-import private key to make it unextractable\r\n const unextractablePrivateKey: CryptoKey = await this.browserCrypto.importJwk(privateKeyJwk, false, [\"sign\"]);\r\n\r\n // Store Keypair data in keystore\r\n await this.cache.asymmetricKeys.setItem(\r\n publicJwkHash, \r\n {\r\n privateKey: unextractablePrivateKey,\r\n publicKey: keyPair.publicKey,\r\n requestMethod: request.resourceRequestMethod,\r\n requestUri: request.resourceRequestUri\r\n }\r\n );\r\n\r\n if (publicKeyThumbMeasurement) {\r\n publicKeyThumbMeasurement.endMeasurement({\r\n success: true\r\n });\r\n }\r\n\r\n return publicJwkHash;\r\n }\r\n\r\n /**\r\n * Removes cryptographic keypair from key store matching the keyId passed in\r\n * @param kid \r\n */\r\n async removeTokenBindingKey(kid: string): Promise {\r\n await this.cache.asymmetricKeys.removeItem(kid);\r\n const keyFound = await this.cache.asymmetricKeys.containsKey(kid);\r\n return !keyFound;\r\n }\r\n\r\n /**\r\n * Removes all cryptographic keys from IndexedDB storage\r\n */\r\n async clearKeystore(): Promise {\r\n return await this.cache.clear();\r\n }\r\n\r\n /**\r\n * Signs the given object as a jwt payload with private key retrieved by given kid.\r\n * @param payload \r\n * @param kid \r\n */\r\n async signJwt(payload: SignedHttpRequest, kid: string, correlationId?: string): Promise {\r\n const signJwtMeasurement = this.performanceClient?.startMeasurement(PerformanceEvents.CryptoOptsSignJwt, correlationId);\r\n const cachedKeyPair = await this.cache.asymmetricKeys.getItem(kid);\r\n \r\n if (!cachedKeyPair) {\r\n throw BrowserAuthError.createSigningKeyNotFoundInStorageError(kid);\r\n }\r\n\r\n // Get public key as JWK\r\n const publicKeyJwk = await this.browserCrypto.exportJwk(cachedKeyPair.publicKey);\r\n const publicKeyJwkString = BrowserStringUtils.getSortedObjectString(publicKeyJwk);\r\n\r\n // Base64URL encode public key thumbprint with keyId only: BASE64URL({ kid: \"FULL_PUBLIC_KEY_HASH\" })\r\n const encodedKeyIdThumbprint = this.b64Encode.urlEncode(JSON.stringify({ kid: kid }));\r\n \r\n // Generate header\r\n const shrHeader = JoseHeader.getShrHeaderString({ kid: encodedKeyIdThumbprint, alg: publicKeyJwk.alg });\r\n const encodedShrHeader = this.b64Encode.urlEncode(shrHeader);\r\n\r\n // Generate payload\r\n payload.cnf = {\r\n jwk: JSON.parse(publicKeyJwkString)\r\n };\r\n const encodedPayload = this.b64Encode.urlEncode(JSON.stringify(payload));\r\n\r\n // Form token string\r\n const tokenString = `${encodedShrHeader}.${encodedPayload}`;\r\n\r\n // Sign token\r\n const tokenBuffer = BrowserStringUtils.stringToArrayBuffer(tokenString);\r\n const signatureBuffer = await this.browserCrypto.sign(cachedKeyPair.privateKey, tokenBuffer);\r\n const encodedSignature = this.b64Encode.urlEncodeArr(new Uint8Array(signatureBuffer));\r\n\r\n const signedJwt = `${tokenString}.${encodedSignature}`;\r\n\r\n if (signJwtMeasurement) {\r\n signJwtMeasurement.endMeasurement({\r\n success: true\r\n });\r\n }\r\n\r\n return signedJwt;\r\n }\r\n\r\n /**\r\n * Returns the SHA-256 hash of an input string\r\n * @param plainText\r\n */\r\n async hashString(plainText: string): Promise {\r\n const hashBuffer: ArrayBuffer = await this.browserCrypto.sha256Digest(plainText);\r\n const hashBytes = new Uint8Array(hashBuffer);\r\n return this.b64Encode.urlEncodeArr(hashBytes);\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { ApplicationTelemetry } from \"../../config/ClientConfiguration\";\r\nimport { Logger } from \"../../logger/Logger\";\r\nimport {\r\n InProgressPerformanceEvent,\r\n IPerformanceClient,\r\n PerformanceCallbackFunction,\r\n QueueMeasurement\r\n} from \"./IPerformanceClient\";\r\nimport { IPerformanceMeasurement } from \"./IPerformanceMeasurement\";\r\nimport {\r\n Counters,\r\n IntFields,\r\n PerformanceEvent,\r\n PerformanceEvents,\r\n PerformanceEventStatus,\r\n StaticFields\r\n} from \"./PerformanceEvent\";\r\n\r\nexport interface PreQueueEvent {\r\n name: PerformanceEvents;\r\n time: number;\r\n}\r\n\r\nexport abstract class PerformanceClient implements IPerformanceClient {\r\n protected authority: string;\r\n protected libraryName: string;\r\n protected libraryVersion: string;\r\n protected applicationTelemetry: ApplicationTelemetry;\r\n protected clientId: string;\r\n protected logger: Logger;\r\n protected callbacks: Map;\r\n\r\n /**\r\n * Multiple events with the same correlation id.\r\n * @protected\r\n * @type {Map}\r\n */\r\n protected eventsByCorrelationId: Map;\r\n\r\n /**\r\n * Map of pre-queue times by correlation Id\r\n *\r\n * @protected\r\n * @type {Map}\r\n */\r\n protected preQueueTimeByCorrelationId: Map;\r\n\r\n /**\r\n * Map of queue measurements by correlation Id\r\n *\r\n * @protected\r\n * @type {Map>}\r\n */\r\n protected queueMeasurements: Map>;\r\n\r\n /**\r\n * Creates an instance of PerformanceClient,\r\n * an abstract class containing core performance telemetry logic.\r\n *\r\n * @constructor\r\n * @param {string} clientId Client ID of the application\r\n * @param {string} authority Authority used by the application\r\n * @param {Logger} logger Logger used by the application\r\n * @param {string} libraryName Name of the library\r\n * @param {string} libraryVersion Version of the library\r\n */\r\n constructor(clientId: string, authority: string, logger: Logger, libraryName: string, libraryVersion: string, applicationTelemetry: ApplicationTelemetry) {\r\n this.authority = authority;\r\n this.libraryName = libraryName;\r\n this.libraryVersion = libraryVersion;\r\n this.applicationTelemetry = applicationTelemetry;\r\n this.clientId = clientId;\r\n this.logger = logger;\r\n this.callbacks = new Map();\r\n this.eventsByCorrelationId = new Map();\r\n this.queueMeasurements = new Map();\r\n this.preQueueTimeByCorrelationId = new Map();\r\n }\r\n\r\n /**\r\n * Generates and returns a unique id, typically a guid.\r\n *\r\n * @abstract\r\n * @returns {string}\r\n */\r\n abstract generateId(): string;\r\n\r\n /**\r\n * Starts and returns an platform-specific implementation of IPerformanceMeasurement.\r\n * Note: this function can be changed to abstract at the next major version bump.\r\n *\r\n * @param {string} measureName\r\n * @param {string} correlationId\r\n * @returns {IPerformanceMeasurement}\r\n */\r\n /* eslint-disable-next-line @typescript-eslint/no-unused-vars */\r\n startPerformanceMeasurement(measureName: string, correlationId: string): IPerformanceMeasurement {\r\n return {} as IPerformanceMeasurement;\r\n }\r\n\r\n /**\r\n * Starts and returns an platform-specific implementation of IPerformanceMeasurement.\r\n * Note: this incorrectly-named function will be removed at the next major version bump.\r\n *\r\n * @param {string} measureName\r\n * @param {string} correlationId\r\n * @returns {IPerformanceMeasurement}\r\n */\r\n /* eslint-disable-next-line @typescript-eslint/no-unused-vars */\r\n startPerformanceMeasuremeant(measureName: string, correlationId: string): IPerformanceMeasurement {\r\n return {} as IPerformanceMeasurement;\r\n }\r\n\r\n /**\r\n * Sets pre-queue time by correlation Id\r\n *\r\n * @abstract\r\n * @param {PerformanceEvents} eventName\r\n * @param {string} correlationId\r\n * @returns\r\n */\r\n abstract setPreQueueTime(eventName: PerformanceEvents, correlationId?: string): void;\r\n\r\n /**\r\n * Get integral fields.\r\n * Override to change the set.\r\n */\r\n getIntFields(): ReadonlySet {\r\n return IntFields;\r\n }\r\n\r\n /**\r\n * Gets map of pre-queue times by correlation Id\r\n *\r\n * @param {PerformanceEvents} eventName\r\n * @param {string} correlationId\r\n * @returns {number}\r\n */\r\n getPreQueueTime(eventName: PerformanceEvents, correlationId: string): number | void {\r\n const preQueueEvent: PreQueueEvent | undefined = this.preQueueTimeByCorrelationId.get(correlationId);\r\n\r\n if (!preQueueEvent) {\r\n this.logger.trace(`PerformanceClient.getPreQueueTime: no pre-queue times found for correlationId: ${correlationId}, unable to add queue measurement`);\r\n return;\r\n } else if (preQueueEvent.name !== eventName) {\r\n this.logger.trace(`PerformanceClient.getPreQueueTime: no pre-queue time found for ${eventName}, unable to add queue measurement`);\r\n return;\r\n }\r\n\r\n return preQueueEvent.time;\r\n }\r\n\r\n /**\r\n * Calculates the difference between current time and time when function was queued.\r\n * Note: It is possible to have 0 as the queue time if the current time and the queued time was the same.\r\n *\r\n * @param {number} preQueueTime\r\n * @param {number} currentTime\r\n * @returns {number}\r\n */\r\n calculateQueuedTime(preQueueTime: number, currentTime: number): number {\r\n if (preQueueTime < 1) {\r\n this.logger.trace(`PerformanceClient: preQueueTime should be a positive integer and not ${preQueueTime}`);\r\n return 0;\r\n }\r\n\r\n if (currentTime < 1) {\r\n this.logger.trace(`PerformanceClient: currentTime should be a positive integer and not ${currentTime}`);\r\n return 0;\r\n }\r\n\r\n if (currentTime < preQueueTime) {\r\n this.logger.trace(\"PerformanceClient: currentTime is less than preQueueTime, check how time is being retrieved\");\r\n return 0;\r\n }\r\n\r\n return currentTime-preQueueTime;\r\n }\r\n\r\n /**\r\n * Adds queue measurement time to QueueMeasurements array for given correlation ID.\r\n *\r\n * @param {PerformanceEvents} eventName\r\n * @param {?string} correlationId\r\n * @param {?number} queueTime\r\n * @param {?boolean} manuallyCompleted - indicator for manually completed queue measurements\r\n * @returns\r\n */\r\n addQueueMeasurement(eventName: PerformanceEvents, correlationId?: string, queueTime?: number, manuallyCompleted?: boolean): void {\r\n if (!correlationId) {\r\n this.logger.trace(`PerformanceClient.addQueueMeasurement: correlationId not provided for ${eventName}, cannot add queue measurement`);\r\n return;\r\n }\r\n\r\n if (queueTime === 0) {\r\n // Possible for there to be no queue time after calculation\r\n this.logger.trace(`PerformanceClient.addQueueMeasurement: queue time provided for ${eventName} is ${queueTime}`);\r\n } else if (!queueTime) {\r\n this.logger.trace(`PerformanceClient.addQueueMeasurement: no queue time provided for ${eventName}`);\r\n return;\r\n }\r\n\r\n const queueMeasurement: QueueMeasurement = {eventName, queueTime, manuallyCompleted};\r\n\r\n // Adds to existing correlation Id if present in queueMeasurements\r\n const existingMeasurements = this.queueMeasurements.get(correlationId);\r\n if (existingMeasurements) {\r\n existingMeasurements.push(queueMeasurement);\r\n this.queueMeasurements.set(correlationId, existingMeasurements);\r\n } else {\r\n // Sets new correlation Id if not present in queueMeasurements\r\n this.logger.trace(`PerformanceClient.addQueueMeasurement: adding correlationId ${correlationId} to queue measurements`);\r\n const measurementArray = [queueMeasurement];\r\n this.queueMeasurements.set(correlationId, measurementArray);\r\n }\r\n // Delete processed pre-queue event.\r\n this.preQueueTimeByCorrelationId.delete(correlationId);\r\n }\r\n\r\n /**\r\n * Starts measuring performance for a given operation. Returns a function that should be used to end the measurement.\r\n *\r\n * @param {PerformanceEvents} measureName\r\n * @param {?string} [correlationId]\r\n * @returns {InProgressPerformanceEvent}\r\n */\r\n startMeasurement(measureName: PerformanceEvents, correlationId?: string): InProgressPerformanceEvent {\r\n // Generate a placeholder correlation if the request does not provide one\r\n const eventCorrelationId = correlationId || this.generateId();\r\n if (!correlationId) {\r\n this.logger.info(`PerformanceClient: No correlation id provided for ${measureName}, generating`, eventCorrelationId);\r\n }\r\n\r\n // Duplicate code to address spelling error will be removed at the next major version bump.\r\n this.logger.trace(`PerformanceClient: Performance measurement started for ${measureName}`, eventCorrelationId);\r\n const performanceMeasurement = this.startPerformanceMeasuremeant(measureName, eventCorrelationId);\r\n performanceMeasurement.startMeasurement();\r\n\r\n const inProgressEvent: PerformanceEvent = {\r\n eventId: this.generateId(),\r\n status: PerformanceEventStatus.InProgress,\r\n authority: this.authority,\r\n libraryName: this.libraryName,\r\n libraryVersion: this.libraryVersion,\r\n clientId: this.clientId,\r\n name: measureName,\r\n startTimeMs: Date.now(),\r\n correlationId: eventCorrelationId,\r\n appName: this.applicationTelemetry?.appName,\r\n appVersion: this.applicationTelemetry?.appVersion,\r\n };\r\n\r\n // Store in progress events so they can be discarded if not ended properly\r\n this.cacheEventByCorrelationId(inProgressEvent);\r\n\r\n // Return the event and functions the caller can use to properly end/flush the measurement\r\n return {\r\n endMeasurement: (event?: Partial): PerformanceEvent | null => {\r\n return this.endMeasurement({\r\n // Initial set of event properties\r\n ...inProgressEvent,\r\n // Properties set when event ends\r\n ...event\r\n },\r\n performanceMeasurement);\r\n },\r\n discardMeasurement: () => {\r\n return this.discardMeasurements(inProgressEvent.correlationId);\r\n },\r\n addStaticFields: (fields: StaticFields) => {\r\n return this.addStaticFields(fields, inProgressEvent.correlationId);\r\n },\r\n increment: (counters: Counters) => {\r\n return this.increment(counters, inProgressEvent.correlationId);\r\n },\r\n measurement: performanceMeasurement,\r\n event: inProgressEvent\r\n };\r\n\r\n }\r\n\r\n /**\r\n * Stops measuring the performance for an operation. Should only be called directly by PerformanceClient classes,\r\n * as consumers should instead use the function returned by startMeasurement.\r\n * Adds a new field named as \"[event name]DurationMs\" for sub-measurements, completes and emits an event\r\n * otherwise.\r\n *\r\n * @param {PerformanceEvent} event\r\n * @param {IPerformanceMeasurement} measurement\r\n * @returns {(PerformanceEvent | null)}\r\n */\r\n endMeasurement(event: PerformanceEvent, measurement?: IPerformanceMeasurement): PerformanceEvent | null {\r\n const rootEvent: PerformanceEvent | undefined = this.eventsByCorrelationId.get(event.correlationId);\r\n if (!rootEvent) {\r\n this.logger.trace(`PerformanceClient: Measurement not found for ${event.eventId}`, event.correlationId);\r\n return null;\r\n }\r\n\r\n const isRoot = event.eventId === rootEvent.eventId;\r\n let queueInfo = {\r\n totalQueueTime: 0,\r\n totalQueueCount: 0,\r\n manuallyCompletedCount: 0\r\n };\r\n if (isRoot) {\r\n queueInfo = this.getQueueInfo(event.correlationId);\r\n this.discardCache(rootEvent.correlationId);\r\n } else {\r\n rootEvent.incompleteSubMeasurements?.delete(event.eventId);\r\n }\r\n\r\n measurement?.endMeasurement();\r\n const durationMs = measurement?.flushMeasurement();\r\n // null indicates no measurement was taken (e.g. needed performance APIs not present)\r\n if (!durationMs) {\r\n this.logger.trace(\"PerformanceClient: Performance measurement not taken\", rootEvent.correlationId);\r\n return null;\r\n }\r\n\r\n this.logger.trace(`PerformanceClient: Performance measurement ended for ${event.name}: ${durationMs} ms`, event.correlationId);\r\n\r\n // Add sub-measurement attribute to root event.\r\n if (!isRoot) {\r\n rootEvent[event.name + \"DurationMs\"] = Math.floor(durationMs);\r\n return { ...rootEvent };\r\n }\r\n\r\n let finalEvent: PerformanceEvent = { ...rootEvent, ...event };\r\n let incompleteSubsCount: number = 0;\r\n // Incomplete sub-measurements are discarded. They are likely an instrumentation bug that should be fixed.\r\n finalEvent.incompleteSubMeasurements?.forEach(subMeasurement => {\r\n this.logger.trace(`PerformanceClient: Incomplete submeasurement ${subMeasurement.name} found for ${event.name}`, finalEvent.correlationId);\r\n incompleteSubsCount++;\r\n });\r\n finalEvent.incompleteSubMeasurements = undefined;\r\n\r\n finalEvent = {\r\n ...finalEvent,\r\n durationMs: Math.round(durationMs),\r\n queuedTimeMs: queueInfo.totalQueueTime,\r\n queuedCount: queueInfo.totalQueueCount,\r\n queuedManuallyCompletedCount: queueInfo.manuallyCompletedCount,\r\n status: PerformanceEventStatus.Completed,\r\n incompleteSubsCount\r\n };\r\n this.truncateIntegralFields(finalEvent, this.getIntFields());\r\n this.emitEvents([finalEvent], event.correlationId);\r\n\r\n return finalEvent;\r\n }\r\n\r\n /**\r\n * Saves extra information to be emitted when the measurements are flushed\r\n * @param fields\r\n * @param correlationId\r\n */\r\n addStaticFields(fields: StaticFields, correlationId: string) : void {\r\n this.logger.trace(\"PerformanceClient: Updating static fields\");\r\n const event = this.eventsByCorrelationId.get(correlationId);\r\n if (event) {\r\n this.eventsByCorrelationId.set(correlationId, {...event, ...fields});\r\n } else {\r\n this.logger.trace(\"PerformanceClient: Event not found for\", correlationId);\r\n }\r\n }\r\n\r\n /**\r\n * Increment counters to be emitted when the measurements are flushed\r\n * @param counters {Counters}\r\n * @param correlationId {string} correlation identifier\r\n */\r\n increment(counters: Counters, correlationId: string): void {\r\n this.logger.trace(\"PerformanceClient: Updating counters\");\r\n const event = this.eventsByCorrelationId.get(correlationId);\r\n if (event) {\r\n for (const counter in counters) {\r\n if (!event.hasOwnProperty(counter)) {\r\n event[counter] = 0;\r\n }\r\n event[counter] += counters[counter];\r\n }\r\n } else {\r\n this.logger.trace(\"PerformanceClient: Event not found for\", correlationId);\r\n }\r\n }\r\n\r\n /**\r\n * Upserts event into event cache.\r\n * First key is the correlation id, second key is the event id.\r\n * Allows for events to be grouped by correlation id,\r\n * and to easily allow for properties on them to be updated.\r\n *\r\n * @private\r\n * @param {PerformanceEvent} event\r\n */\r\n private cacheEventByCorrelationId(event: PerformanceEvent) {\r\n const rootEvent = this.eventsByCorrelationId.get(event.correlationId);\r\n if (rootEvent) {\r\n this.logger.trace(`PerformanceClient: Performance measurement for ${event.name} added/updated`, event.correlationId);\r\n rootEvent.incompleteSubMeasurements = rootEvent.incompleteSubMeasurements || new Map();\r\n rootEvent.incompleteSubMeasurements.set(event.eventId, {name: event.name, startTimeMs: event.startTimeMs });\r\n } else {\r\n this.logger.trace(`PerformanceClient: Performance measurement for ${event.name} started`, event.correlationId);\r\n this.eventsByCorrelationId.set(event.correlationId, { ...event });\r\n }\r\n }\r\n\r\n private getQueueInfo(correlationId: string): { totalQueueTime: number, totalQueueCount: number, manuallyCompletedCount: number } {\r\n const queueMeasurementForCorrelationId = this.queueMeasurements.get(correlationId);\r\n if (!queueMeasurementForCorrelationId) {\r\n this.logger.trace(`PerformanceClient: no queue measurements found for for correlationId: ${correlationId}`);\r\n }\r\n\r\n let totalQueueTime = 0;\r\n let totalQueueCount = 0;\r\n let manuallyCompletedCount = 0;\r\n queueMeasurementForCorrelationId?.forEach((measurement) => {\r\n totalQueueTime += measurement.queueTime;\r\n totalQueueCount++;\r\n manuallyCompletedCount += measurement.manuallyCompleted ? 1 : 0;\r\n });\r\n\r\n return {\r\n totalQueueTime,\r\n totalQueueCount,\r\n manuallyCompletedCount\r\n };\r\n }\r\n\r\n /**\r\n * Removes measurements for a given correlation id.\r\n *\r\n * @param {string} correlationId\r\n */\r\n discardMeasurements(correlationId: string): void {\r\n this.logger.trace(\"PerformanceClient: Performance measurements discarded\", correlationId);\r\n this.eventsByCorrelationId.delete(correlationId);\r\n }\r\n\r\n /**\r\n * Removes cache for a given correlation id.\r\n *\r\n * @param {string} correlationId correlation identifier\r\n */\r\n private discardCache(correlationId: string): void {\r\n this.discardMeasurements(correlationId);\r\n\r\n this.logger.trace(\"PerformanceClient: QueueMeasurements discarded\", correlationId);\r\n this.queueMeasurements.delete(correlationId);\r\n\r\n this.logger.trace(\"PerformanceClient: Pre-queue times discarded\", correlationId);\r\n this.preQueueTimeByCorrelationId.delete(correlationId);\r\n }\r\n\r\n /**\r\n * Registers a callback function to receive performance events.\r\n *\r\n * @param {PerformanceCallbackFunction} callback\r\n * @returns {string}\r\n */\r\n addPerformanceCallback(callback: PerformanceCallbackFunction): string {\r\n const callbackId = this.generateId();\r\n this.callbacks.set(callbackId, callback);\r\n this.logger.verbose(`PerformanceClient: Performance callback registered with id: ${callbackId}`);\r\n\r\n return callbackId;\r\n }\r\n\r\n /**\r\n * Removes a callback registered with addPerformanceCallback.\r\n *\r\n * @param {string} callbackId\r\n * @returns {boolean}\r\n */\r\n removePerformanceCallback(callbackId: string): boolean {\r\n const result = this.callbacks.delete(callbackId);\r\n\r\n if (result) {\r\n this.logger.verbose(`PerformanceClient: Performance callback ${callbackId} removed.`);\r\n } else {\r\n this.logger.verbose(`PerformanceClient: Performance callback ${callbackId} not removed.`);\r\n }\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Emits events to all registered callbacks.\r\n *\r\n * @param {PerformanceEvent[]} events\r\n * @param {?string} [correlationId]\r\n */\r\n emitEvents(events: PerformanceEvent[], correlationId: string): void {\r\n this.logger.verbose(\"PerformanceClient: Emitting performance events\", correlationId);\r\n\r\n this.callbacks.forEach((callback: PerformanceCallbackFunction, callbackId: string) => {\r\n this.logger.trace(`PerformanceClient: Emitting event to callback ${callbackId}`, correlationId);\r\n callback.apply(null, [events]);\r\n });\r\n }\r\n\r\n /**\r\n * Enforce truncation of integral fields in performance event.\r\n * @param {PerformanceEvent} event performance event to update.\r\n * @param {Set} intFields integral fields.\r\n */\r\n private truncateIntegralFields(event: PerformanceEvent, intFields: ReadonlySet): void {\r\n intFields.forEach((key) => {\r\n if (key in event && typeof event[key] === \"number\") {\r\n event[key] = Math.floor(event[key]);\r\n }\r\n });\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { IPerformanceClient } from \"./IPerformanceClient\";\r\nimport { IPerformanceMeasurement } from \"./IPerformanceMeasurement\";\r\nimport { PerformanceClient } from \"./PerformanceClient\";\r\nimport { PerformanceEvents } from \"./PerformanceEvent\";\r\n\r\nexport class StubPerformanceMeasurement implements IPerformanceMeasurement {\r\n /* eslint-disable-next-line @typescript-eslint/no-empty-function */\r\n startMeasurement(): void { }\r\n /* eslint-disable-next-line @typescript-eslint/no-empty-function */\r\n endMeasurement(): void { }\r\n flushMeasurement(): number | null {\r\n return null;\r\n }\r\n \r\n}\r\n\r\nexport class StubPerformanceClient extends PerformanceClient implements IPerformanceClient {\r\n generateId(): string {\r\n return \"callback-id\";\r\n }\r\n \r\n startPerformanceMeasuremeant(): IPerformanceMeasurement {\r\n return new StubPerformanceMeasurement();\r\n }\r\n\r\n startPerformanceMeasurement(): IPerformanceMeasurement {\r\n return new StubPerformanceMeasurement();\r\n }\r\n\r\n /* eslint-disable-next-line @typescript-eslint/no-unused-vars */\r\n calculateQueuedTime(preQueueTime: number, currentTime: number): number {\r\n return 0;\r\n }\r\n\r\n /* eslint-disable-next-line @typescript-eslint/no-unused-vars */\r\n addQueueMeasurement(eventName: PerformanceEvents, correlationId: string, queueTime: number): void {\r\n return;\r\n }\r\n\r\n /* eslint-disable-next-line @typescript-eslint/no-unused-vars */\r\n setPreQueueTime(eventName: PerformanceEvents, correlationId?: string | undefined): void {\r\n return;\r\n }\r\n\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { AuthError } from \"../error/AuthError\";\r\nimport { BaseAuthRequest } from \"../request/BaseAuthRequest\";\r\nimport { SignedHttpRequest } from \"./SignedHttpRequest\";\r\n\r\n/**\r\n * The PkceCodes type describes the structure\r\n * of objects that contain PKCE code\r\n * challenge and verifier pairs\r\n */\r\nexport type PkceCodes = {\r\n verifier: string,\r\n challenge: string\r\n};\r\n\r\nexport type SignedHttpRequestParameters = Pick & {\r\n correlationId?: string\r\n};\r\n\r\n/**\r\n * Interface for crypto functions used by library\r\n */\r\nexport interface ICrypto {\r\n /**\r\n * Creates a guid randomly.\r\n */\r\n createNewGuid(): string;\r\n /**\r\n * base64 Encode string\r\n * @param input \r\n */\r\n base64Encode(input: string): string;\r\n /**\r\n * base64 decode string\r\n * @param input \r\n */\r\n base64Decode(input: string): string;\r\n /**\r\n * Generate PKCE codes for OAuth. See RFC here: https://tools.ietf.org/html/rfc7636\r\n */\r\n generatePkceCodes(): Promise;\r\n /**\r\n * Generates an JWK RSA S256 Thumbprint\r\n * @param request\r\n */\r\n getPublicKeyThumbprint(request: SignedHttpRequestParameters): Promise;\r\n /**\r\n * Removes cryptographic keypair from key store matching the keyId passed in\r\n * @param kid \r\n */\r\n removeTokenBindingKey(kid: string): Promise;\r\n /**\r\n * Removes all cryptographic keys from IndexedDB storage\r\n */\r\n clearKeystore(): Promise;\r\n /** \r\n * Returns a signed proof-of-possession token with a given acces token that contains a cnf claim with the required kid.\r\n * @param accessToken \r\n */\r\n signJwt(payload: SignedHttpRequest, kid: string, correlationId?: string): Promise;\r\n /**\r\n * Returns the SHA-256 hash of an input string\r\n * @param plainText\r\n */\r\n hashString(plainText: string): Promise;\r\n}\r\n\r\nexport const DEFAULT_CRYPTO_IMPLEMENTATION: ICrypto = {\r\n createNewGuid: (): string => {\r\n const notImplErr = \"Crypto interface - createNewGuid() has not been implemented\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n },\r\n base64Decode: (): string => {\r\n const notImplErr = \"Crypto interface - base64Decode() has not been implemented\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n },\r\n base64Encode: (): string => {\r\n const notImplErr = \"Crypto interface - base64Encode() has not been implemented\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n },\r\n async generatePkceCodes(): Promise {\r\n const notImplErr = \"Crypto interface - generatePkceCodes() has not been implemented\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n },\r\n async getPublicKeyThumbprint(): Promise {\r\n const notImplErr = \"Crypto interface - getPublicKeyThumbprint() has not been implemented\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n },\r\n async removeTokenBindingKey(): Promise {\r\n const notImplErr = \"Crypto interface - removeTokenBindingKey() has not been implemented\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n },\r\n async clearKeystore(): Promise {\r\n const notImplErr = \"Crypto interface - clearKeystore() has not been implemented\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n },\r\n async signJwt(): Promise {\r\n const notImplErr = \"Crypto interface - signJwt() has not been implemented\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n },\r\n async hashString(): Promise {\r\n const notImplErr = \"Crypto interface - hashString() has not been implemented\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n }\r\n};\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { Separators, CredentialType, CacheType, Constants, AuthenticationScheme } from \"../../utils/Constants\";\r\nimport { ClientAuthError } from \"../../error/ClientAuthError\";\r\n\r\n/**\r\n * Base type for credentials to be stored in the cache: eg: ACCESS_TOKEN, ID_TOKEN etc\r\n *\r\n * Key:Value Schema:\r\n *\r\n * Key: -------\r\n *\r\n * Value Schema:\r\n * {\r\n * homeAccountId: home account identifier for the auth scheme,\r\n * environment: entity that issued the token, represented as a full host\r\n * credentialType: Type of credential as a string, can be one of the following: RefreshToken, AccessToken, IdToken, Password, Cookie, Certificate, Other\r\n * clientId: client ID of the application\r\n * secret: Actual credential as a string\r\n * familyId: Family ID identifier, usually only used for refresh tokens\r\n * realm: Full tenant or organizational identifier that the account belongs to\r\n * target: Permissions that are included in the token, or for refresh tokens, the resource identifier.\r\n * tokenType: Matches the authentication scheme for which the token was issued (i.e. Bearer or pop)\r\n * requestedClaimsHash: Matches the SHA 256 hash of the claims object included in the token request\r\n * userAssertionHash: Matches the SHA 256 hash of the obo_assertion for the OBO flow\r\n * }\r\n */\r\nexport class CredentialEntity {\r\n homeAccountId: string;\r\n environment: string;\r\n credentialType: CredentialType;\r\n clientId: string;\r\n secret: string;\r\n familyId?: string;\r\n realm?: string;\r\n target?: string;\r\n userAssertionHash?: string;\r\n tokenType?: AuthenticationScheme;\r\n keyId?: string;\r\n requestedClaimsHash?: string;\r\n\r\n /**\r\n * Generate Account Id key component as per the schema: -\r\n */\r\n generateAccountId(): string {\r\n return CredentialEntity.generateAccountIdForCacheKey(this.homeAccountId, this.environment);\r\n }\r\n\r\n /**\r\n * Generate Credential Id key component as per the schema: --\r\n */\r\n generateCredentialId(): string {\r\n return CredentialEntity.generateCredentialIdForCacheKey(\r\n this.credentialType,\r\n this.clientId,\r\n this.realm,\r\n this.familyId\r\n );\r\n }\r\n\r\n /**\r\n * Generate target key component as per schema: \r\n */\r\n generateTarget(): string {\r\n return CredentialEntity.generateTargetForCacheKey(this.target);\r\n }\r\n\r\n /**\r\n * generates credential key\r\n */\r\n generateCredentialKey(): string {\r\n return CredentialEntity.generateCredentialCacheKey(\r\n this.homeAccountId,\r\n this.environment,\r\n this.credentialType,\r\n this.clientId,\r\n this.realm,\r\n this.target,\r\n this.familyId,\r\n this.tokenType,\r\n this.requestedClaimsHash,\r\n );\r\n }\r\n\r\n /**\r\n * returns the type of the cache (in this case credential)\r\n */\r\n generateType(): number {\r\n switch (this.credentialType) {\r\n case CredentialType.ID_TOKEN:\r\n return CacheType.ID_TOKEN;\r\n case CredentialType.ACCESS_TOKEN:\r\n case CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME:\r\n return CacheType.ACCESS_TOKEN;\r\n case CredentialType.REFRESH_TOKEN:\r\n return CacheType.REFRESH_TOKEN;\r\n default: {\r\n throw ClientAuthError.createUnexpectedCredentialTypeError();\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * generates credential key\r\n * -\\-----\r\n */\r\n static generateCredentialCacheKey(\r\n homeAccountId: string,\r\n environment: string,\r\n credentialType: CredentialType,\r\n clientId: string,\r\n realm?: string,\r\n target?: string,\r\n familyId?: string,\r\n tokenType?: AuthenticationScheme,\r\n requestedClaimsHash?: string\r\n ): string {\r\n const credentialKey = [\r\n this.generateAccountIdForCacheKey(homeAccountId, environment),\r\n this.generateCredentialIdForCacheKey(credentialType, clientId, realm, familyId),\r\n this.generateTargetForCacheKey(target),\r\n this.generateClaimsHashForCacheKey(requestedClaimsHash),\r\n this.generateSchemeForCacheKey(tokenType)\r\n ];\r\n\r\n return credentialKey.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();\r\n }\r\n\r\n /**\r\n * generates Account Id for keys\r\n * @param homeAccountId\r\n * @param environment\r\n */\r\n private static generateAccountIdForCacheKey(\r\n homeAccountId: string,\r\n environment: string\r\n ): string {\r\n const accountId: Array = [homeAccountId, environment];\r\n return accountId.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();\r\n }\r\n\r\n /**\r\n * Generates Credential Id for keys\r\n * @param credentialType\r\n * @param realm\r\n * @param clientId\r\n * @param familyId\r\n */\r\n private static generateCredentialIdForCacheKey(\r\n credentialType: CredentialType,\r\n clientId: string,\r\n realm?: string,\r\n familyId?: string\r\n ): string {\r\n const clientOrFamilyId =\r\n credentialType === CredentialType.REFRESH_TOKEN\r\n ? familyId || clientId\r\n : clientId;\r\n const credentialId: Array = [\r\n credentialType,\r\n clientOrFamilyId,\r\n realm || Constants.EMPTY_STRING,\r\n ];\r\n\r\n return credentialId.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();\r\n }\r\n\r\n /**\r\n * Generate target key component as per schema: \r\n */\r\n private static generateTargetForCacheKey(scopes?: string): string {\r\n return (scopes || Constants.EMPTY_STRING).toLowerCase();\r\n }\r\n\r\n /**\r\n * Generate requested claims key component as per schema: \r\n */\r\n private static generateClaimsHashForCacheKey(requestedClaimsHash?: string): string {\r\n return(requestedClaimsHash || Constants.EMPTY_STRING).toLowerCase();\r\n }\r\n\r\n /**\r\n * Generate scheme key componenet as per schema: \r\n */\r\n private static generateSchemeForCacheKey(tokenType?: string): string {\r\n /*\r\n * PoP Tokens and SSH certs include scheme in cache key\r\n * Cast to lowercase to handle \"bearer\" from ADFS\r\n */\r\n return (tokenType && tokenType.toLowerCase() !== AuthenticationScheme.BEARER.toLowerCase()) ? tokenType.toLowerCase() : Constants.EMPTY_STRING;\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { CredentialEntity } from \"./CredentialEntity\";\r\nimport { CredentialType } from \"../../utils/Constants\";\r\n\r\n/**\r\n * ID_TOKEN Cache\r\n *\r\n * Key:Value Schema:\r\n *\r\n * Key Example: uid.utid-login.microsoftonline.com-idtoken-clientId-contoso.com-\r\n *\r\n * Value Schema:\r\n * {\r\n * homeAccountId: home account identifier for the auth scheme,\r\n * environment: entity that issued the token, represented as a full host\r\n * credentialType: Type of credential as a string, can be one of the following: RefreshToken, AccessToken, IdToken, Password, Cookie, Certificate, Other\r\n * clientId: client ID of the application\r\n * secret: Actual credential as a string\r\n * realm: Full tenant or organizational identifier that the account belongs to\r\n * }\r\n */\r\nexport class IdTokenEntity extends CredentialEntity {\r\n realm: string;\r\n\r\n /**\r\n * Create IdTokenEntity\r\n * @param homeAccountId\r\n * @param authenticationResult\r\n * @param clientId\r\n * @param authority\r\n */\r\n static createIdTokenEntity(\r\n homeAccountId: string,\r\n environment: string,\r\n idToken: string,\r\n clientId: string,\r\n tenantId: string,\r\n ): IdTokenEntity {\r\n const idTokenEntity = new IdTokenEntity();\r\n\r\n idTokenEntity.credentialType = CredentialType.ID_TOKEN;\r\n idTokenEntity.homeAccountId = homeAccountId;\r\n idTokenEntity.environment = environment;\r\n idTokenEntity.clientId = clientId;\r\n idTokenEntity.secret = idToken;\r\n idTokenEntity.realm = tenantId;\r\n\r\n return idTokenEntity;\r\n }\r\n\r\n /**\r\n * Validates an entity: checks for all expected params\r\n * @param entity\r\n */\r\n static isIdTokenEntity(entity: object): boolean {\r\n\r\n if (!entity) {\r\n return false;\r\n }\r\n\r\n return (\r\n entity.hasOwnProperty(\"homeAccountId\") &&\r\n entity.hasOwnProperty(\"environment\") &&\r\n entity.hasOwnProperty(\"credentialType\") &&\r\n entity.hasOwnProperty(\"realm\") &&\r\n entity.hasOwnProperty(\"clientId\") &&\r\n entity.hasOwnProperty(\"secret\") &&\r\n entity[\"credentialType\"] === CredentialType.ID_TOKEN\r\n );\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { ClientAuthError } from \"./ClientAuthError\";\r\n\r\n/**\r\n * ClientConfigurationErrorMessage class containing string constants used by error codes and messages.\r\n */\r\nexport const ClientConfigurationErrorMessage = {\r\n redirectUriNotSet: {\r\n code: \"redirect_uri_empty\",\r\n desc: \"A redirect URI is required for all calls, and none has been set.\"\r\n },\r\n postLogoutUriNotSet: {\r\n code: \"post_logout_uri_empty\",\r\n desc: \"A post logout redirect has not been set.\"\r\n },\r\n claimsRequestParsingError: {\r\n code: \"claims_request_parsing_error\",\r\n desc: \"Could not parse the given claims request object.\"\r\n },\r\n authorityUriInsecure: {\r\n code: \"authority_uri_insecure\",\r\n desc: \"Authority URIs must use https. Please see here for valid authority configuration options: https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-js-initializing-client-applications#configuration-options\"\r\n },\r\n urlParseError: {\r\n code: \"url_parse_error\",\r\n desc: \"URL could not be parsed into appropriate segments.\"\r\n },\r\n urlEmptyError: {\r\n code: \"empty_url_error\",\r\n desc: \"URL was empty or null.\"\r\n },\r\n emptyScopesError: {\r\n code: \"empty_input_scopes_error\",\r\n desc: \"Scopes cannot be passed as null, undefined or empty array because they are required to obtain an access token.\"\r\n },\r\n nonArrayScopesError: {\r\n code: \"nonarray_input_scopes_error\",\r\n desc: \"Scopes cannot be passed as non-array.\"\r\n },\r\n clientIdSingleScopeError: {\r\n code: \"clientid_input_scopes_error\",\r\n desc: \"Client ID can only be provided as a single scope.\"\r\n },\r\n invalidPrompt: {\r\n code: \"invalid_prompt_value\",\r\n desc: \"Supported prompt values are 'login', 'select_account', 'consent', 'create', 'none' and 'no_session'. Please see here for valid configuration options: https://azuread.github.io/microsoft-authentication-library-for-js/ref/modules/_azure_msal_common.html#commonauthorizationurlrequest\",\r\n },\r\n invalidClaimsRequest: {\r\n code: \"invalid_claims\",\r\n desc: \"Given claims parameter must be a stringified JSON object.\"\r\n },\r\n tokenRequestEmptyError: {\r\n code: \"token_request_empty\",\r\n desc: \"Token request was empty and not found in cache.\"\r\n },\r\n logoutRequestEmptyError: {\r\n code: \"logout_request_empty\",\r\n desc: \"The logout request was null or undefined.\"\r\n },\r\n invalidCodeChallengeMethod: {\r\n code: \"invalid_code_challenge_method\",\r\n desc: \"code_challenge_method passed is invalid. Valid values are \\\"plain\\\" and \\\"S256\\\".\"\r\n },\r\n invalidCodeChallengeParams: {\r\n code: \"pkce_params_missing\",\r\n desc: \"Both params: code_challenge and code_challenge_method are to be passed if to be sent in the request\"\r\n },\r\n invalidCloudDiscoveryMetadata: {\r\n code: \"invalid_cloud_discovery_metadata\",\r\n desc: \"Invalid cloudDiscoveryMetadata provided. Must be a stringified JSON object containing tenant_discovery_endpoint and metadata fields\"\r\n },\r\n invalidAuthorityMetadata: {\r\n code: \"invalid_authority_metadata\",\r\n desc: \"Invalid authorityMetadata provided. Must by a stringified JSON object containing authorization_endpoint, token_endpoint, issuer fields.\"\r\n },\r\n untrustedAuthority: {\r\n code: \"untrusted_authority\",\r\n desc: \"The provided authority is not a trusted authority. Please include this authority in the knownAuthorities config parameter.\"\r\n },\r\n invalidAzureCloudInstance: {\r\n code: \"invalid_azure_cloud_instance\",\r\n desc: \"Invalid AzureCloudInstance provided. Please refer MSAL JS docs: aks.ms/msaljs/azure_cloud_instance for valid values\"\r\n },\r\n missingSshJwk: {\r\n code: \"missing_ssh_jwk\",\r\n desc: \"Missing sshJwk in SSH certificate request. A stringified JSON Web Key is required when using the SSH authentication scheme.\"\r\n },\r\n missingSshKid: {\r\n code: \"missing_ssh_kid\",\r\n desc: \"Missing sshKid in SSH certificate request. A string that uniquely identifies the public SSH key is required when using the SSH authentication scheme.\"\r\n },\r\n missingNonceAuthenticationHeader: {\r\n code: \"missing_nonce_authentication_header\",\r\n desc: \"Unable to find an authentication header containing server nonce. Either the Authentication-Info or WWW-Authenticate headers must be present in order to obtain a server nonce.\"\r\n },\r\n invalidAuthenticationHeader: {\r\n code: \"invalid_authentication_header\",\r\n desc: \"Invalid authentication header provided\"\r\n },\r\n authorityMismatch: {\r\n code: \"authority_mismatch\",\r\n desc: \"Authority mismatch error. Authority provided in login request or PublicClientApplication config does not match the environment of the provided account. Please use a matching account or make an interactive request to login to this authority.\"\r\n }\r\n};\r\n\r\n/**\r\n * Error thrown when there is an error in configuration of the MSAL.js library.\r\n */\r\nexport class ClientConfigurationError extends ClientAuthError {\r\n\r\n constructor(errorCode: string, errorMessage?: string) {\r\n super(errorCode, errorMessage);\r\n this.name = \"ClientConfigurationError\";\r\n Object.setPrototypeOf(this, ClientConfigurationError.prototype);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the redirect uri is empty (not set by caller)\r\n */\r\n static createRedirectUriEmptyError(): ClientConfigurationError {\r\n return new ClientConfigurationError(ClientConfigurationErrorMessage.redirectUriNotSet.code,\r\n ClientConfigurationErrorMessage.redirectUriNotSet.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the post-logout redirect uri is empty (not set by caller)\r\n */\r\n static createPostLogoutRedirectUriEmptyError(): ClientConfigurationError {\r\n return new ClientConfigurationError(ClientConfigurationErrorMessage.postLogoutUriNotSet.code,\r\n ClientConfigurationErrorMessage.postLogoutUriNotSet.desc);\r\n }\r\n\r\n /**\r\n * Creates an error thrown when the claims request could not be successfully parsed\r\n */\r\n static createClaimsRequestParsingError(claimsRequestParseError: string): ClientConfigurationError {\r\n return new ClientConfigurationError(ClientConfigurationErrorMessage.claimsRequestParsingError.code,\r\n `${ClientConfigurationErrorMessage.claimsRequestParsingError.desc} Given value: ${claimsRequestParseError}`);\r\n }\r\n\r\n /**\r\n * Creates an error thrown if authority uri is given an insecure protocol.\r\n * @param urlString\r\n */\r\n static createInsecureAuthorityUriError(urlString: string): ClientConfigurationError {\r\n return new ClientConfigurationError(ClientConfigurationErrorMessage.authorityUriInsecure.code,\r\n `${ClientConfigurationErrorMessage.authorityUriInsecure.desc} Given URI: ${urlString}`);\r\n }\r\n\r\n /**\r\n * Creates an error thrown if URL string does not parse into separate segments.\r\n * @param urlString\r\n */\r\n static createUrlParseError(urlParseError: string): ClientConfigurationError {\r\n return new ClientConfigurationError(ClientConfigurationErrorMessage.urlParseError.code,\r\n `${ClientConfigurationErrorMessage.urlParseError.desc} Given Error: ${urlParseError}`);\r\n }\r\n\r\n /**\r\n * Creates an error thrown if URL string is empty or null.\r\n * @param urlString\r\n */\r\n static createUrlEmptyError(): ClientConfigurationError {\r\n return new ClientConfigurationError(ClientConfigurationErrorMessage.urlEmptyError.code,\r\n ClientConfigurationErrorMessage.urlEmptyError.desc);\r\n }\r\n\r\n /**\r\n * Error thrown when scopes are empty.\r\n * @param scopesValue\r\n */\r\n static createEmptyScopesArrayError(): ClientConfigurationError {\r\n return new ClientConfigurationError(ClientConfigurationErrorMessage.emptyScopesError.code,\r\n `${ClientConfigurationErrorMessage.emptyScopesError.desc}`);\r\n }\r\n\r\n /**\r\n * Error thrown when client id scope is not provided as single scope.\r\n * @param inputScopes\r\n */\r\n static createClientIdSingleScopeError(inputScopes: Array): ClientConfigurationError {\r\n return new ClientConfigurationError(ClientConfigurationErrorMessage.clientIdSingleScopeError.code,\r\n `${ClientConfigurationErrorMessage.clientIdSingleScopeError.desc} Given Scopes: ${inputScopes}`);\r\n }\r\n\r\n /**\r\n * Error thrown when prompt is not an allowed type.\r\n * @param promptValue\r\n */\r\n static createInvalidPromptError(promptValue: string): ClientConfigurationError {\r\n return new ClientConfigurationError(ClientConfigurationErrorMessage.invalidPrompt.code,\r\n `${ClientConfigurationErrorMessage.invalidPrompt.desc} Given value: ${promptValue}`);\r\n }\r\n\r\n /**\r\n * Creates error thrown when claims parameter is not a stringified JSON object\r\n */\r\n static createInvalidClaimsRequestError(): ClientConfigurationError {\r\n return new ClientConfigurationError(ClientConfigurationErrorMessage.invalidClaimsRequest.code,\r\n ClientConfigurationErrorMessage.invalidClaimsRequest.desc);\r\n }\r\n\r\n /**\r\n * Throws error when token request is empty and nothing cached in storage.\r\n */\r\n static createEmptyLogoutRequestError(): ClientConfigurationError {\r\n return new ClientConfigurationError(\r\n ClientConfigurationErrorMessage.logoutRequestEmptyError.code,\r\n ClientConfigurationErrorMessage.logoutRequestEmptyError.desc\r\n );\r\n }\r\n\r\n /**\r\n * Throws error when token request is empty and nothing cached in storage.\r\n */\r\n static createEmptyTokenRequestError(): ClientConfigurationError {\r\n return new ClientConfigurationError(\r\n ClientConfigurationErrorMessage.tokenRequestEmptyError.code,\r\n ClientConfigurationErrorMessage.tokenRequestEmptyError.desc\r\n );\r\n }\r\n\r\n /**\r\n * Throws error when an invalid code_challenge_method is passed by the user\r\n */\r\n static createInvalidCodeChallengeMethodError(): ClientConfigurationError {\r\n return new ClientConfigurationError(\r\n ClientConfigurationErrorMessage.invalidCodeChallengeMethod.code,\r\n ClientConfigurationErrorMessage.invalidCodeChallengeMethod.desc\r\n );\r\n }\r\n\r\n /**\r\n * Throws error when both params: code_challenge and code_challenge_method are not passed together\r\n */\r\n static createInvalidCodeChallengeParamsError(): ClientConfigurationError {\r\n return new ClientConfigurationError(\r\n ClientConfigurationErrorMessage.invalidCodeChallengeParams.code,\r\n ClientConfigurationErrorMessage.invalidCodeChallengeParams.desc\r\n );\r\n }\r\n\r\n /**\r\n * Throws an error when the user passes invalid cloudDiscoveryMetadata\r\n */\r\n static createInvalidCloudDiscoveryMetadataError(): ClientConfigurationError {\r\n return new ClientConfigurationError(ClientConfigurationErrorMessage.invalidCloudDiscoveryMetadata.code,\r\n ClientConfigurationErrorMessage.invalidCloudDiscoveryMetadata.desc);\r\n }\r\n\r\n /**\r\n * Throws an error when the user passes invalid cloudDiscoveryMetadata\r\n */\r\n static createInvalidAuthorityMetadataError(): ClientConfigurationError {\r\n return new ClientConfigurationError(ClientConfigurationErrorMessage.invalidAuthorityMetadata.code,\r\n ClientConfigurationErrorMessage.invalidAuthorityMetadata.desc);\r\n }\r\n\r\n /**\r\n * Throws error when provided authority is not a member of the trusted host list\r\n */\r\n static createUntrustedAuthorityError(): ClientConfigurationError {\r\n return new ClientConfigurationError(ClientConfigurationErrorMessage.untrustedAuthority.code,\r\n ClientConfigurationErrorMessage.untrustedAuthority.desc);\r\n }\r\n\r\n /**\r\n * Throws error when the AzureCloudInstance is set to an invalid value\r\n */\r\n static createInvalidAzureCloudInstanceError(): ClientConfigurationError {\r\n return new ClientConfigurationError(ClientConfigurationErrorMessage.invalidAzureCloudInstance.code,\r\n ClientConfigurationErrorMessage.invalidAzureCloudInstance.desc);\r\n }\r\n\r\n /**\r\n * Throws an error when the authentication scheme is set to SSH but the SSH public key is omitted from the request\r\n */\r\n static createMissingSshJwkError(): ClientConfigurationError {\r\n return new ClientConfigurationError(ClientConfigurationErrorMessage.missingSshJwk.code,\r\n ClientConfigurationErrorMessage.missingSshJwk.desc);\r\n }\r\n\r\n /**\r\n * Throws an error when the authentication scheme is set to SSH but the SSH public key ID is omitted from the request\r\n */\r\n static createMissingSshKidError(): ClientConfigurationError {\r\n return new ClientConfigurationError(ClientConfigurationErrorMessage.missingSshKid.code,\r\n ClientConfigurationErrorMessage.missingSshKid.desc);\r\n }\r\n\r\n /**\r\n * Throws error when provided headers don't contain a header that a server nonce can be extracted from\r\n */\r\n static createMissingNonceAuthenticationHeadersError(): ClientConfigurationError {\r\n return new ClientConfigurationError(ClientConfigurationErrorMessage.missingNonceAuthenticationHeader.code,\r\n ClientConfigurationErrorMessage.missingNonceAuthenticationHeader.desc);\r\n }\r\n\r\n /**\r\n * Throws error when a provided header is invalid in any way\r\n */\r\n static createInvalidAuthenticationHeaderError(invalidHeaderName: string, details: string): ClientConfigurationError {\r\n return new ClientConfigurationError(ClientConfigurationErrorMessage.invalidAuthenticationHeader.code,\r\n `${ClientConfigurationErrorMessage.invalidAuthenticationHeader.desc}. Invalid header: ${invalidHeaderName}. Details: ${details}`);\r\n }\r\n \r\n /**\r\n * Create an error when the authority provided in request does not match authority provided in account or MSAL.js configuration.\r\n */\r\n static createAuthorityMismatchError(): ClientConfigurationError {\r\n return new ClientConfigurationError(ClientConfigurationErrorMessage.authorityMismatch.code, ClientConfigurationErrorMessage.authorityMismatch.desc);\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { ClientConfigurationError } from \"../error/ClientConfigurationError\";\r\nimport { StringUtils } from \"../utils/StringUtils\";\r\nimport { ClientAuthError } from \"../error/ClientAuthError\";\r\nimport { Constants, OIDC_SCOPES } from \"../utils/Constants\";\r\n\r\n/**\r\n * The ScopeSet class creates a set of scopes. Scopes are case-insensitive, unique values, so the Set object in JS makes\r\n * the most sense to implement for this class. All scopes are trimmed and converted to lower case strings in intersection and union functions\r\n * to ensure uniqueness of strings.\r\n */\r\nexport class ScopeSet {\r\n // Scopes as a Set of strings\r\n private scopes: Set;\r\n\r\n constructor(inputScopes: Array) {\r\n // Filter empty string and null/undefined array items\r\n const scopeArr = inputScopes ? StringUtils.trimArrayEntries([...inputScopes]) : [];\r\n const filteredInput = scopeArr ? StringUtils.removeEmptyStringsFromArray(scopeArr) : [];\r\n\r\n // Validate and filter scopes (validate function throws if validation fails)\r\n this.validateInputScopes(filteredInput);\r\n\r\n this.scopes = new Set(); // Iterator in constructor not supported by IE11\r\n filteredInput.forEach(scope => this.scopes.add(scope));\r\n }\r\n\r\n /**\r\n * Factory method to create ScopeSet from space-delimited string\r\n * @param inputScopeString\r\n * @param appClientId\r\n * @param scopesRequired\r\n */\r\n static fromString(inputScopeString: string): ScopeSet {\r\n const scopeString = inputScopeString || Constants.EMPTY_STRING;\r\n const inputScopes: Array = scopeString.split(\" \");\r\n return new ScopeSet(inputScopes);\r\n }\r\n\r\n /**\r\n * Creates the set of scopes to search for in cache lookups\r\n * @param inputScopeString \r\n * @returns \r\n */\r\n static createSearchScopes(inputScopeString: Array): ScopeSet {\r\n const scopeSet = new ScopeSet(inputScopeString);\r\n if (!scopeSet.containsOnlyOIDCScopes()) {\r\n scopeSet.removeOIDCScopes();\r\n } else {\r\n scopeSet.removeScope(Constants.OFFLINE_ACCESS_SCOPE);\r\n }\r\n\r\n return scopeSet;\r\n }\r\n\r\n /**\r\n * Used to validate the scopes input parameter requested by the developer.\r\n * @param {Array} inputScopes - Developer requested permissions. Not all scopes are guaranteed to be included in the access token returned.\r\n * @param {boolean} scopesRequired - Boolean indicating whether the scopes array is required or not\r\n */\r\n private validateInputScopes(inputScopes: Array): void {\r\n // Check if scopes are required but not given or is an empty array\r\n if (!inputScopes || inputScopes.length < 1) {\r\n throw ClientConfigurationError.createEmptyScopesArrayError();\r\n }\r\n }\r\n\r\n /**\r\n * Check if a given scope is present in this set of scopes.\r\n * @param scope\r\n */\r\n containsScope(scope: string): boolean {\r\n const lowerCaseScopes = this.printScopesLowerCase().split(\" \");\r\n const lowerCaseScopesSet = new ScopeSet(lowerCaseScopes);\r\n // compare lowercase scopes\r\n return !StringUtils.isEmpty(scope) ? lowerCaseScopesSet.scopes.has(scope.toLowerCase()) : false;\r\n }\r\n\r\n /**\r\n * Check if a set of scopes is present in this set of scopes.\r\n * @param scopeSet\r\n */\r\n containsScopeSet(scopeSet: ScopeSet): boolean {\r\n if (!scopeSet || scopeSet.scopes.size <= 0) {\r\n return false;\r\n }\r\n\r\n return (this.scopes.size >= scopeSet.scopes.size && scopeSet.asArray().every(scope => this.containsScope(scope)));\r\n }\r\n\r\n /**\r\n * Check if set of scopes contains only the defaults\r\n */\r\n containsOnlyOIDCScopes(): boolean {\r\n let defaultScopeCount = 0;\r\n OIDC_SCOPES.forEach((defaultScope: string) => {\r\n if (this.containsScope(defaultScope)) {\r\n defaultScopeCount += 1;\r\n }\r\n });\r\n\r\n return this.scopes.size === defaultScopeCount;\r\n }\r\n\r\n /**\r\n * Appends single scope if passed\r\n * @param newScope\r\n */\r\n appendScope(newScope: string): void {\r\n if (!StringUtils.isEmpty(newScope)) {\r\n this.scopes.add(newScope.trim());\r\n }\r\n }\r\n\r\n /**\r\n * Appends multiple scopes if passed\r\n * @param newScopes\r\n */\r\n appendScopes(newScopes: Array): void {\r\n try {\r\n newScopes.forEach(newScope => this.appendScope(newScope));\r\n } catch (e) {\r\n throw ClientAuthError.createAppendScopeSetError(e);\r\n }\r\n }\r\n\r\n /**\r\n * Removes element from set of scopes.\r\n * @param scope\r\n */\r\n removeScope(scope: string): void {\r\n if (StringUtils.isEmpty(scope)) {\r\n throw ClientAuthError.createRemoveEmptyScopeFromSetError(scope);\r\n }\r\n this.scopes.delete(scope.trim());\r\n }\r\n\r\n /**\r\n * Removes default scopes from set of scopes\r\n * Primarily used to prevent cache misses if the default scopes are not returned from the server\r\n */\r\n removeOIDCScopes(): void {\r\n OIDC_SCOPES.forEach((defaultScope: string) => {\r\n this.scopes.delete(defaultScope);\r\n });\r\n }\r\n\r\n /**\r\n * Combines an array of scopes with the current set of scopes.\r\n * @param otherScopes\r\n */\r\n unionScopeSets(otherScopes: ScopeSet): Set {\r\n if (!otherScopes) {\r\n throw ClientAuthError.createEmptyInputScopeSetError();\r\n }\r\n const unionScopes = new Set(); // Iterator in constructor not supported in IE11\r\n otherScopes.scopes.forEach(scope => unionScopes.add(scope.toLowerCase()));\r\n this.scopes.forEach(scope => unionScopes.add(scope.toLowerCase()));\r\n return unionScopes;\r\n }\r\n\r\n /**\r\n * Check if scopes intersect between this set and another.\r\n * @param otherScopes\r\n */\r\n intersectingScopeSets(otherScopes: ScopeSet): boolean {\r\n if (!otherScopes) {\r\n throw ClientAuthError.createEmptyInputScopeSetError();\r\n }\r\n \r\n // Do not allow OIDC scopes to be the only intersecting scopes\r\n if (!otherScopes.containsOnlyOIDCScopes()) {\r\n otherScopes.removeOIDCScopes();\r\n }\r\n const unionScopes = this.unionScopeSets(otherScopes);\r\n const sizeOtherScopes = otherScopes.getScopeCount();\r\n const sizeThisScopes = this.getScopeCount();\r\n const sizeUnionScopes = unionScopes.size;\r\n return sizeUnionScopes < (sizeThisScopes + sizeOtherScopes);\r\n }\r\n\r\n /**\r\n * Returns size of set of scopes.\r\n */\r\n getScopeCount(): number {\r\n return this.scopes.size;\r\n }\r\n\r\n /**\r\n * Returns the scopes as an array of string values\r\n */\r\n asArray(): Array {\r\n const array: Array = [];\r\n this.scopes.forEach(val => array.push(val));\r\n return array;\r\n }\r\n\r\n /**\r\n * Prints scopes into a space-delimited string\r\n */\r\n printScopes(): string {\r\n if (this.scopes) {\r\n const scopeArr = this.asArray();\r\n return scopeArr.join(\" \");\r\n }\r\n return Constants.EMPTY_STRING;\r\n }\r\n\r\n /**\r\n * Prints scopes into a space-delimited lower-case string (used for caching)\r\n */\r\n printScopesLowerCase(): string {\r\n return this.printScopes().toLowerCase();\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { TokenClaims } from \"./TokenClaims\";\r\nimport { DecodedAuthToken } from \"./DecodedAuthToken\";\r\nimport { ClientAuthError } from \"../error/ClientAuthError\";\r\nimport { StringUtils } from \"../utils/StringUtils\";\r\nimport { ICrypto } from \"../crypto/ICrypto\";\r\n\r\n/**\r\n * JWT Token representation class. Parses token string and generates claims object.\r\n */\r\nexport class AuthToken {\r\n\r\n // Raw Token string\r\n rawToken: string;\r\n // Claims inside token\r\n claims: TokenClaims;\r\n constructor(rawToken: string, crypto: ICrypto) {\r\n if (StringUtils.isEmpty(rawToken)) {\r\n throw ClientAuthError.createTokenNullOrEmptyError(rawToken);\r\n }\r\n\r\n this.rawToken = rawToken;\r\n this.claims = AuthToken.extractTokenClaims(rawToken, crypto);\r\n }\r\n\r\n /**\r\n * Extract token by decoding the rawToken\r\n *\r\n * @param encodedToken\r\n */\r\n static extractTokenClaims(encodedToken: string, crypto: ICrypto): TokenClaims {\r\n\r\n const decodedToken: DecodedAuthToken = StringUtils.decodeAuthToken(encodedToken);\r\n\r\n // token will be decoded to get the username\r\n try {\r\n const base64TokenPayload = decodedToken.JWSPayload;\r\n\r\n // base64Decode() should throw an error if there is an issue\r\n const base64Decoded = crypto.base64Decode(base64TokenPayload);\r\n return JSON.parse(base64Decoded) as TokenClaims;\r\n } catch (err) {\r\n throw ClientAuthError.createTokenParsingError(err);\r\n }\r\n }\r\n\r\n /**\r\n * Determine if the token's max_age has transpired\r\n */\r\n static checkMaxAge(authTime: number, maxAge: number): void {\r\n /*\r\n * per https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest\r\n * To force an immediate re-authentication: If an app requires that a user re-authenticate prior to access,\r\n * provide a value of 0 for the max_age parameter and the AS will force a fresh login.\r\n */\r\n const fiveMinuteSkew = 300000; // five minutes in milliseconds\r\n if ((maxAge === 0) || ((Date.now() - fiveMinuteSkew) > (authTime + maxAge))) {\r\n throw ClientAuthError.createMaxAgeTranspiredError();\r\n }\r\n }\r\n}\r\n","/* eslint-disable header/header */\nexport const name = \"@azure/msal-common\";\nexport const version = \"13.3.3\";\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { AccountFilter, CredentialFilter, ValidCredentialType, AppMetadataFilter, AppMetadataCache, TokenKeys } from \"./utils/CacheTypes\";\r\nimport { CacheRecord } from \"./entities/CacheRecord\";\r\nimport { CredentialType, APP_METADATA, THE_FAMILY_ID, AUTHORITY_METADATA_CONSTANTS, AuthenticationScheme, Separators } from \"../utils/Constants\";\r\nimport { CredentialEntity } from \"./entities/CredentialEntity\";\r\nimport { ScopeSet } from \"../request/ScopeSet\";\r\nimport { AccountEntity } from \"./entities/AccountEntity\";\r\nimport { AccessTokenEntity } from \"./entities/AccessTokenEntity\";\r\nimport { IdTokenEntity } from \"./entities/IdTokenEntity\";\r\nimport { RefreshTokenEntity } from \"./entities/RefreshTokenEntity\";\r\nimport { AuthError } from \"../error/AuthError\";\r\nimport { ICacheManager } from \"./interface/ICacheManager\";\r\nimport { ClientAuthError } from \"../error/ClientAuthError\";\r\nimport { AccountInfo } from \"../account/AccountInfo\";\r\nimport { AppMetadataEntity } from \"./entities/AppMetadataEntity\";\r\nimport { ServerTelemetryEntity } from \"./entities/ServerTelemetryEntity\";\r\nimport { ThrottlingEntity } from \"./entities/ThrottlingEntity\";\r\nimport { AuthToken } from \"../account/AuthToken\";\r\nimport { ICrypto } from \"../crypto/ICrypto\";\r\nimport { AuthorityMetadataEntity } from \"./entities/AuthorityMetadataEntity\";\r\nimport { BaseAuthRequest } from \"../request/BaseAuthRequest\";\r\nimport { Logger } from \"../logger/Logger\";\r\nimport { name, version } from \"../packageMetadata\";\r\n\r\n/**\r\n * Interface class which implement cache storage functions used by MSAL to perform validity checks, and store tokens.\r\n */\r\nexport abstract class CacheManager implements ICacheManager {\r\n protected clientId: string;\r\n protected cryptoImpl: ICrypto;\r\n // Instance of logger for functions defined in the msal-common layer\r\n private commonLogger: Logger;\r\n\r\n constructor(clientId: string, cryptoImpl: ICrypto, logger: Logger) {\r\n this.clientId = clientId;\r\n this.cryptoImpl = cryptoImpl;\r\n this.commonLogger = logger.clone(name, version);\r\n }\r\n\r\n /**\r\n * fetch the account entity from the platform cache\r\n * @param accountKey\r\n */\r\n abstract getAccount(accountKey: string): AccountEntity | null;\r\n\r\n /**\r\n * set account entity in the platform cache\r\n * @param account\r\n */\r\n abstract setAccount(account: AccountEntity): void;\r\n\r\n /**\r\n * fetch the idToken entity from the platform cache\r\n * @param idTokenKey\r\n */\r\n abstract getIdTokenCredential(idTokenKey: string): IdTokenEntity | null;\r\n\r\n /**\r\n * set idToken entity to the platform cache\r\n * @param idToken\r\n */\r\n abstract setIdTokenCredential(idToken: IdTokenEntity): void;\r\n\r\n /**\r\n * fetch the idToken entity from the platform cache\r\n * @param accessTokenKey\r\n */\r\n abstract getAccessTokenCredential(accessTokenKey: string): AccessTokenEntity | null;\r\n\r\n /**\r\n * set idToken entity to the platform cache\r\n * @param accessToken\r\n */\r\n abstract setAccessTokenCredential(accessToken: AccessTokenEntity): void;\r\n\r\n /**\r\n * fetch the idToken entity from the platform cache\r\n * @param refreshTokenKey\r\n */\r\n abstract getRefreshTokenCredential(refreshTokenKey: string): RefreshTokenEntity | null;\r\n\r\n /**\r\n * set idToken entity to the platform cache\r\n * @param refreshToken\r\n */\r\n abstract setRefreshTokenCredential(refreshToken: RefreshTokenEntity): void;\r\n\r\n /**\r\n * fetch appMetadata entity from the platform cache\r\n * @param appMetadataKey\r\n */\r\n abstract getAppMetadata(appMetadataKey: string): AppMetadataEntity | null;\r\n\r\n /**\r\n * set appMetadata entity to the platform cache\r\n * @param appMetadata\r\n */\r\n abstract setAppMetadata(appMetadata: AppMetadataEntity): void;\r\n\r\n /**\r\n * fetch server telemetry entity from the platform cache\r\n * @param serverTelemetryKey\r\n */\r\n abstract getServerTelemetry(serverTelemetryKey: string): ServerTelemetryEntity | null;\r\n\r\n /**\r\n * set server telemetry entity to the platform cache\r\n * @param serverTelemetryKey\r\n * @param serverTelemetry\r\n */\r\n abstract setServerTelemetry(serverTelemetryKey: string, serverTelemetry: ServerTelemetryEntity): void;\r\n\r\n /**\r\n * fetch cloud discovery metadata entity from the platform cache\r\n * @param key\r\n */\r\n abstract getAuthorityMetadata(key: string): AuthorityMetadataEntity | null;\r\n\r\n /**\r\n *\r\n */\r\n abstract getAuthorityMetadataKeys(): Array;\r\n\r\n /**\r\n * set cloud discovery metadata entity to the platform cache\r\n * @param key\r\n * @param value\r\n */\r\n abstract setAuthorityMetadata(key: string, value: AuthorityMetadataEntity): void;\r\n\r\n /**\r\n * fetch throttling entity from the platform cache\r\n * @param throttlingCacheKey\r\n */\r\n abstract getThrottlingCache(throttlingCacheKey: string): ThrottlingEntity | null;\r\n\r\n /**\r\n * set throttling entity to the platform cache\r\n * @param throttlingCacheKey\r\n * @param throttlingCache\r\n */\r\n abstract setThrottlingCache(throttlingCacheKey: string, throttlingCache: ThrottlingEntity): void;\r\n\r\n /**\r\n * Function to remove an item from cache given its key.\r\n * @param key\r\n */\r\n abstract removeItem(key: string): void;\r\n\r\n /**\r\n * Function which returns boolean whether cache contains a specific key.\r\n * @param key\r\n */\r\n abstract containsKey(key: string, type?: string): boolean;\r\n\r\n /**\r\n * Function which retrieves all current keys from the cache.\r\n */\r\n abstract getKeys(): string[];\r\n\r\n /**\r\n * Function which retrieves all account keys from the cache\r\n */\r\n abstract getAccountKeys(): string[];\r\n\r\n /**\r\n * Function which retrieves all token keys from the cache\r\n */\r\n abstract getTokenKeys(): TokenKeys;\r\n\r\n /**\r\n * Function which clears cache.\r\n */\r\n abstract clear(): Promise;\r\n\r\n /**\r\n * Function which updates an outdated credential cache key\r\n */\r\n abstract updateCredentialCacheKey(currentCacheKey: string, credential: ValidCredentialType): string;\r\n\r\n /**\r\n * Returns all accounts in cache\r\n */\r\n getAllAccounts(): AccountInfo[] {\r\n const allAccountKeys = this.getAccountKeys();\r\n if (allAccountKeys.length < 1) {\r\n return [];\r\n }\r\n\r\n const accountEntities: AccountEntity[] = allAccountKeys.reduce((accounts: AccountEntity[], key: string) => {\r\n const entity: AccountEntity | null = this.getAccount(key);\r\n\r\n if (!entity) {\r\n return accounts;\r\n }\r\n accounts.push(entity);\r\n return accounts;\r\n }, []);\r\n\r\n if (accountEntities.length < 1) {\r\n return [];\r\n } else {\r\n const allAccounts = accountEntities.map((accountEntity) => {\r\n return this.getAccountInfoFromEntity(accountEntity);\r\n });\r\n return allAccounts;\r\n }\r\n }\r\n\r\n /** \r\n * Gets accountInfo object based on provided filters\r\n */\r\n getAccountInfoFilteredBy(accountFilter: AccountFilter): AccountInfo | null{\r\n const allAccounts = this.getAccountsFilteredBy(accountFilter);\r\n if (allAccounts.length > 0) {\r\n return this.getAccountInfoFromEntity(allAccounts[0]);\r\n } else {\r\n return null;\r\n }\r\n }\r\n\r\n private getAccountInfoFromEntity(accountEntity: AccountEntity): AccountInfo {\r\n const accountInfo = accountEntity.getAccountInfo();\r\n const idToken = this.getIdToken(accountInfo);\r\n if (idToken) {\r\n accountInfo.idToken = idToken.secret;\r\n accountInfo.idTokenClaims = new AuthToken(idToken.secret, this.cryptoImpl).claims;\r\n }\r\n return accountInfo;\r\n }\r\n\r\n /**\r\n * saves a cache record\r\n * @param cacheRecord\r\n */\r\n async saveCacheRecord(cacheRecord: CacheRecord): Promise {\r\n if (!cacheRecord) {\r\n throw ClientAuthError.createNullOrUndefinedCacheRecord();\r\n }\r\n\r\n if (!!cacheRecord.account) {\r\n this.setAccount(cacheRecord.account);\r\n }\r\n\r\n if (!!cacheRecord.idToken) {\r\n this.setIdTokenCredential(cacheRecord.idToken);\r\n }\r\n\r\n if (!!cacheRecord.accessToken) {\r\n await this.saveAccessToken(cacheRecord.accessToken);\r\n }\r\n\r\n if (!!cacheRecord.refreshToken) {\r\n this.setRefreshTokenCredential(cacheRecord.refreshToken);\r\n }\r\n\r\n if (!!cacheRecord.appMetadata) {\r\n this.setAppMetadata(cacheRecord.appMetadata);\r\n }\r\n }\r\n\r\n /**\r\n * saves access token credential\r\n * @param credential\r\n */\r\n private async saveAccessToken(credential: AccessTokenEntity): Promise {\r\n const accessTokenFilter: CredentialFilter = {\r\n clientId: credential.clientId,\r\n credentialType: credential.credentialType,\r\n environment: credential.environment,\r\n homeAccountId: credential.homeAccountId,\r\n realm: credential.realm,\r\n tokenType: credential.tokenType,\r\n requestedClaimsHash: credential.requestedClaimsHash\r\n };\r\n\r\n const tokenKeys = this.getTokenKeys();\r\n const currentScopes = ScopeSet.fromString(credential.target);\r\n\r\n const removedAccessTokens: Array> = [];\r\n tokenKeys.accessToken.forEach((key) => {\r\n if(!this.accessTokenKeyMatchesFilter(key, accessTokenFilter, false)) {\r\n return;\r\n }\r\n \r\n const tokenEntity = this.getAccessTokenCredential(key);\r\n\r\n if (tokenEntity && this.credentialMatchesFilter(tokenEntity, accessTokenFilter)) {\r\n const tokenScopeSet = ScopeSet.fromString(tokenEntity.target);\r\n if (tokenScopeSet.intersectingScopeSets(currentScopes)) {\r\n removedAccessTokens.push(this.removeAccessToken(key));\r\n }\r\n }\r\n });\r\n await Promise.all(removedAccessTokens);\r\n this.setAccessTokenCredential(credential);\r\n }\r\n\r\n /**\r\n * retrieve accounts matching all provided filters; if no filter is set, get all accounts\r\n * not checking for casing as keys are all generated in lower case, remember to convert to lower case if object properties are compared\r\n * @param homeAccountId\r\n * @param environment\r\n * @param realm\r\n */\r\n getAccountsFilteredBy(accountFilter: AccountFilter): AccountEntity[] {\r\n const allAccountKeys = this.getAccountKeys();\r\n const matchingAccounts: AccountEntity[] = [];\r\n\r\n allAccountKeys.forEach((cacheKey) => {\r\n if (!this.isAccountKey(cacheKey, accountFilter.homeAccountId, accountFilter.realm)) {\r\n // Don't parse value if the key doesn't match the account filters\r\n return;\r\n }\r\n\r\n const entity: AccountEntity | null = this.getAccount(cacheKey);\r\n\r\n if (!entity) {\r\n return;\r\n }\r\n\r\n if (!!accountFilter.homeAccountId && !this.matchHomeAccountId(entity, accountFilter.homeAccountId)) {\r\n return;\r\n }\r\n\r\n if (!!accountFilter.localAccountId && !this.matchLocalAccountId(entity, accountFilter.localAccountId)) {\r\n return;\r\n }\r\n\r\n if (!!accountFilter.username && !this.matchUsername(entity, accountFilter.username)) {\r\n return;\r\n }\r\n\r\n if (!!accountFilter.environment && !this.matchEnvironment(entity, accountFilter.environment)) {\r\n return;\r\n }\r\n\r\n if (!!accountFilter.realm && !this.matchRealm(entity, accountFilter.realm)) {\r\n return;\r\n }\r\n\r\n if (!!accountFilter.nativeAccountId && !this.matchNativeAccountId(entity, accountFilter.nativeAccountId)) {\r\n return;\r\n }\r\n\r\n matchingAccounts.push(entity);\r\n });\r\n\r\n return matchingAccounts;\r\n }\r\n\r\n /**\r\n * Returns true if the given key matches our account key schema. Also matches homeAccountId and/or tenantId if provided\r\n * @param key \r\n * @param homeAccountId \r\n * @param tenantId \r\n * @returns \r\n */\r\n isAccountKey(key: string, homeAccountId?: string, tenantId?: string): boolean {\r\n if (key.split(Separators.CACHE_KEY_SEPARATOR).length < 3) {\r\n // Account cache keys contain 3 items separated by '-' (each item may also contain '-')\r\n return false;\r\n }\r\n\r\n if (homeAccountId && !key.toLowerCase().includes(homeAccountId.toLowerCase())) {\r\n return false;\r\n }\r\n\r\n if (tenantId && !key.toLowerCase().includes(tenantId.toLowerCase())) {\r\n return false;\r\n }\r\n\r\n // Do not check environment as aliasing can cause false negatives\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Returns true if the given key matches our credential key schema.\r\n * @param key \r\n */\r\n isCredentialKey(key: string): boolean {\r\n if (key.split(Separators.CACHE_KEY_SEPARATOR).length < 6) {\r\n // Credential cache keys contain 6 items separated by '-' (each item may also contain '-')\r\n return false;\r\n }\r\n\r\n const lowerCaseKey = key.toLowerCase();\r\n // Credential keys must indicate what credential type they represent\r\n if (lowerCaseKey.indexOf(CredentialType.ID_TOKEN.toLowerCase()) === -1 &&\r\n lowerCaseKey.indexOf(CredentialType.ACCESS_TOKEN.toLowerCase()) === -1 &&\r\n lowerCaseKey.indexOf(CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME.toLowerCase()) === -1 &&\r\n lowerCaseKey.indexOf(CredentialType.REFRESH_TOKEN.toLowerCase()) === -1\r\n ) {\r\n return false;\r\n }\r\n\r\n if (lowerCaseKey.indexOf(CredentialType.REFRESH_TOKEN.toLowerCase()) > -1) {\r\n // Refresh tokens must contain the client id or family id\r\n const clientIdValidation = `${CredentialType.REFRESH_TOKEN}${Separators.CACHE_KEY_SEPARATOR}${this.clientId}${Separators.CACHE_KEY_SEPARATOR}`;\r\n const familyIdValidation = `${CredentialType.REFRESH_TOKEN}${Separators.CACHE_KEY_SEPARATOR}${THE_FAMILY_ID}${Separators.CACHE_KEY_SEPARATOR}`;\r\n if (lowerCaseKey.indexOf(clientIdValidation.toLowerCase()) === -1 && lowerCaseKey.indexOf(familyIdValidation.toLowerCase()) === -1) {\r\n return false;\r\n }\r\n } else if (lowerCaseKey.indexOf(this.clientId.toLowerCase()) === -1) {\r\n // Tokens must contain the clientId\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Returns whether or not the given credential entity matches the filter\r\n * @param entity \r\n * @param filter \r\n * @returns \r\n */\r\n credentialMatchesFilter(entity: ValidCredentialType, filter: CredentialFilter): boolean {\r\n if (!!filter.clientId && !this.matchClientId(entity, filter.clientId)) {\r\n return false;\r\n }\r\n\r\n if (!!filter.userAssertionHash && !this.matchUserAssertionHash(entity, filter.userAssertionHash)) {\r\n return false;\r\n }\r\n\r\n /*\r\n * homeAccountId can be undefined, and we want to filter out cached items that have a homeAccountId of \"\"\r\n * because we don't want a client_credential request to return a cached token that has a homeAccountId\r\n */\r\n if ((typeof filter.homeAccountId === \"string\") && !this.matchHomeAccountId(entity, filter.homeAccountId)) {\r\n return false;\r\n }\r\n\r\n if (!!filter.environment && !this.matchEnvironment(entity, filter.environment)) {\r\n return false;\r\n }\r\n\r\n if (!!filter.realm && !this.matchRealm(entity, filter.realm)) {\r\n return false;\r\n }\r\n\r\n if (!!filter.credentialType && !this.matchCredentialType(entity, filter.credentialType)) {\r\n return false;\r\n }\r\n\r\n if (!!filter.familyId && !this.matchFamilyId(entity, filter.familyId)) {\r\n return false;\r\n }\r\n\r\n /*\r\n * idTokens do not have \"target\", target specific refreshTokens do exist for some types of authentication\r\n * Resource specific refresh tokens case will be added when the support is deemed necessary\r\n */\r\n if (!!filter.target && !this.matchTarget(entity, filter.target)) {\r\n return false;\r\n }\r\n\r\n // If request OR cached entity has requested Claims Hash, check if they match\r\n if (filter.requestedClaimsHash || entity.requestedClaimsHash) {\r\n // Don't match if either is undefined or they are different\r\n if (entity.requestedClaimsHash !== filter.requestedClaimsHash) {\r\n return false;\r\n }\r\n }\r\n\r\n // Access Token with Auth Scheme specific matching\r\n if (entity.credentialType === CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME) {\r\n if(!!filter.tokenType && !this.matchTokenType(entity, filter.tokenType)) {\r\n return false;\r\n }\r\n\r\n // KeyId (sshKid) in request must match cached SSH certificate keyId because SSH cert is bound to a specific key\r\n if (filter.tokenType === AuthenticationScheme.SSH) {\r\n if(filter.keyId && !this.matchKeyId(entity, filter.keyId)) {\r\n return false;\r\n }\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * retrieve appMetadata matching all provided filters; if no filter is set, get all appMetadata\r\n * @param filter\r\n */\r\n getAppMetadataFilteredBy(filter: AppMetadataFilter): AppMetadataCache {\r\n return this.getAppMetadataFilteredByInternal(\r\n filter.environment,\r\n filter.clientId,\r\n );\r\n }\r\n\r\n /**\r\n * Support function to help match appMetadata\r\n * @param environment\r\n * @param clientId\r\n */\r\n private getAppMetadataFilteredByInternal(\r\n environment?: string,\r\n clientId?: string\r\n ): AppMetadataCache {\r\n\r\n const allCacheKeys = this.getKeys();\r\n const matchingAppMetadata: AppMetadataCache = {};\r\n\r\n allCacheKeys.forEach((cacheKey) => {\r\n // don't parse any non-appMetadata type cache entities\r\n if (!this.isAppMetadata(cacheKey)) {\r\n return;\r\n }\r\n\r\n // Attempt retrieval\r\n const entity = this.getAppMetadata(cacheKey);\r\n\r\n if (!entity) {\r\n return;\r\n }\r\n\r\n if (!!environment && !this.matchEnvironment(entity, environment)) {\r\n return;\r\n }\r\n\r\n if (!!clientId && !this.matchClientId(entity, clientId)) {\r\n return;\r\n }\r\n\r\n matchingAppMetadata[cacheKey] = entity;\r\n\r\n });\r\n\r\n return matchingAppMetadata;\r\n }\r\n\r\n /**\r\n * retrieve authorityMetadata that contains a matching alias\r\n * @param filter\r\n */\r\n getAuthorityMetadataByAlias(host: string): AuthorityMetadataEntity | null {\r\n const allCacheKeys = this.getAuthorityMetadataKeys();\r\n let matchedEntity = null;\r\n\r\n allCacheKeys.forEach((cacheKey) => {\r\n // don't parse any non-authorityMetadata type cache entities\r\n if (!this.isAuthorityMetadata(cacheKey) || cacheKey.indexOf(this.clientId) === -1) {\r\n return;\r\n }\r\n\r\n // Attempt retrieval\r\n const entity = this.getAuthorityMetadata(cacheKey);\r\n\r\n if (!entity) {\r\n return;\r\n }\r\n\r\n if (entity.aliases.indexOf(host) === -1) {\r\n return;\r\n }\r\n\r\n matchedEntity = entity;\r\n\r\n });\r\n\r\n return matchedEntity;\r\n }\r\n\r\n /**\r\n * Removes all accounts and related tokens from cache.\r\n */\r\n async removeAllAccounts(): Promise {\r\n const allAccountKeys = this.getAccountKeys();\r\n const removedAccounts: Array> = [];\r\n\r\n allAccountKeys.forEach((cacheKey) => {\r\n removedAccounts.push(this.removeAccount(cacheKey));\r\n });\r\n\r\n await Promise.all(removedAccounts);\r\n }\r\n\r\n /**\r\n * Removes the account and related tokens for a given account key\r\n * @param account\r\n */\r\n async removeAccount(accountKey: string): Promise {\r\n const account = this.getAccount(accountKey);\r\n if (!account) {\r\n throw ClientAuthError.createNoAccountFoundError();\r\n }\r\n await this.removeAccountContext(account);\r\n this.removeItem(accountKey);\r\n }\r\n\r\n /**\r\n * Removes credentials associated with the provided account\r\n * @param account\r\n */\r\n async removeAccountContext(account: AccountEntity): Promise {\r\n const allTokenKeys = this.getTokenKeys();\r\n const accountId = account.generateAccountId();\r\n const removedCredentials: Array> = [];\r\n\r\n allTokenKeys.idToken.forEach((key) => {\r\n if (key.indexOf(accountId) === 0) {\r\n this.removeIdToken(key);\r\n }\r\n });\r\n\r\n allTokenKeys.accessToken.forEach((key) => {\r\n if (key.indexOf(accountId) === 0) {\r\n removedCredentials.push(this.removeAccessToken(key));\r\n }\r\n });\r\n\r\n allTokenKeys.refreshToken.forEach((key) => {\r\n if (key.indexOf(accountId) === 0) {\r\n this.removeRefreshToken(key);\r\n }\r\n });\r\n\r\n await Promise.all(removedCredentials);\r\n }\r\n\r\n /**\r\n * returns a boolean if the given credential is removed\r\n * @param credential\r\n */\r\n async removeAccessToken(key: string): Promise {\r\n const credential = this.getAccessTokenCredential(key);\r\n if (!credential) {\r\n return;\r\n }\r\n\r\n // Remove Token Binding Key from key store for PoP Tokens Credentials\r\n if (credential.credentialType.toLowerCase() === CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME.toLowerCase()) {\r\n if(credential.tokenType === AuthenticationScheme.POP) {\r\n const accessTokenWithAuthSchemeEntity = credential as AccessTokenEntity;\r\n const kid = accessTokenWithAuthSchemeEntity.keyId;\r\n\r\n if (kid) {\r\n try {\r\n await this.cryptoImpl.removeTokenBindingKey(kid);\r\n } catch (error) {\r\n throw ClientAuthError.createBindingKeyNotRemovedError();\r\n }\r\n }\r\n }\r\n }\r\n\r\n return this.removeItem(key);\r\n }\r\n\r\n /**\r\n * Removes all app metadata objects from cache.\r\n */\r\n removeAppMetadata(): boolean {\r\n const allCacheKeys = this.getKeys();\r\n allCacheKeys.forEach((cacheKey) => {\r\n if (this.isAppMetadata(cacheKey)) {\r\n this.removeItem(cacheKey);\r\n }\r\n });\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Retrieve the cached credentials into a cacherecord\r\n * @param account\r\n * @param clientId\r\n * @param scopes\r\n * @param environment\r\n * @param authScheme\r\n */\r\n readCacheRecord(account: AccountInfo, request: BaseAuthRequest, environment: string): CacheRecord {\r\n const tokenKeys = this.getTokenKeys();\r\n const cachedAccount = this.readAccountFromCache(account);\r\n const cachedIdToken = this.getIdToken(account, tokenKeys);\r\n const cachedAccessToken = this.getAccessToken(account, request, tokenKeys);\r\n const cachedRefreshToken = this.getRefreshToken(account, false, tokenKeys);\r\n const cachedAppMetadata = this.readAppMetadataFromCache(environment);\r\n\r\n if (cachedAccount && cachedIdToken) {\r\n cachedAccount.idTokenClaims = new AuthToken(cachedIdToken.secret, this.cryptoImpl).claims;\r\n }\r\n\r\n return {\r\n account: cachedAccount,\r\n idToken: cachedIdToken,\r\n accessToken: cachedAccessToken,\r\n refreshToken: cachedRefreshToken,\r\n appMetadata: cachedAppMetadata,\r\n };\r\n }\r\n\r\n /**\r\n * Retrieve AccountEntity from cache\r\n * @param account\r\n */\r\n readAccountFromCache(account: AccountInfo): AccountEntity | null {\r\n const accountKey: string = AccountEntity.generateAccountCacheKey(account);\r\n return this.getAccount(accountKey);\r\n }\r\n\r\n /**\r\n * Retrieve IdTokenEntity from cache\r\n * @param clientId\r\n * @param account\r\n * @param inputRealm\r\n */\r\n getIdToken(account: AccountInfo, tokenKeys?: TokenKeys): IdTokenEntity | null {\r\n this.commonLogger.trace(\"CacheManager - getIdToken called\");\r\n const idTokenFilter: CredentialFilter = {\r\n homeAccountId: account.homeAccountId,\r\n environment: account.environment,\r\n credentialType: CredentialType.ID_TOKEN,\r\n clientId: this.clientId,\r\n realm: account.tenantId,\r\n };\r\n\r\n const idTokens: IdTokenEntity[] = this.getIdTokensByFilter(idTokenFilter, tokenKeys);\r\n const numIdTokens = idTokens.length;\r\n\r\n if (numIdTokens < 1) {\r\n this.commonLogger.info(\"CacheManager:getIdToken - No token found\");\r\n return null;\r\n } else if (numIdTokens > 1) {\r\n this.commonLogger.info(\r\n \"CacheManager:getIdToken - Multiple id tokens found, clearing them\"\r\n );\r\n idTokens.forEach((idToken) => {\r\n this.removeIdToken(idToken.generateCredentialKey());\r\n });\r\n return null;\r\n }\r\n\r\n this.commonLogger.info(\"CacheManager:getIdToken - Returning id token\");\r\n return idTokens[0];\r\n }\r\n\r\n /**\r\n * Gets all idTokens matching the given filter\r\n * @param filter \r\n * @returns \r\n */\r\n getIdTokensByFilter(filter: CredentialFilter, tokenKeys?: TokenKeys): IdTokenEntity[] {\r\n const idTokenKeys = tokenKeys && tokenKeys.idToken || this.getTokenKeys().idToken;\r\n\r\n const idTokens: IdTokenEntity[] = [];\r\n idTokenKeys.forEach((key) => {\r\n if (!this.idTokenKeyMatchesFilter(key, {clientId: this.clientId, ...filter})) {\r\n return;\r\n }\r\n\r\n const idToken = this.getIdTokenCredential(key);\r\n if (idToken && this.credentialMatchesFilter(idToken, filter)) {\r\n idTokens.push(idToken);\r\n }\r\n });\r\n\r\n return idTokens;\r\n }\r\n\r\n /**\r\n * Validate the cache key against filter before retrieving and parsing cache value\r\n * @param key \r\n * @param filter\r\n * @returns \r\n */\r\n idTokenKeyMatchesFilter(inputKey: string, filter: CredentialFilter): boolean {\r\n const key = inputKey.toLowerCase();\r\n if (filter.clientId && key.indexOf(filter.clientId.toLowerCase()) === -1) {\r\n return false;\r\n }\r\n\r\n if (filter.homeAccountId && key.indexOf(filter.homeAccountId.toLowerCase()) === -1) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Removes idToken from the cache\r\n * @param key \r\n */\r\n removeIdToken(key: string): void {\r\n this.removeItem(key);\r\n }\r\n\r\n /**\r\n * Removes refresh token from the cache\r\n * @param key \r\n */\r\n removeRefreshToken(key: string): void {\r\n this.removeItem(key);\r\n }\r\n\r\n /**\r\n * Retrieve AccessTokenEntity from cache\r\n * @param clientId\r\n * @param account\r\n * @param scopes\r\n * @param authScheme\r\n */\r\n getAccessToken(account: AccountInfo, request: BaseAuthRequest, tokenKeys?: TokenKeys): AccessTokenEntity | null {\r\n this.commonLogger.trace(\"CacheManager - getAccessToken called\");\r\n const scopes = ScopeSet.createSearchScopes(request.scopes);\r\n const authScheme = request.authenticationScheme || AuthenticationScheme.BEARER;\r\n /*\r\n * Distinguish between Bearer and PoP/SSH token cache types\r\n * Cast to lowercase to handle \"bearer\" from ADFS\r\n */\r\n const credentialType = (authScheme && authScheme.toLowerCase() !== AuthenticationScheme.BEARER.toLowerCase()) ? CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME : CredentialType.ACCESS_TOKEN;\r\n\r\n const accessTokenFilter: CredentialFilter = {\r\n homeAccountId: account.homeAccountId,\r\n environment: account.environment,\r\n credentialType: credentialType,\r\n clientId: this.clientId,\r\n realm: account.tenantId,\r\n target: scopes,\r\n tokenType: authScheme,\r\n keyId: request.sshKid,\r\n requestedClaimsHash: request.requestedClaimsHash,\r\n };\r\n\r\n const accessTokenKeys = tokenKeys && tokenKeys.accessToken || this.getTokenKeys().accessToken;\r\n const accessTokens: AccessTokenEntity[] = [];\r\n\r\n accessTokenKeys.forEach((key) => {\r\n // Validate key\r\n if (this.accessTokenKeyMatchesFilter(key, accessTokenFilter, true)) {\r\n const accessToken = this.getAccessTokenCredential(key);\r\n\r\n // Validate value\r\n if (accessToken && this.credentialMatchesFilter(accessToken, accessTokenFilter)) {\r\n accessTokens.push(accessToken);\r\n }\r\n }\r\n });\r\n\r\n const numAccessTokens = accessTokens.length;\r\n if (numAccessTokens < 1) {\r\n this.commonLogger.info(\"CacheManager:getAccessToken - No token found\");\r\n return null;\r\n } else if (numAccessTokens > 1) {\r\n this.commonLogger.info(\r\n \"CacheManager:getAccessToken - Multiple access tokens found, clearing them\"\r\n );\r\n accessTokens.forEach((accessToken) => {\r\n this.removeAccessToken(accessToken.generateCredentialKey());\r\n });\r\n return null;\r\n }\r\n\r\n this.commonLogger.info(\"CacheManager:getAccessToken - Returning access token\");\r\n return accessTokens[0];\r\n }\r\n\r\n /**\r\n * Validate the cache key against filter before retrieving and parsing cache value\r\n * @param key \r\n * @param filter \r\n * @param keyMustContainAllScopes \r\n * @returns \r\n */\r\n accessTokenKeyMatchesFilter(inputKey: string, filter: CredentialFilter, keyMustContainAllScopes: boolean): boolean {\r\n const key = inputKey.toLowerCase();\r\n if (filter.clientId && key.indexOf(filter.clientId.toLowerCase()) === -1) {\r\n return false;\r\n }\r\n\r\n if (filter.homeAccountId && key.indexOf(filter.homeAccountId.toLowerCase()) === -1) {\r\n return false;\r\n }\r\n\r\n if (filter.realm && key.indexOf(filter.realm.toLowerCase()) === -1) {\r\n return false;\r\n }\r\n\r\n if (filter.requestedClaimsHash && key.indexOf(filter.requestedClaimsHash.toLowerCase()) === -1) {\r\n return false;\r\n }\r\n\r\n if (filter.target) {\r\n const scopes = filter.target.asArray();\r\n for (let i = 0; i < scopes.length; i++) {\r\n if (keyMustContainAllScopes && !key.includes(scopes[i].toLowerCase())) {\r\n // When performing a cache lookup a missing scope would be a cache miss\r\n return false;\r\n } else if (!keyMustContainAllScopes && key.includes(scopes[i].toLowerCase())) {\r\n // When performing a cache write, any token with a subset of requested scopes should be replaced\r\n return true;\r\n }\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Gets all access tokens matching the filter\r\n * @param filter \r\n * @returns \r\n */\r\n getAccessTokensByFilter(filter: CredentialFilter): AccessTokenEntity[] {\r\n const tokenKeys = this.getTokenKeys();\r\n\r\n const accessTokens: AccessTokenEntity[] = [];\r\n tokenKeys.accessToken.forEach((key) => {\r\n if (!this.accessTokenKeyMatchesFilter(key, filter, true)) {\r\n return;\r\n }\r\n\r\n const accessToken = this.getAccessTokenCredential(key);\r\n if (accessToken && this.credentialMatchesFilter(accessToken, filter)) {\r\n accessTokens.push(accessToken);\r\n }\r\n });\r\n\r\n return accessTokens;\r\n }\r\n\r\n /**\r\n * Helper to retrieve the appropriate refresh token from cache\r\n * @param clientId\r\n * @param account\r\n * @param familyRT\r\n */\r\n getRefreshToken(account: AccountInfo, familyRT: boolean, tokenKeys?: TokenKeys): RefreshTokenEntity | null {\r\n this.commonLogger.trace(\"CacheManager - getRefreshToken called\");\r\n const id = familyRT ? THE_FAMILY_ID : undefined;\r\n const refreshTokenFilter: CredentialFilter = {\r\n homeAccountId: account.homeAccountId,\r\n environment: account.environment,\r\n credentialType: CredentialType.REFRESH_TOKEN,\r\n clientId: this.clientId,\r\n familyId: id,\r\n };\r\n\r\n const refreshTokenKeys = tokenKeys && tokenKeys.refreshToken || this.getTokenKeys().refreshToken;\r\n const refreshTokens: RefreshTokenEntity[] = [];\r\n\r\n refreshTokenKeys.forEach((key) => {\r\n // Validate key\r\n if (this.refreshTokenKeyMatchesFilter(key, refreshTokenFilter)) {\r\n const refreshToken = this.getRefreshTokenCredential(key);\r\n // Validate value\r\n if (refreshToken && this.credentialMatchesFilter(refreshToken, refreshTokenFilter)) {\r\n refreshTokens.push(refreshToken);\r\n }\r\n }\r\n });\r\n\r\n const numRefreshTokens = refreshTokens.length;\r\n if (numRefreshTokens < 1) {\r\n this.commonLogger.info(\"CacheManager:getRefreshToken - No refresh token found.\");\r\n return null;\r\n }\r\n // address the else case after remove functions address environment aliases\r\n\r\n this.commonLogger.info(\"CacheManager:getRefreshToken - returning refresh token\");\r\n return refreshTokens[0] as RefreshTokenEntity;\r\n }\r\n\r\n /**\r\n * Validate the cache key against filter before retrieving and parsing cache value\r\n * @param key\r\n * @param filter\r\n */\r\n refreshTokenKeyMatchesFilter(inputKey: string, filter: CredentialFilter): boolean {\r\n const key = inputKey.toLowerCase();\r\n if (filter.familyId && key.indexOf(filter.familyId.toLowerCase()) === -1) {\r\n return false;\r\n }\r\n\r\n // If familyId is used, clientId is not in the key\r\n if (!filter.familyId && filter.clientId && key.indexOf(filter.clientId.toLowerCase()) === -1) {\r\n return false;\r\n }\r\n\r\n if (filter.homeAccountId && key.indexOf(filter.homeAccountId.toLowerCase()) === -1) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Retrieve AppMetadataEntity from cache\r\n */\r\n readAppMetadataFromCache(environment: string): AppMetadataEntity | null {\r\n const appMetadataFilter: AppMetadataFilter = {\r\n environment,\r\n clientId: this.clientId,\r\n };\r\n\r\n const appMetadata: AppMetadataCache = this.getAppMetadataFilteredBy(appMetadataFilter);\r\n const appMetadataEntries: AppMetadataEntity[] = Object.keys(appMetadata).map((key) => appMetadata[key]);\r\n\r\n const numAppMetadata = appMetadataEntries.length;\r\n if (numAppMetadata < 1) {\r\n return null;\r\n } else if (numAppMetadata > 1) {\r\n throw ClientAuthError.createMultipleMatchingAppMetadataInCacheError();\r\n }\r\n\r\n return appMetadataEntries[0] as AppMetadataEntity;\r\n }\r\n\r\n /**\r\n * Return the family_id value associated with FOCI\r\n * @param environment\r\n * @param clientId\r\n */\r\n isAppMetadataFOCI(environment: string): boolean {\r\n const appMetadata = this.readAppMetadataFromCache(environment);\r\n return !!(appMetadata && appMetadata.familyId === THE_FAMILY_ID);\r\n }\r\n\r\n /**\r\n * helper to match account ids\r\n * @param value\r\n * @param homeAccountId\r\n */\r\n private matchHomeAccountId(entity: AccountEntity | CredentialEntity, homeAccountId: string): boolean {\r\n return !!((typeof entity.homeAccountId === \"string\") && (homeAccountId === entity.homeAccountId));\r\n }\r\n\r\n /**\r\n * helper to match account ids\r\n * @param entity \r\n * @param localAccountId \r\n * @returns \r\n */\r\n private matchLocalAccountId(entity: AccountEntity, localAccountId: string): boolean {\r\n return !!((typeof entity.localAccountId === \"string\") && (localAccountId === entity.localAccountId));\r\n }\r\n\r\n /**\r\n * helper to match usernames\r\n * @param entity \r\n * @param username \r\n * @returns \r\n */\r\n private matchUsername(entity: AccountEntity, username: string): boolean {\r\n return !!((typeof entity.username === \"string\") && (username.toLowerCase() === entity.username.toLowerCase()));\r\n }\r\n\r\n /**\r\n * helper to match assertion\r\n * @param value\r\n * @param oboAssertion\r\n */\r\n private matchUserAssertionHash(entity: CredentialEntity, userAssertionHash: string): boolean {\r\n return !!(entity.userAssertionHash && userAssertionHash === entity.userAssertionHash);\r\n }\r\n\r\n /**\r\n * helper to match environment\r\n * @param value\r\n * @param environment\r\n */\r\n private matchEnvironment(entity: AccountEntity | CredentialEntity | AppMetadataEntity, environment: string): boolean {\r\n const cloudMetadata = this.getAuthorityMetadataByAlias(environment);\r\n if (cloudMetadata && cloudMetadata.aliases.indexOf(entity.environment) > -1) {\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * helper to match credential type\r\n * @param entity\r\n * @param credentialType\r\n */\r\n private matchCredentialType(entity: CredentialEntity, credentialType: string): boolean {\r\n return (entity.credentialType && credentialType.toLowerCase() === entity.credentialType.toLowerCase());\r\n }\r\n\r\n /**\r\n * helper to match client ids\r\n * @param entity\r\n * @param clientId\r\n */\r\n private matchClientId(entity: CredentialEntity | AppMetadataEntity, clientId: string): boolean {\r\n return !!(entity.clientId && clientId === entity.clientId);\r\n }\r\n\r\n /**\r\n * helper to match family ids\r\n * @param entity\r\n * @param familyId\r\n */\r\n private matchFamilyId(entity: CredentialEntity | AppMetadataEntity, familyId: string): boolean {\r\n return !!(entity.familyId && familyId === entity.familyId);\r\n }\r\n\r\n /**\r\n * helper to match realm\r\n * @param entity\r\n * @param realm\r\n */\r\n private matchRealm(entity: AccountEntity | CredentialEntity, realm: string): boolean {\r\n return !!(entity.realm && realm === entity.realm);\r\n }\r\n\r\n /**\r\n * helper to match nativeAccountId\r\n * @param entity\r\n * @param nativeAccountId\r\n * @returns boolean indicating the match result\r\n */\r\n private matchNativeAccountId(entity: AccountEntity, nativeAccountId: string): boolean {\r\n return !!(entity.nativeAccountId && nativeAccountId === entity.nativeAccountId);\r\n }\r\n\r\n /**\r\n * Returns true if the target scopes are a subset of the current entity's scopes, false otherwise.\r\n * @param entity\r\n * @param target\r\n */\r\n private matchTarget(entity: CredentialEntity, target: ScopeSet): boolean {\r\n const isNotAccessTokenCredential = (entity.credentialType !== CredentialType.ACCESS_TOKEN && entity.credentialType !== CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME);\r\n\r\n if ( isNotAccessTokenCredential || !entity.target) {\r\n return false;\r\n }\r\n\r\n const entityScopeSet: ScopeSet = ScopeSet.fromString(entity.target);\r\n\r\n return entityScopeSet.containsScopeSet(target);\r\n }\r\n\r\n /**\r\n * Returns true if the credential's tokenType or Authentication Scheme matches the one in the request, false otherwise\r\n * @param entity\r\n * @param tokenType\r\n */\r\n private matchTokenType(entity: CredentialEntity, tokenType: AuthenticationScheme): boolean {\r\n return !!(entity.tokenType && entity.tokenType === tokenType);\r\n }\r\n\r\n /**\r\n * Returns true if the credential's keyId matches the one in the request, false otherwise\r\n * @param entity\r\n * @param tokenType\r\n */\r\n private matchKeyId(entity: CredentialEntity, keyId: string): boolean {\r\n return !!(entity.keyId && entity.keyId === keyId);\r\n }\r\n\r\n /**\r\n * returns if a given cache entity is of the type appmetadata\r\n * @param key\r\n */\r\n private isAppMetadata(key: string): boolean {\r\n return key.indexOf(APP_METADATA) !== -1;\r\n }\r\n\r\n /**\r\n * returns if a given cache entity is of the type authoritymetadata\r\n * @param key\r\n */\r\n protected isAuthorityMetadata(key: string): boolean {\r\n return key.indexOf(AUTHORITY_METADATA_CONSTANTS.CACHE_KEY) !== -1;\r\n }\r\n\r\n /**\r\n * returns cache key used for cloud instance metadata\r\n */\r\n generateAuthorityMetadataCacheKey(authority: string): string {\r\n return `${AUTHORITY_METADATA_CONSTANTS.CACHE_KEY}-${this.clientId}-${authority}`;\r\n }\r\n\r\n /**\r\n * Helper to convert serialized data to object\r\n * @param obj\r\n * @param json\r\n */\r\n static toObject(obj: T, json: object): T {\r\n for (const propertyName in json) {\r\n obj[propertyName] = json[propertyName];\r\n }\r\n return obj;\r\n }\r\n}\r\n\r\nexport class DefaultStorageClass extends CacheManager {\r\n setAccount(): void {\r\n const notImplErr = \"Storage interface - setAccount() has not been implemented for the cacheStorage interface.\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n }\r\n getAccount(): AccountEntity {\r\n const notImplErr = \"Storage interface - getAccount() has not been implemented for the cacheStorage interface.\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n }\r\n setIdTokenCredential(): void {\r\n const notImplErr = \"Storage interface - setIdTokenCredential() has not been implemented for the cacheStorage interface.\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n }\r\n getIdTokenCredential(): IdTokenEntity {\r\n const notImplErr = \"Storage interface - getIdTokenCredential() has not been implemented for the cacheStorage interface.\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n }\r\n setAccessTokenCredential(): void {\r\n const notImplErr = \"Storage interface - setAccessTokenCredential() has not been implemented for the cacheStorage interface.\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n }\r\n getAccessTokenCredential(): AccessTokenEntity {\r\n const notImplErr = \"Storage interface - getAccessTokenCredential() has not been implemented for the cacheStorage interface.\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n }\r\n setRefreshTokenCredential(): void {\r\n const notImplErr = \"Storage interface - setRefreshTokenCredential() has not been implemented for the cacheStorage interface.\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n }\r\n getRefreshTokenCredential(): RefreshTokenEntity {\r\n const notImplErr = \"Storage interface - getRefreshTokenCredential() has not been implemented for the cacheStorage interface.\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n }\r\n setAppMetadata(): void {\r\n const notImplErr = \"Storage interface - setAppMetadata() has not been implemented for the cacheStorage interface.\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n }\r\n getAppMetadata(): AppMetadataEntity {\r\n const notImplErr = \"Storage interface - getAppMetadata() has not been implemented for the cacheStorage interface.\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n }\r\n setServerTelemetry(): void {\r\n const notImplErr = \"Storage interface - setServerTelemetry() has not been implemented for the cacheStorage interface.\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n }\r\n getServerTelemetry(): ServerTelemetryEntity {\r\n const notImplErr = \"Storage interface - getServerTelemetry() has not been implemented for the cacheStorage interface.\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n }\r\n setAuthorityMetadata(): void {\r\n const notImplErr = \"Storage interface - setAuthorityMetadata() has not been implemented for the cacheStorage interface.\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n }\r\n getAuthorityMetadata(): AuthorityMetadataEntity | null {\r\n const notImplErr = \"Storage interface - getAuthorityMetadata() has not been implemented for the cacheStorage interface.\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n }\r\n getAuthorityMetadataKeys(): Array {\r\n const notImplErr = \"Storage interface - getAuthorityMetadataKeys() has not been implemented for the cacheStorage interface.\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n }\r\n setThrottlingCache(): void {\r\n const notImplErr = \"Storage interface - setThrottlingCache() has not been implemented for the cacheStorage interface.\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n }\r\n getThrottlingCache(): ThrottlingEntity {\r\n const notImplErr = \"Storage interface - getThrottlingCache() has not been implemented for the cacheStorage interface.\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n }\r\n removeItem(): boolean {\r\n const notImplErr = \"Storage interface - removeItem() has not been implemented for the cacheStorage interface.\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n }\r\n containsKey(): boolean {\r\n const notImplErr = \"Storage interface - containsKey() has not been implemented for the cacheStorage interface.\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n }\r\n getKeys(): string[] {\r\n const notImplErr = \"Storage interface - getKeys() has not been implemented for the cacheStorage interface.\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n }\r\n getAccountKeys(): string[] {\r\n const notImplErr = \"Storage interface - getAccountKeys() has not been implemented for the cacheStorage interface.\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n }\r\n getTokenKeys(): TokenKeys {\r\n const notImplErr = \"Storage interface - getTokenKeys() has not been implemented for the cacheStorage interface.\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n }\r\n async clear(): Promise {\r\n const notImplErr = \"Storage interface - clear() has not been implemented for the cacheStorage interface.\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n }\r\n updateCredentialCacheKey(): string {\r\n const notImplErr = \"Storage interface - updateCredentialCacheKey() has not been implemented for the cacheStorage interface.\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\n/**\r\n * Utility class which exposes functions for managing date and time operations.\r\n */\r\nexport class TimeUtils {\r\n\r\n /**\r\n * return the current time in Unix time (seconds).\r\n */\r\n static nowSeconds(): number {\r\n // Date.getTime() returns in milliseconds.\r\n return Math.round(new Date().getTime() / 1000.0);\r\n }\r\n \r\n /**\r\n * check if a token is expired based on given UTC time in seconds.\r\n * @param expiresOn\r\n */\r\n static isTokenExpired(expiresOn: string, offset: number): boolean {\r\n // check for access token expiry\r\n const expirationSec = Number(expiresOn) || 0;\r\n const offsetCurrentTimeSec = TimeUtils.nowSeconds() + offset;\r\n\r\n // If current time + offset is greater than token expiration time, then token is expired.\r\n return (offsetCurrentTimeSec > expirationSec);\r\n }\r\n\r\n /**\r\n * If the current time is earlier than the time that a token was cached at, we must discard the token\r\n * i.e. The system clock was turned back after acquiring the cached token\r\n * @param cachedAt \r\n * @param offset \r\n */\r\n static wasClockTurnedBack(cachedAt: string): boolean {\r\n const cachedAtSec = Number(cachedAt);\r\n\r\n return cachedAtSec > TimeUtils.nowSeconds();\r\n }\r\n\r\n /**\r\n * Waits for t number of milliseconds\r\n * @param t number\r\n * @param value T\r\n */\r\n static delay(t: number, value?: T): Promise {\r\n return new Promise((resolve) => setTimeout(() => resolve(value), t));\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { CredentialEntity } from \"./CredentialEntity\";\r\nimport { CredentialType, AuthenticationScheme } from \"../../utils/Constants\";\r\nimport { TimeUtils } from \"../../utils/TimeUtils\";\r\nimport { StringUtils } from \"../../utils/StringUtils\";\r\nimport { ICrypto } from \"../../crypto/ICrypto\";\r\nimport { TokenClaims } from \"../../account/TokenClaims\";\r\nimport { AuthToken } from \"../../account/AuthToken\";\r\nimport { ClientAuthError } from \"../../error/ClientAuthError\";\r\n\r\n/**\r\n * ACCESS_TOKEN Credential Type\r\n *\r\n * Key:Value Schema:\r\n *\r\n * Key Example: uid.utid-login.microsoftonline.com-accesstoken-clientId-contoso.com-user.read\r\n *\r\n * Value Schema:\r\n * {\r\n * homeAccountId: home account identifier for the auth scheme,\r\n * environment: entity that issued the token, represented as a full host\r\n * credentialType: Type of credential as a string, can be one of the following: RefreshToken, AccessToken, IdToken, Password, Cookie, Certificate, Other\r\n * clientId: client ID of the application\r\n * secret: Actual credential as a string\r\n * familyId: Family ID identifier, usually only used for refresh tokens\r\n * realm: Full tenant or organizational identifier that the account belongs to\r\n * target: Permissions that are included in the token, or for refresh tokens, the resource identifier.\r\n * cachedAt: Absolute device time when entry was created in the cache.\r\n * expiresOn: Token expiry time, calculated based on current UTC time in seconds. Represented as a string.\r\n * extendedExpiresOn: Additional extended expiry time until when token is valid in case of server-side outage. Represented as string in UTC seconds.\r\n * keyId: used for POP and SSH tokenTypes\r\n * tokenType: Type of the token issued. Usually \"Bearer\"\r\n * }\r\n */\r\nexport class AccessTokenEntity extends CredentialEntity {\r\n realm: string;\r\n target: string;\r\n cachedAt: string;\r\n expiresOn: string;\r\n extendedExpiresOn?: string;\r\n refreshOn?: string;\r\n keyId?: string; // for POP and SSH tokenTypes\r\n tokenType?: AuthenticationScheme;\r\n requestedClaims?: string;\r\n requestedClaimsHash?: string;\r\n\r\n /**\r\n * Create AccessTokenEntity\r\n * @param homeAccountId\r\n * @param environment\r\n * @param accessToken\r\n * @param clientId\r\n * @param tenantId\r\n * @param scopes\r\n * @param expiresOn\r\n * @param extExpiresOn\r\n */\r\n static createAccessTokenEntity(\r\n homeAccountId: string,\r\n environment: string,\r\n accessToken: string,\r\n clientId: string,\r\n tenantId: string,\r\n scopes: string,\r\n expiresOn: number,\r\n extExpiresOn: number,\r\n cryptoUtils: ICrypto,\r\n refreshOn?: number,\r\n tokenType?: AuthenticationScheme,\r\n userAssertionHash?:string,\r\n keyId?: string,\r\n requestedClaims?: string,\r\n requestedClaimsHash?: string\r\n ): AccessTokenEntity {\r\n const atEntity: AccessTokenEntity = new AccessTokenEntity();\r\n\r\n atEntity.homeAccountId = homeAccountId;\r\n atEntity.credentialType = CredentialType.ACCESS_TOKEN;\r\n atEntity.secret = accessToken;\r\n\r\n const currentTime = TimeUtils.nowSeconds();\r\n atEntity.cachedAt = currentTime.toString();\r\n\r\n /*\r\n * Token expiry time.\r\n * This value should be calculated based on the current UTC time measured locally and the value expires_in Represented as a string in JSON.\r\n */\r\n atEntity.expiresOn = expiresOn.toString();\r\n atEntity.extendedExpiresOn = extExpiresOn.toString();\r\n if (refreshOn) {\r\n atEntity.refreshOn = refreshOn.toString();\r\n }\r\n\r\n atEntity.environment = environment;\r\n atEntity.clientId = clientId;\r\n atEntity.realm = tenantId;\r\n atEntity.target = scopes;\r\n atEntity.userAssertionHash = userAssertionHash;\r\n\r\n atEntity.tokenType = StringUtils.isEmpty(tokenType) ? AuthenticationScheme.BEARER : tokenType;\r\n\r\n if (requestedClaims) {\r\n atEntity.requestedClaims = requestedClaims;\r\n atEntity.requestedClaimsHash = requestedClaimsHash;\r\n }\r\n\r\n /*\r\n * Create Access Token With Auth Scheme instead of regular access token\r\n * Cast to lower to handle \"bearer\" from ADFS\r\n */\r\n if (atEntity.tokenType?.toLowerCase() !== AuthenticationScheme.BEARER.toLowerCase()) {\r\n atEntity.credentialType = CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME;\r\n switch (atEntity.tokenType) {\r\n case AuthenticationScheme.POP:\r\n // Make sure keyId is present and add it to credential\r\n const tokenClaims: TokenClaims | null = AuthToken.extractTokenClaims(accessToken, cryptoUtils);\r\n if (!tokenClaims?.cnf?.kid) {\r\n throw ClientAuthError.createTokenClaimsRequiredError();\r\n }\r\n atEntity.keyId = tokenClaims.cnf.kid;\r\n break;\r\n case AuthenticationScheme.SSH:\r\n atEntity.keyId = keyId;\r\n }\r\n }\r\n\r\n return atEntity;\r\n }\r\n\r\n /**\r\n * Validates an entity: checks for all expected params\r\n * @param entity\r\n */\r\n static isAccessTokenEntity(entity: object): boolean {\r\n\r\n if (!entity) {\r\n return false;\r\n }\r\n\r\n return (\r\n entity.hasOwnProperty(\"homeAccountId\") &&\r\n entity.hasOwnProperty(\"environment\") &&\r\n entity.hasOwnProperty(\"credentialType\") &&\r\n entity.hasOwnProperty(\"realm\") &&\r\n entity.hasOwnProperty(\"clientId\") &&\r\n entity.hasOwnProperty(\"secret\") &&\r\n entity.hasOwnProperty(\"target\") &&\r\n (entity[\"credentialType\"] === CredentialType.ACCESS_TOKEN || entity[\"credentialType\"] === CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME)\r\n );\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { CredentialEntity } from \"./CredentialEntity\";\r\nimport { CredentialType } from \"../../utils/Constants\";\r\n\r\n/**\r\n * REFRESH_TOKEN Cache\r\n *\r\n * Key:Value Schema:\r\n *\r\n * Key Example: uid.utid-login.microsoftonline.com-refreshtoken-clientId--\r\n *\r\n * Value:\r\n * {\r\n * homeAccountId: home account identifier for the auth scheme,\r\n * environment: entity that issued the token, represented as a full host\r\n * credentialType: Type of credential as a string, can be one of the following: RefreshToken, AccessToken, IdToken, Password, Cookie, Certificate, Other\r\n * clientId: client ID of the application\r\n * secret: Actual credential as a string\r\n * familyId: Family ID identifier, '1' represents Microsoft Family\r\n * realm: Full tenant or organizational identifier that the account belongs to\r\n * target: Permissions that are included in the token, or for refresh tokens, the resource identifier.\r\n * }\r\n */\r\nexport class RefreshTokenEntity extends CredentialEntity {\r\n familyId?: string;\r\n\r\n /**\r\n * Create RefreshTokenEntity\r\n * @param homeAccountId\r\n * @param authenticationResult\r\n * @param clientId\r\n * @param authority\r\n */\r\n static createRefreshTokenEntity(\r\n homeAccountId: string,\r\n environment: string,\r\n refreshToken: string,\r\n clientId: string,\r\n familyId?: string,\r\n userAssertionHash?: string\r\n ): RefreshTokenEntity {\r\n const rtEntity = new RefreshTokenEntity();\r\n\r\n rtEntity.clientId = clientId;\r\n rtEntity.credentialType = CredentialType.REFRESH_TOKEN;\r\n rtEntity.environment = environment;\r\n rtEntity.homeAccountId = homeAccountId;\r\n rtEntity.secret = refreshToken;\r\n rtEntity.userAssertionHash = userAssertionHash;\r\n\r\n if (familyId)\r\n rtEntity.familyId = familyId;\r\n\r\n return rtEntity;\r\n }\r\n\r\n /**\r\n * Validates an entity: checks for all expected params\r\n * @param entity\r\n */\r\n static isRefreshTokenEntity(entity: object): boolean {\r\n\r\n if (!entity) {\r\n return false;\r\n }\r\n\r\n return (\r\n entity.hasOwnProperty(\"homeAccountId\") &&\r\n entity.hasOwnProperty(\"environment\") &&\r\n entity.hasOwnProperty(\"credentialType\") &&\r\n entity.hasOwnProperty(\"clientId\") &&\r\n entity.hasOwnProperty(\"secret\") &&\r\n entity[\"credentialType\"] === CredentialType.REFRESH_TOKEN\r\n );\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { APP_METADATA, Separators } from \"../../utils/Constants\";\r\n\r\n/**\r\n * APP_METADATA Cache\r\n *\r\n * Key:Value Schema:\r\n *\r\n * Key: appmetadata--\r\n *\r\n * Value:\r\n * {\r\n * clientId: client ID of the application\r\n * environment: entity that issued the token, represented as a full host\r\n * familyId: Family ID identifier, '1' represents Microsoft Family\r\n * }\r\n */\r\nexport class AppMetadataEntity {\r\n clientId: string;\r\n environment: string;\r\n familyId?: string;\r\n\r\n /**\r\n * Generate AppMetadata Cache Key as per the schema: appmetadata--\r\n */\r\n generateAppMetadataKey(): string {\r\n return AppMetadataEntity.generateAppMetadataCacheKey(this.environment, this.clientId);\r\n }\r\n\r\n /**\r\n * Generate AppMetadata Cache Key\r\n */\r\n static generateAppMetadataCacheKey(environment: string, clientId: string): string {\r\n const appMetaDataKeyArray: Array = [\r\n APP_METADATA,\r\n environment,\r\n clientId,\r\n ];\r\n return appMetaDataKeyArray.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();\r\n }\r\n\r\n /**\r\n * Creates AppMetadataEntity\r\n * @param clientId\r\n * @param environment\r\n * @param familyId\r\n */\r\n static createAppMetadataEntity(clientId: string, environment: string, familyId?: string): AppMetadataEntity {\r\n const appMetadata = new AppMetadataEntity();\r\n\r\n appMetadata.clientId = clientId;\r\n appMetadata.environment = environment;\r\n if (familyId) {\r\n appMetadata.familyId = familyId;\r\n }\r\n\r\n return appMetadata;\r\n }\r\n\r\n /**\r\n * Validates an entity: checks for all expected params\r\n * @param entity\r\n */\r\n static isAppMetadataEntity(key: string, entity: object): boolean {\r\n\r\n if (!entity) {\r\n return false;\r\n }\r\n\r\n return (\r\n key.indexOf(APP_METADATA) === 0 &&\r\n entity.hasOwnProperty(\"clientId\") &&\r\n entity.hasOwnProperty(\"environment\")\r\n );\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { SERVER_TELEM_CONSTANTS } from \"../../utils/Constants\";\r\n\r\nexport class ServerTelemetryEntity {\r\n failedRequests: Array;\r\n errors: string[];\r\n cacheHits: number;\r\n\r\n constructor() {\r\n this.failedRequests = [];\r\n this.errors = [];\r\n this.cacheHits = 0;\r\n }\r\n\r\n /**\r\n * validates if a given cache entry is \"Telemetry\", parses \r\n * @param key\r\n * @param entity\r\n */\r\n static isServerTelemetryEntity(key: string, entity?: object): boolean {\r\n\r\n const validateKey: boolean = key.indexOf(SERVER_TELEM_CONSTANTS.CACHE_KEY) === 0;\r\n let validateEntity: boolean = true;\r\n\r\n if (entity) {\r\n validateEntity =\r\n entity.hasOwnProperty(\"failedRequests\") &&\r\n entity.hasOwnProperty(\"errors\") &&\r\n entity.hasOwnProperty(\"cacheHits\");\r\n }\r\n\r\n return validateKey && validateEntity;\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { CloudDiscoveryMetadata } from \"../../authority/CloudDiscoveryMetadata\";\r\nimport { OpenIdConfigResponse } from \"../../authority/OpenIdConfigResponse\";\r\nimport { AUTHORITY_METADATA_CONSTANTS } from \"../../utils/Constants\";\r\nimport { TimeUtils } from \"../../utils/TimeUtils\";\r\n\r\nexport class AuthorityMetadataEntity {\r\n aliases: Array;\r\n preferred_cache: string;\r\n preferred_network: string;\r\n canonical_authority: string;\r\n authorization_endpoint: string;\r\n token_endpoint: string;\r\n end_session_endpoint?: string;\r\n issuer: string;\r\n aliasesFromNetwork: boolean;\r\n endpointsFromNetwork: boolean;\r\n expiresAt: number;\r\n jwks_uri: string;\r\n\r\n constructor() {\r\n this.expiresAt = TimeUtils.nowSeconds() + AUTHORITY_METADATA_CONSTANTS.REFRESH_TIME_SECONDS;\r\n }\r\n\r\n /**\r\n * Update the entity with new aliases, preferred_cache and preferred_network values\r\n * @param metadata \r\n * @param fromNetwork \r\n */\r\n updateCloudDiscoveryMetadata(metadata: CloudDiscoveryMetadata, fromNetwork: boolean): void {\r\n this.aliases = metadata.aliases;\r\n this.preferred_cache = metadata.preferred_cache;\r\n this.preferred_network = metadata.preferred_network;\r\n this.aliasesFromNetwork = fromNetwork;\r\n }\r\n\r\n /**\r\n * Update the entity with new endpoints\r\n * @param metadata \r\n * @param fromNetwork \r\n */\r\n updateEndpointMetadata(metadata: OpenIdConfigResponse, fromNetwork: boolean): void {\r\n this.authorization_endpoint = metadata.authorization_endpoint;\r\n this.token_endpoint = metadata.token_endpoint;\r\n this.end_session_endpoint = metadata.end_session_endpoint;\r\n this.issuer = metadata.issuer;\r\n this.endpointsFromNetwork = fromNetwork;\r\n this.jwks_uri = metadata.jwks_uri;\r\n }\r\n\r\n /**\r\n * Save the authority that was used to create this cache entry\r\n * @param authority \r\n */\r\n updateCanonicalAuthority(authority: string): void {\r\n this.canonical_authority = authority;\r\n }\r\n\r\n /**\r\n * Reset the exiresAt value\r\n */\r\n resetExpiresAt(): void {\r\n this.expiresAt = TimeUtils.nowSeconds() + AUTHORITY_METADATA_CONSTANTS.REFRESH_TIME_SECONDS;\r\n }\r\n\r\n /**\r\n * Returns whether or not the data needs to be refreshed\r\n */\r\n isExpired(): boolean {\r\n return this.expiresAt <= TimeUtils.nowSeconds();\r\n }\r\n\r\n /**\r\n * Validates an entity: checks for all expected params\r\n * @param entity\r\n */\r\n static isAuthorityMetadataEntity(key: string, entity: object): boolean {\r\n\r\n if (!entity) {\r\n return false;\r\n }\r\n\r\n return (\r\n key.indexOf(AUTHORITY_METADATA_CONSTANTS.CACHE_KEY) === 0 &&\r\n entity.hasOwnProperty(\"aliases\") &&\r\n entity.hasOwnProperty(\"preferred_cache\") &&\r\n entity.hasOwnProperty(\"preferred_network\") &&\r\n entity.hasOwnProperty(\"canonical_authority\") &&\r\n entity.hasOwnProperty(\"authorization_endpoint\") &&\r\n entity.hasOwnProperty(\"token_endpoint\") &&\r\n entity.hasOwnProperty(\"issuer\") &&\r\n entity.hasOwnProperty(\"aliasesFromNetwork\") &&\r\n entity.hasOwnProperty(\"endpointsFromNetwork\") &&\r\n entity.hasOwnProperty(\"expiresAt\") &&\r\n entity.hasOwnProperty(\"jwks_uri\")\r\n );\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { ThrottlingConstants } from \"../../utils/Constants\";\r\n\r\nexport class ThrottlingEntity {\r\n // Unix-time value representing the expiration of the throttle\r\n throttleTime: number;\r\n // Information provided by the server\r\n error?: string;\r\n errorCodes?: Array;\r\n errorMessage?: string;\r\n subError?: string;\r\n\r\n /**\r\n * validates if a given cache entry is \"Throttling\", parses \r\n * @param key\r\n * @param entity\r\n */\r\n static isThrottlingEntity(key: string, entity?: object): boolean {\r\n \r\n let validateKey: boolean = false;\r\n if (key) {\r\n validateKey = key.indexOf(ThrottlingConstants.THROTTLING_PREFIX) === 0;\r\n }\r\n \r\n let validateEntity: boolean = true;\r\n if (entity) {\r\n validateEntity = entity.hasOwnProperty(\"throttleTime\");\r\n }\r\n\r\n return validateKey && validateEntity;\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { StringUtils } from \"./StringUtils\";\r\nimport { Constants } from \"./Constants\";\r\nimport { ICrypto } from \"../crypto/ICrypto\";\r\nimport { ClientAuthError } from \"../error/ClientAuthError\";\r\n\r\n/**\r\n * Type which defines the object that is stringified, encoded and sent in the state value.\r\n * Contains the following:\r\n * - id - unique identifier for this request\r\n * - ts - timestamp for the time the request was made. Used to ensure that token expiration is not calculated incorrectly.\r\n * - platformState - string value sent from the platform.\r\n */\r\nexport type LibraryStateObject = {\r\n id: string,\r\n meta?: Record\r\n};\r\n\r\n/**\r\n * Type which defines the stringified and encoded object sent to the service in the authorize request.\r\n */\r\nexport type RequestStateObject = {\r\n userRequestState: string,\r\n libraryState: LibraryStateObject\r\n};\r\n\r\n/**\r\n * Class which provides helpers for OAuth 2.0 protocol specific values\r\n */\r\nexport class ProtocolUtils {\r\n\r\n /**\r\n * Appends user state with random guid, or returns random guid.\r\n * @param userState \r\n * @param randomGuid \r\n */\r\n static setRequestState(cryptoObj: ICrypto, userState?: string, meta?: Record): string {\r\n const libraryState = ProtocolUtils.generateLibraryState(cryptoObj, meta);\r\n return !StringUtils.isEmpty(userState) ? `${libraryState}${Constants.RESOURCE_DELIM}${userState}` : libraryState;\r\n }\r\n\r\n /**\r\n * Generates the state value used by the common library.\r\n * @param randomGuid \r\n * @param cryptoObj \r\n */\r\n static generateLibraryState(cryptoObj: ICrypto, meta?: Record): string {\r\n if (!cryptoObj) {\r\n throw ClientAuthError.createNoCryptoObjectError(\"generateLibraryState\");\r\n }\r\n\r\n // Create a state object containing a unique id and the timestamp of the request creation\r\n const stateObj: LibraryStateObject = {\r\n id: cryptoObj.createNewGuid()\r\n };\r\n\r\n if (meta) {\r\n stateObj.meta = meta;\r\n }\r\n\r\n const stateString = JSON.stringify(stateObj);\r\n\r\n return cryptoObj.base64Encode(stateString);\r\n }\r\n\r\n /**\r\n * Parses the state into the RequestStateObject, which contains the LibraryState info and the state passed by the user.\r\n * @param state \r\n * @param cryptoObj \r\n */\r\n static parseRequestState(cryptoObj: ICrypto, state: string): RequestStateObject {\r\n if (!cryptoObj) {\r\n throw ClientAuthError.createNoCryptoObjectError(\"parseRequestState\");\r\n }\r\n\r\n if (StringUtils.isEmpty(state)) {\r\n throw ClientAuthError.createInvalidStateError(state, \"Null, undefined or empty state\");\r\n }\r\n\r\n try {\r\n // Split the state between library state and user passed state and decode them separately\r\n const splitState = state.split(Constants.RESOURCE_DELIM);\r\n const libraryState = splitState[0];\r\n const userState = splitState.length > 1 ? splitState.slice(1).join(Constants.RESOURCE_DELIM) : Constants.EMPTY_STRING;\r\n const libraryStateString = cryptoObj.base64Decode(libraryState);\r\n const libraryStateObj = JSON.parse(libraryStateString) as LibraryStateObject;\r\n return {\r\n userRequestState: !StringUtils.isEmpty(userState) ? userState : Constants.EMPTY_STRING,\r\n libraryState: libraryStateObj\r\n };\r\n } catch(e) {\r\n throw ClientAuthError.createInvalidStateError(state, e);\r\n }\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { IdTokenEntity } from \"./IdTokenEntity\";\r\nimport { AccessTokenEntity } from \"./AccessTokenEntity\";\r\nimport { RefreshTokenEntity } from \"./RefreshTokenEntity\";\r\nimport { AccountEntity } from \"./AccountEntity\";\r\nimport { AppMetadataEntity } from \"./AppMetadataEntity\";\r\n\r\nexport class CacheRecord {\r\n account: AccountEntity | null;\r\n idToken: IdTokenEntity | null;\r\n accessToken: AccessTokenEntity | null;\r\n refreshToken: RefreshTokenEntity | null;\r\n appMetadata: AppMetadataEntity | null;\r\n\r\n constructor(accountEntity?: AccountEntity | null, idTokenEntity?: IdTokenEntity | null, accessTokenEntity?: AccessTokenEntity | null, refreshTokenEntity?: RefreshTokenEntity | null, appMetadataEntity?: AppMetadataEntity | null) {\r\n this.account = accountEntity || null;\r\n this.idToken = idTokenEntity || null;\r\n this.accessToken = accessTokenEntity || null;\r\n this.refreshToken = refreshTokenEntity || null;\r\n this.appMetadata = appMetadataEntity || null;\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { ProtocolMode } from \"./ProtocolMode\";\r\nimport { AzureRegionConfiguration } from \"./AzureRegionConfiguration\";\r\n\r\nexport type AuthorityOptions = {\r\n protocolMode: ProtocolMode;\r\n knownAuthorities: Array;\r\n cloudDiscoveryMetadata: string;\r\n authorityMetadata: string;\r\n skipAuthorityMetadataCache?: boolean;\r\n azureRegionConfiguration?: AzureRegionConfiguration;\r\n};\r\n\r\nexport enum AzureCloudInstance {\r\n // AzureCloudInstance is not specified.\r\n None,\r\n\r\n // Microsoft Azure public cloud\r\n AzurePublic = \"https://login.microsoftonline.com\",\r\n\r\n // Microsoft PPE\r\n AzurePpe = \"https://login.windows-ppe.net\",\r\n\r\n // Microsoft Chinese national cloud\r\n AzureChina = \"https://login.chinacloudapi.cn\",\r\n\r\n // Microsoft German national cloud (\"Black Forest\")\r\n AzureGermany = \"https://login.microsoftonline.de\",\r\n\r\n // US Government cloud\r\n AzureUsGovernment = \"https://login.microsoftonline.us\",\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { BrowserConfigurationAuthError } from \"../error/BrowserConfigurationAuthError\";\r\nimport { BrowserCacheLocation } from \"../utils/BrowserConstants\";\r\nimport { IWindowStorage } from \"./IWindowStorage\";\r\n\r\nexport class BrowserStorage implements IWindowStorage {\r\n\r\n private windowStorage: Storage;\r\n\r\n constructor(cacheLocation: string) {\r\n this.validateWindowStorage(cacheLocation);\r\n this.windowStorage = window[cacheLocation];\r\n }\r\n\r\n private validateWindowStorage(cacheLocation: string): void {\r\n if (cacheLocation !== BrowserCacheLocation.LocalStorage && cacheLocation !== BrowserCacheLocation.SessionStorage) {\r\n throw BrowserConfigurationAuthError.createStorageNotSupportedError(cacheLocation);\r\n }\r\n const storageSupported = !!window[cacheLocation];\r\n if (!storageSupported) {\r\n throw BrowserConfigurationAuthError.createStorageNotSupportedError(cacheLocation);\r\n }\r\n }\r\n\r\n getItem(key: string): string | null {\r\n return this.windowStorage.getItem(key);\r\n }\r\n\r\n setItem(key: string, value: string): void {\r\n this.windowStorage.setItem(key, value);\r\n }\r\n\r\n removeItem(key: string): void {\r\n this.windowStorage.removeItem(key);\r\n }\r\n\r\n getKeys(): string[] {\r\n return Object.keys(this.windowStorage);\r\n }\r\n\r\n containsKey(key: string): boolean {\r\n return this.windowStorage.hasOwnProperty(key);\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { ServerAuthorizationCodeResponse } from \"../response/ServerAuthorizationCodeResponse\";\r\nimport { ClientConfigurationError } from \"../error/ClientConfigurationError\";\r\nimport { ClientAuthError } from \"../error/ClientAuthError\";\r\nimport { StringUtils } from \"../utils/StringUtils\";\r\nimport { IUri } from \"./IUri\";\r\nimport { AADAuthorityConstants, Constants } from \"../utils/Constants\";\r\n\r\n/**\r\n * Url object class which can perform various transformations on url strings.\r\n */\r\nexport class UrlString {\r\n\r\n // internal url string field\r\n private _urlString: string;\r\n public get urlString(): string {\r\n return this._urlString;\r\n }\r\n\r\n constructor(url: string) {\r\n this._urlString = url;\r\n if (StringUtils.isEmpty(this._urlString)) {\r\n // Throws error if url is empty\r\n throw ClientConfigurationError.createUrlEmptyError();\r\n }\r\n\r\n if (StringUtils.isEmpty(this.getHash())) {\r\n this._urlString = UrlString.canonicalizeUri(url);\r\n }\r\n }\r\n\r\n /**\r\n * Ensure urls are lower case and end with a / character.\r\n * @param url\r\n */\r\n static canonicalizeUri(url: string): string {\r\n if (url) {\r\n let lowerCaseUrl = url.toLowerCase();\r\n\r\n if (StringUtils.endsWith(lowerCaseUrl, \"?\")) {\r\n lowerCaseUrl = lowerCaseUrl.slice(0, -1);\r\n } else if (StringUtils.endsWith(lowerCaseUrl, \"?/\")) {\r\n lowerCaseUrl = lowerCaseUrl.slice(0, -2);\r\n }\r\n\r\n if (!StringUtils.endsWith(lowerCaseUrl, \"/\")) {\r\n lowerCaseUrl += \"/\";\r\n }\r\n\r\n return lowerCaseUrl;\r\n }\r\n\r\n return url;\r\n }\r\n\r\n /**\r\n * Throws if urlString passed is not a valid authority URI string.\r\n */\r\n validateAsUri(): void {\r\n // Attempts to parse url for uri components\r\n let components;\r\n try {\r\n components = this.getUrlComponents();\r\n } catch (e) {\r\n throw ClientConfigurationError.createUrlParseError(e);\r\n }\r\n\r\n // Throw error if URI or path segments are not parseable.\r\n if (!components.HostNameAndPort || !components.PathSegments) {\r\n throw ClientConfigurationError.createUrlParseError(`Given url string: ${this.urlString}`);\r\n }\r\n\r\n // Throw error if uri is insecure.\r\n if(!components.Protocol || components.Protocol.toLowerCase() !== \"https:\") {\r\n throw ClientConfigurationError.createInsecureAuthorityUriError(this.urlString);\r\n }\r\n }\r\n\r\n /**\r\n * Given a url and a query string return the url with provided query string appended\r\n * @param url\r\n * @param queryString\r\n */\r\n static appendQueryString(url: string, queryString: string): string {\r\n if (StringUtils.isEmpty(queryString)) {\r\n return url;\r\n }\r\n\r\n return url.indexOf(\"?\") < 0 ? `${url}?${queryString}` : `${url}&${queryString}`;\r\n }\r\n\r\n /**\r\n * Returns a url with the hash removed\r\n * @param url\r\n */\r\n static removeHashFromUrl(url: string): string {\r\n return UrlString.canonicalizeUri(url.split(\"#\")[0]);\r\n }\r\n\r\n /**\r\n * Given a url like https://a:b/common/d?e=f#g, and a tenantId, returns https://a:b/tenantId/d\r\n * @param href The url\r\n * @param tenantId The tenant id to replace\r\n */\r\n replaceTenantPath(tenantId: string): UrlString {\r\n const urlObject = this.getUrlComponents();\r\n const pathArray = urlObject.PathSegments;\r\n if (tenantId && (pathArray.length !== 0 && (pathArray[0] === AADAuthorityConstants.COMMON || pathArray[0] === AADAuthorityConstants.ORGANIZATIONS))) {\r\n pathArray[0] = tenantId;\r\n }\r\n return UrlString.constructAuthorityUriFromObject(urlObject);\r\n }\r\n\r\n /**\r\n * Returns the anchor part(#) of the URL\r\n */\r\n getHash(): string {\r\n return UrlString.parseHash(this.urlString);\r\n }\r\n\r\n /**\r\n * Parses out the components from a url string.\r\n * @returns An object with the various components. Please cache this value insted of calling this multiple times on the same url.\r\n */\r\n getUrlComponents(): IUri {\r\n // https://gist.github.com/curtisz/11139b2cfcaef4a261e0\r\n const regEx = RegExp(\"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\\\?([^#]*))?(#(.*))?\");\r\n\r\n // If url string does not match regEx, we throw an error\r\n const match = this.urlString.match(regEx);\r\n if (!match) {\r\n throw ClientConfigurationError.createUrlParseError(`Given url string: ${this.urlString}`);\r\n }\r\n\r\n // Url component object\r\n const urlComponents = {\r\n Protocol: match[1],\r\n HostNameAndPort: match[4],\r\n AbsolutePath: match[5],\r\n QueryString: match[7]\r\n } as IUri;\r\n\r\n let pathSegments = urlComponents.AbsolutePath.split(\"/\");\r\n pathSegments = pathSegments.filter((val) => val && val.length > 0); // remove empty elements\r\n urlComponents.PathSegments = pathSegments;\r\n\r\n if (!StringUtils.isEmpty(urlComponents.QueryString) && urlComponents.QueryString.endsWith(\"/\")) {\r\n urlComponents.QueryString = urlComponents.QueryString.substring(0, urlComponents.QueryString.length-1);\r\n }\r\n return urlComponents;\r\n }\r\n\r\n static getDomainFromUrl(url: string): string {\r\n const regEx = RegExp(\"^([^:/?#]+://)?([^/?#]*)\");\r\n\r\n const match = url.match(regEx);\r\n\r\n if (!match) {\r\n throw ClientConfigurationError.createUrlParseError(`Given url string: ${url}`);\r\n }\r\n\r\n return match[2];\r\n }\r\n\r\n static getAbsoluteUrl(relativeUrl: string, baseUrl: string): string {\r\n if (relativeUrl[0] === Constants.FORWARD_SLASH) {\r\n const url = new UrlString(baseUrl);\r\n const baseComponents = url.getUrlComponents();\r\n\r\n return baseComponents.Protocol + \"//\" + baseComponents.HostNameAndPort + relativeUrl;\r\n }\r\n\r\n return relativeUrl;\r\n }\r\n\r\n /**\r\n * Parses hash string from given string. Returns empty string if no hash symbol is found.\r\n * @param hashString\r\n */\r\n static parseHash(hashString: string): string {\r\n const hashIndex1 = hashString.indexOf(\"#\");\r\n const hashIndex2 = hashString.indexOf(\"#/\");\r\n if (hashIndex2 > -1) {\r\n return hashString.substring(hashIndex2 + 2);\r\n } else if (hashIndex1 > -1) {\r\n return hashString.substring(hashIndex1 + 1);\r\n }\r\n return Constants.EMPTY_STRING;\r\n }\r\n\r\n /**\r\n * Parses query string from given string. Returns empty string if no query symbol is found.\r\n * @param queryString\r\n */\r\n static parseQueryString(queryString: string): string {\r\n const queryIndex1 = queryString.indexOf(\"?\");\r\n const queryIndex2 = queryString.indexOf(\"/?\");\r\n if (queryIndex2 > -1) {\r\n return queryString.substring(queryIndex2 + 2);\r\n } else if (queryIndex1 > -1) {\r\n return queryString.substring(queryIndex1 + 1);\r\n }\r\n return Constants.EMPTY_STRING;\r\n }\r\n\r\n static constructAuthorityUriFromObject(urlObject: IUri): UrlString {\r\n return new UrlString(urlObject.Protocol + \"//\" + urlObject.HostNameAndPort + \"/\" + urlObject.PathSegments.join(\"/\"));\r\n }\r\n\r\n /**\r\n * Returns URL hash as server auth code response object.\r\n */\r\n static getDeserializedHash(hash: string): ServerAuthorizationCodeResponse {\r\n // Check if given hash is empty\r\n if (StringUtils.isEmpty(hash)) {\r\n return {};\r\n }\r\n // Strip the # symbol if present\r\n const parsedHash = UrlString.parseHash(hash);\r\n // If # symbol was not present, above will return empty string, so give original hash value\r\n const deserializedHash: ServerAuthorizationCodeResponse = StringUtils.queryStringToObject(StringUtils.isEmpty(parsedHash) ? hash : parsedHash);\r\n // Check if deserialization didn't work\r\n if (!deserializedHash) {\r\n throw ClientAuthError.createHashNotDeserializedError(JSON.stringify(deserializedHash));\r\n }\r\n return deserializedHash;\r\n }\r\n\r\n /**\r\n * Returns URL query string as server auth code response object.\r\n */\r\n static getDeserializedQueryString(query: string): ServerAuthorizationCodeResponse {\r\n // Check if given query is empty\r\n if (StringUtils.isEmpty(query)) {\r\n return {};\r\n }\r\n // Strip the ? symbol if present\r\n const parsedQueryString = UrlString.parseQueryString(query);\r\n // If ? symbol was not present, above will return empty string, so give original query value\r\n const deserializedQueryString: ServerAuthorizationCodeResponse = StringUtils.queryStringToObject(StringUtils.isEmpty(parsedQueryString) ? query : parsedQueryString);\r\n // Check if deserialization didn't work\r\n if (!deserializedQueryString) {\r\n throw ClientAuthError.createHashNotDeserializedError(JSON.stringify(deserializedQueryString));\r\n }\r\n return deserializedQueryString;\r\n }\r\n\r\n /**\r\n * Check if the hash of the URL string contains known properties\r\n */\r\n static hashContainsKnownProperties(hash: string): boolean {\r\n if (StringUtils.isEmpty(hash) || hash.indexOf(\"=\") < 0) {\r\n // Hash doesn't contain key/value pairs\r\n return false;\r\n }\r\n\r\n const parameters: ServerAuthorizationCodeResponse = UrlString.getDeserializedHash(hash);\r\n return !!(\r\n parameters.code ||\r\n parameters.error_description ||\r\n parameters.error ||\r\n parameters.state\r\n );\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { InteractionType } from \"./BrowserConstants\";\r\nimport { StringUtils, ClientAuthError, ICrypto, RequestStateObject, ProtocolUtils, ServerAuthorizationCodeResponse, UrlString } from \"@azure/msal-common\";\r\n\r\nexport type BrowserStateObject = {\r\n interactionType: InteractionType\r\n};\r\n\r\nexport class BrowserProtocolUtils {\r\n\r\n /**\r\n * Extracts the BrowserStateObject from the state string.\r\n * @param browserCrypto \r\n * @param state \r\n */\r\n static extractBrowserRequestState(browserCrypto: ICrypto, state: string): BrowserStateObject | null {\r\n if (StringUtils.isEmpty(state)) {\r\n return null;\r\n }\r\n\r\n try {\r\n const requestStateObj: RequestStateObject = ProtocolUtils.parseRequestState(browserCrypto, state);\r\n return requestStateObj.libraryState.meta as BrowserStateObject;\r\n } catch (e) {\r\n throw ClientAuthError.createInvalidStateError(state, e);\r\n }\r\n }\r\n\r\n /**\r\n * Parses properties of server response from url hash\r\n * @param locationHash Hash from url\r\n */\r\n static parseServerResponseFromHash(locationHash: string): ServerAuthorizationCodeResponse {\r\n if (!locationHash) {\r\n return {};\r\n }\r\n \r\n const hashUrlString = new UrlString(locationHash);\r\n return UrlString.getDeserializedHash(hashUrlString.getHash());\r\n }\r\n}\r\n","/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { Constants, PersistentCacheKeys, StringUtils, CommonAuthorizationCodeRequest, ICrypto, AccountEntity, IdTokenEntity, AccessTokenEntity, RefreshTokenEntity, AppMetadataEntity, CacheManager, ServerTelemetryEntity, ThrottlingEntity, ProtocolUtils, Logger, AuthorityMetadataEntity, DEFAULT_CRYPTO_IMPLEMENTATION, AccountInfo, ActiveAccountFilters, CcsCredential, CcsCredentialType, IdToken, ValidCredentialType, ClientAuthError, TokenKeys, CredentialType, AuthenticationResult, AuthenticationScheme, CacheRecord } from \"@azure/msal-common\";\r\nimport { CacheOptions } from \"../config/Configuration\";\r\nimport { BrowserAuthError } from \"../error/BrowserAuthError\";\r\nimport { BrowserCacheLocation, InteractionType, TemporaryCacheKeys, InMemoryCacheKeys, StaticCacheKeys } from \"../utils/BrowserConstants\";\r\nimport { BrowserStorage } from \"./BrowserStorage\";\r\nimport { MemoryStorage } from \"./MemoryStorage\";\r\nimport { IWindowStorage } from \"./IWindowStorage\";\r\nimport { BrowserProtocolUtils } from \"../utils/BrowserProtocolUtils\";\r\nimport { NativeTokenRequest } from \"../broker/nativeBroker/NativeRequest\";\r\nimport { SilentRequest } from \"../request/SilentRequest\";\r\nimport { SsoSilentRequest } from \"../request/SsoSilentRequest\";\r\nimport { RedirectRequest } from \"../request/RedirectRequest\";\r\nimport { PopupRequest } from \"../request/PopupRequest\";\r\n\r\n/**\r\n * This class implements the cache storage interface for MSAL through browser local or session storage.\r\n * Cookies are only used if storeAuthStateInCookie is true, and are only used for\r\n * parameters such as state and nonce, generally.\r\n */\r\nexport class BrowserCacheManager extends CacheManager {\r\n\r\n // Cache configuration, either set by user or default values.\r\n protected cacheConfig: Required;\r\n // Window storage object (either local or sessionStorage)\r\n protected browserStorage: IWindowStorage;\r\n // Internal in-memory storage object used for data used by msal that does not need to persist across page loads\r\n protected internalStorage: MemoryStorage;\r\n // Temporary cache\r\n protected temporaryCacheStorage: IWindowStorage