@azure/msal-common 14.0.3 → 14.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/dist/account/AccountInfo.d.ts +0 -1
  2. package/dist/account/AccountInfo.d.ts.map +1 -1
  3. package/dist/account/AuthToken.d.ts.map +1 -1
  4. package/dist/account/AuthToken.mjs +7 -6
  5. package/dist/account/AuthToken.mjs.map +1 -1
  6. package/dist/account/CcsCredential.mjs +1 -1
  7. package/dist/account/ClientInfo.d.ts.map +1 -1
  8. package/dist/account/ClientInfo.mjs +6 -5
  9. package/dist/account/ClientInfo.mjs.map +1 -1
  10. package/dist/authority/Authority.d.ts.map +1 -1
  11. package/dist/authority/Authority.mjs +28 -50
  12. package/dist/authority/Authority.mjs.map +1 -1
  13. package/dist/authority/AuthorityFactory.d.ts.map +1 -1
  14. package/dist/authority/AuthorityFactory.mjs +9 -7
  15. package/dist/authority/AuthorityFactory.mjs.map +1 -1
  16. package/dist/authority/AuthorityMetadata.mjs +1 -1
  17. package/dist/authority/AuthorityOptions.mjs +1 -1
  18. package/dist/authority/AuthorityType.mjs +1 -1
  19. package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs +1 -1
  20. package/dist/authority/CloudInstanceDiscoveryResponse.mjs +1 -1
  21. package/dist/authority/OpenIdConfigResponse.mjs +1 -1
  22. package/dist/authority/ProtocolMode.mjs +1 -1
  23. package/dist/authority/RegionDiscovery.d.ts +3 -1
  24. package/dist/authority/RegionDiscovery.d.ts.map +1 -1
  25. package/dist/authority/RegionDiscovery.mjs +7 -8
  26. package/dist/authority/RegionDiscovery.mjs.map +1 -1
  27. package/dist/cache/CacheManager.d.ts +25 -7
  28. package/dist/cache/CacheManager.d.ts.map +1 -1
  29. package/dist/cache/CacheManager.mjs +98 -71
  30. package/dist/cache/CacheManager.mjs.map +1 -1
  31. package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -1
  32. package/dist/cache/entities/AccessTokenEntity.mjs +4 -3
  33. package/dist/cache/entities/AccessTokenEntity.mjs.map +1 -1
  34. package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
  35. package/dist/cache/entities/AccountEntity.mjs +4 -3
  36. package/dist/cache/entities/AccountEntity.mjs.map +1 -1
  37. package/dist/cache/entities/AppMetadataEntity.mjs +1 -1
  38. package/dist/cache/entities/AuthorityMetadataEntity.mjs +1 -1
  39. package/dist/cache/entities/CacheRecord.mjs +1 -1
  40. package/dist/cache/entities/CredentialEntity.d.ts.map +1 -1
  41. package/dist/cache/entities/CredentialEntity.mjs +4 -3
  42. package/dist/cache/entities/CredentialEntity.mjs.map +1 -1
  43. package/dist/cache/entities/IdTokenEntity.mjs +1 -1
  44. package/dist/cache/entities/RefreshTokenEntity.mjs +1 -1
  45. package/dist/cache/entities/ServerTelemetryEntity.mjs +1 -1
  46. package/dist/cache/entities/ThrottlingEntity.mjs +1 -1
  47. package/dist/cache/persistence/TokenCacheContext.mjs +1 -1
  48. package/dist/cache/utils/CacheTypes.d.ts +3 -6
  49. package/dist/cache/utils/CacheTypes.d.ts.map +1 -1
  50. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  51. package/dist/client/AuthorizationCodeClient.mjs +13 -11
  52. package/dist/client/AuthorizationCodeClient.mjs.map +1 -1
  53. package/dist/client/BaseClient.d.ts.map +1 -1
  54. package/dist/client/BaseClient.mjs +5 -4
  55. package/dist/client/BaseClient.mjs.map +1 -1
  56. package/dist/client/RefreshTokenClient.d.ts.map +1 -1
  57. package/dist/client/RefreshTokenClient.mjs +33 -74
  58. package/dist/client/RefreshTokenClient.mjs.map +1 -1
  59. package/dist/client/SilentFlowClient.d.ts +2 -1
  60. package/dist/client/SilentFlowClient.d.ts.map +1 -1
  61. package/dist/client/SilentFlowClient.mjs +43 -19
  62. package/dist/client/SilentFlowClient.mjs.map +1 -1
  63. package/dist/config/ClientConfiguration.d.ts.map +1 -1
  64. package/dist/config/ClientConfiguration.mjs +5 -6
  65. package/dist/config/ClientConfiguration.mjs.map +1 -1
  66. package/dist/crypto/ICrypto.d.ts +0 -4
  67. package/dist/crypto/ICrypto.d.ts.map +1 -1
  68. package/dist/crypto/ICrypto.mjs +11 -22
  69. package/dist/crypto/ICrypto.mjs.map +1 -1
  70. package/dist/crypto/JoseHeader.d.ts.map +1 -1
  71. package/dist/crypto/JoseHeader.mjs +5 -4
  72. package/dist/crypto/JoseHeader.mjs.map +1 -1
  73. package/dist/crypto/PopTokenGenerator.d.ts +2 -1
  74. package/dist/crypto/PopTokenGenerator.d.ts.map +1 -1
  75. package/dist/crypto/PopTokenGenerator.mjs +4 -4
  76. package/dist/crypto/PopTokenGenerator.mjs.map +1 -1
  77. package/dist/error/AuthError.d.ts +8 -11
  78. package/dist/error/AuthError.d.ts.map +1 -1
  79. package/dist/error/AuthError.mjs +19 -21
  80. package/dist/error/AuthError.mjs.map +1 -1
  81. package/dist/error/AuthErrorCodes.d.ts +6 -0
  82. package/dist/error/AuthErrorCodes.d.ts.map +1 -0
  83. package/dist/error/AuthErrorCodes.mjs +14 -0
  84. package/dist/error/AuthErrorCodes.mjs.map +1 -0
  85. package/dist/error/ClientAuthError.d.ts +54 -234
  86. package/dist/error/ClientAuthError.d.ts.map +1 -1
  87. package/dist/error/ClientAuthError.mjs +149 -421
  88. package/dist/error/ClientAuthError.mjs.map +1 -1
  89. package/dist/error/ClientAuthErrorCodes.d.ts +44 -0
  90. package/dist/error/ClientAuthErrorCodes.d.ts.map +1 -0
  91. package/dist/error/ClientAuthErrorCodes.mjs +52 -0
  92. package/dist/error/ClientAuthErrorCodes.mjs.map +1 -0
  93. package/dist/error/ClientConfigurationError.d.ts +31 -125
  94. package/dist/error/ClientConfigurationError.d.ts.map +1 -1
  95. package/dist/error/ClientConfigurationError.mjs +81 -222
  96. package/dist/error/ClientConfigurationError.mjs.map +1 -1
  97. package/dist/error/ClientConfigurationErrorCodes.d.ts +23 -0
  98. package/dist/error/ClientConfigurationErrorCodes.d.ts.map +1 -0
  99. package/dist/error/ClientConfigurationErrorCodes.mjs +31 -0
  100. package/dist/error/ClientConfigurationErrorCodes.mjs.map +1 -0
  101. package/dist/error/InteractionRequiredAuthError.d.ts +14 -16
  102. package/dist/error/InteractionRequiredAuthError.d.ts.map +1 -1
  103. package/dist/error/InteractionRequiredAuthError.mjs +42 -41
  104. package/dist/error/InteractionRequiredAuthError.mjs.map +1 -1
  105. package/dist/error/InteractionRequiredAuthErrorCodes.d.ts +6 -0
  106. package/dist/error/InteractionRequiredAuthErrorCodes.d.ts.map +1 -0
  107. package/dist/error/InteractionRequiredAuthErrorCodes.mjs +16 -0
  108. package/dist/error/InteractionRequiredAuthErrorCodes.mjs.map +1 -0
  109. package/dist/error/JoseHeaderError.d.ts +7 -20
  110. package/dist/error/JoseHeaderError.d.ts.map +1 -1
  111. package/dist/error/JoseHeaderError.mjs +10 -26
  112. package/dist/error/JoseHeaderError.mjs.map +1 -1
  113. package/dist/error/JoseHeaderErrorCodes.d.ts +3 -0
  114. package/dist/error/JoseHeaderErrorCodes.d.ts.map +1 -0
  115. package/dist/error/JoseHeaderErrorCodes.mjs +11 -0
  116. package/dist/error/JoseHeaderErrorCodes.mjs.map +1 -0
  117. package/dist/error/ServerError.mjs +1 -1
  118. package/dist/index.cjs +942 -1210
  119. package/dist/index.cjs.map +1 -1
  120. package/dist/index.d.ts +5 -5
  121. package/dist/index.d.ts.map +1 -1
  122. package/dist/index.mjs +13 -5
  123. package/dist/index.mjs.map +1 -1
  124. package/dist/logger/Logger.mjs +1 -1
  125. package/dist/network/INetworkModule.d.ts.map +1 -1
  126. package/dist/network/INetworkModule.mjs +5 -6
  127. package/dist/network/INetworkModule.mjs.map +1 -1
  128. package/dist/network/NetworkManager.d.ts.map +1 -1
  129. package/dist/network/NetworkManager.mjs +4 -3
  130. package/dist/network/NetworkManager.mjs.map +1 -1
  131. package/dist/network/ThrottlingUtils.mjs +1 -1
  132. package/dist/packageMetadata.d.ts +1 -1
  133. package/dist/packageMetadata.mjs +2 -2
  134. package/dist/request/AuthenticationHeaderParser.d.ts.map +1 -1
  135. package/dist/request/AuthenticationHeaderParser.mjs +7 -6
  136. package/dist/request/AuthenticationHeaderParser.mjs.map +1 -1
  137. package/dist/request/CommonRefreshTokenRequest.d.ts +3 -0
  138. package/dist/request/CommonRefreshTokenRequest.d.ts.map +1 -1
  139. package/dist/request/CommonSilentFlowRequest.d.ts +2 -0
  140. package/dist/request/CommonSilentFlowRequest.d.ts.map +1 -1
  141. package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
  142. package/dist/request/RequestParameterBuilder.mjs +5 -4
  143. package/dist/request/RequestParameterBuilder.mjs.map +1 -1
  144. package/dist/request/RequestValidator.d.ts.map +1 -1
  145. package/dist/request/RequestValidator.mjs +8 -7
  146. package/dist/request/RequestValidator.mjs.map +1 -1
  147. package/dist/request/ScopeSet.d.ts.map +1 -1
  148. package/dist/request/ScopeSet.mjs +10 -8
  149. package/dist/request/ScopeSet.mjs.map +1 -1
  150. package/dist/response/ResponseHandler.d.ts.map +1 -1
  151. package/dist/response/ResponseHandler.mjs +15 -14
  152. package/dist/response/ResponseHandler.mjs.map +1 -1
  153. package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -1
  154. package/dist/telemetry/performance/PerformanceClient.mjs +3 -2
  155. package/dist/telemetry/performance/PerformanceClient.mjs.map +1 -1
  156. package/dist/telemetry/performance/PerformanceEvent.d.ts +8 -0
  157. package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
  158. package/dist/telemetry/performance/PerformanceEvent.mjs +9 -1
  159. package/dist/telemetry/performance/PerformanceEvent.mjs.map +1 -1
  160. package/dist/telemetry/performance/StubPerformanceClient.mjs +1 -1
  161. package/dist/telemetry/server/ServerTelemetryManager.d.ts.map +1 -1
  162. package/dist/telemetry/server/ServerTelemetryManager.mjs +2 -2
  163. package/dist/telemetry/server/ServerTelemetryManager.mjs.map +1 -1
  164. package/dist/url/UrlString.d.ts.map +1 -1
  165. package/dist/url/UrlString.mjs +13 -11
  166. package/dist/url/UrlString.mjs.map +1 -1
  167. package/dist/utils/Constants.d.ts +6 -3
  168. package/dist/utils/Constants.d.ts.map +1 -1
  169. package/dist/utils/Constants.mjs +12 -4
  170. package/dist/utils/Constants.mjs.map +1 -1
  171. package/dist/utils/FunctionWrappers.d.ts.map +1 -1
  172. package/dist/utils/FunctionWrappers.mjs +1 -2
  173. package/dist/utils/FunctionWrappers.mjs.map +1 -1
  174. package/dist/utils/ProtocolUtils.d.ts.map +1 -1
  175. package/dist/utils/ProtocolUtils.mjs +7 -6
  176. package/dist/utils/ProtocolUtils.mjs.map +1 -1
  177. package/dist/utils/StringUtils.mjs +1 -1
  178. package/dist/utils/TimeUtils.mjs +1 -1
  179. package/package.json +1 -1
  180. package/src/account/AccountInfo.ts +0 -1
  181. package/src/account/AuthToken.ts +8 -7
  182. package/src/account/ClientInfo.ts +9 -6
  183. package/src/authority/Authority.ts +76 -94
  184. package/src/authority/AuthorityFactory.ts +21 -9
  185. package/src/authority/RegionDiscovery.ts +21 -18
  186. package/src/cache/CacheManager.ts +133 -95
  187. package/src/cache/entities/AccessTokenEntity.ts +7 -2
  188. package/src/cache/entities/AccountEntity.ts +7 -2
  189. package/src/cache/entities/CredentialEntity.ts +7 -2
  190. package/src/cache/utils/CacheTypes.ts +6 -6
  191. package/src/client/AuthorizationCodeClient.ts +35 -11
  192. package/src/client/BaseClient.ts +7 -4
  193. package/src/client/RefreshTokenClient.ts +100 -126
  194. package/src/client/SilentFlowClient.ts +72 -19
  195. package/src/config/ClientConfiguration.ts +6 -7
  196. package/src/crypto/ICrypto.ts +12 -34
  197. package/src/crypto/JoseHeader.ts +6 -3
  198. package/src/crypto/PopTokenGenerator.ts +10 -5
  199. package/src/error/AuthError.ts +24 -26
  200. package/src/error/AuthErrorCodes.ts +10 -0
  201. package/src/error/ClientAuthError.ts +227 -632
  202. package/src/error/ClientAuthErrorCodes.ts +51 -0
  203. package/src/error/ClientConfigurationError.ts +146 -332
  204. package/src/error/ClientConfigurationErrorCodes.ts +28 -0
  205. package/src/error/InteractionRequiredAuthError.ts +60 -55
  206. package/src/error/InteractionRequiredAuthErrorCodes.ts +13 -0
  207. package/src/error/JoseHeaderError.ts +11 -31
  208. package/src/error/JoseHeaderErrorCodes.ts +7 -0
  209. package/src/index.ts +13 -1
  210. package/src/network/INetworkModule.ts +10 -7
  211. package/src/network/NetworkManager.ts +5 -5
  212. package/src/packageMetadata.ts +1 -1
  213. package/src/request/AuthenticationHeaderParser.ts +11 -8
  214. package/src/request/CommonRefreshTokenRequest.ts +3 -0
  215. package/src/request/CommonSilentFlowRequest.ts +2 -0
  216. package/src/request/RequestParameterBuilder.ts +10 -3
  217. package/src/request/RequestValidator.ts +19 -6
  218. package/src/request/ScopeSet.ts +23 -7
  219. package/src/response/ResponseHandler.ts +37 -17
  220. package/src/telemetry/performance/PerformanceClient.ts +2 -1
  221. package/src/telemetry/performance/PerformanceEvent.ts +9 -0
  222. package/src/telemetry/server/ServerTelemetryManager.ts +1 -1
  223. package/src/url/UrlString.ts +26 -16
  224. package/src/utils/Constants.ts +11 -3
  225. package/src/utils/FunctionWrappers.ts +0 -1
  226. package/src/utils/ProtocolUtils.ts +8 -12
@@ -4,219 +4,307 @@
4
4
  */
5
5
 
6
6
  import { AuthError } from "./AuthError";
7
+ import * as ClientAuthErrorCodes from "./ClientAuthErrorCodes";
8
+ export { ClientAuthErrorCodes }; // Allow importing as "ClientAuthErrorCodes";
7
9
 
8
10
  /**
9
11
  * ClientAuthErrorMessage class containing string constants used by error codes and messages.
10
12
  */
13
+
14
+ export const ClientAuthErrorMessages = {
15
+ [ClientAuthErrorCodes.clientInfoDecodingError]:
16
+ "The client info could not be parsed/decoded correctly",
17
+ [ClientAuthErrorCodes.clientInfoEmptyError]: "The client info was empty",
18
+ [ClientAuthErrorCodes.tokenParsingError]: "Token cannot be parsed",
19
+ [ClientAuthErrorCodes.nullOrEmptyToken]: "The token is null or empty",
20
+ [ClientAuthErrorCodes.endpointResolutionError]:
21
+ "Endpoints cannot be resolved",
22
+ [ClientAuthErrorCodes.networkError]: "Network request failed",
23
+ [ClientAuthErrorCodes.openIdConfigError]:
24
+ "Could not retrieve endpoints. Check your authority and verify the .well-known/openid-configuration endpoint returns the required endpoints.",
25
+ [ClientAuthErrorCodes.hashNotDeserialized]:
26
+ "The hash parameters could not be deserialized",
27
+ [ClientAuthErrorCodes.invalidState]: "State was not the expected format",
28
+ [ClientAuthErrorCodes.stateMismatch]: "State mismatch error",
29
+ [ClientAuthErrorCodes.stateNotFound]: "State not found",
30
+ [ClientAuthErrorCodes.nonceMismatch]: "Nonce mismatch error",
31
+ [ClientAuthErrorCodes.authTimeNotFound]:
32
+ "Max Age was requested and the ID token is missing the auth_time variable." +
33
+ " auth_time is an optional claim and is not enabled by default - it must be enabled." +
34
+ " See https://aka.ms/msaljs/optional-claims for more information.",
35
+ [ClientAuthErrorCodes.maxAgeTranspired]:
36
+ "Max Age is set to 0, or too much time has elapsed since the last end-user authentication.",
37
+ [ClientAuthErrorCodes.multipleMatchingTokens]:
38
+ "The cache contains multiple tokens satisfying the requirements. " +
39
+ "Call AcquireToken again providing more requirements such as authority or account.",
40
+ [ClientAuthErrorCodes.multipleMatchingAccounts]:
41
+ "The cache contains multiple accounts satisfying the given parameters. Please pass more info to obtain the correct account",
42
+ [ClientAuthErrorCodes.multipleMatchingAppMetadata]:
43
+ "The cache contains multiple appMetadata satisfying the given parameters. Please pass more info to obtain the correct appMetadata",
44
+ [ClientAuthErrorCodes.requestCannotBeMade]:
45
+ "Token request cannot be made without authorization code or refresh token.",
46
+ [ClientAuthErrorCodes.cannotRemoveEmptyScope]:
47
+ "Cannot remove null or empty scope from ScopeSet",
48
+ [ClientAuthErrorCodes.cannotAppendScopeSet]: "Cannot append ScopeSet",
49
+ [ClientAuthErrorCodes.emptyInputScopeSet]:
50
+ "Empty input ScopeSet cannot be processed",
51
+ [ClientAuthErrorCodes.deviceCodePollingCancelled]:
52
+ "Caller has cancelled token endpoint polling during device code flow by setting DeviceCodeRequest.cancel = true.",
53
+ [ClientAuthErrorCodes.deviceCodeExpired]: "Device code is expired.",
54
+ [ClientAuthErrorCodes.deviceCodeUnknownError]:
55
+ "Device code stopped polling for unknown reasons.",
56
+ [ClientAuthErrorCodes.noAccountInSilentRequest]:
57
+ "Please pass an account object, silent flow is not supported without account information",
58
+ [ClientAuthErrorCodes.invalidCacheRecord]:
59
+ "Cache record object was null or undefined.",
60
+ [ClientAuthErrorCodes.invalidCacheEnvironment]:
61
+ "Invalid environment when attempting to create cache entry",
62
+ [ClientAuthErrorCodes.noAccountFound]:
63
+ "No account found in cache for given key.",
64
+ [ClientAuthErrorCodes.noCryptoObject]: "No crypto object detected.",
65
+ [ClientAuthErrorCodes.unexpectedCredentialType]:
66
+ "Unexpected credential type.",
67
+ [ClientAuthErrorCodes.invalidAssertion]:
68
+ "Client assertion must meet requirements described in https://tools.ietf.org/html/rfc7515",
69
+ [ClientAuthErrorCodes.invalidClientCredential]:
70
+ "Client credential (secret, certificate, or assertion) must not be empty when creating a confidential client. An application should at most have one credential",
71
+ [ClientAuthErrorCodes.tokenRefreshRequired]:
72
+ "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.",
73
+ [ClientAuthErrorCodes.userTimeoutReached]:
74
+ "User defined timeout for device code polling reached",
75
+ [ClientAuthErrorCodes.tokenClaimsCnfRequiredForSignedJwt]:
76
+ "Cannot generate a POP jwt if the token_claims are not populated",
77
+ [ClientAuthErrorCodes.authorizationCodeMissingFromServerResponse]:
78
+ "Server response does not contain an authorization code to proceed",
79
+ [ClientAuthErrorCodes.bindingKeyNotRemoved]:
80
+ "Could not remove the credential's binding key from storage.",
81
+ [ClientAuthErrorCodes.endSessionEndpointNotSupported]:
82
+ "The provided authority does not support logout",
83
+ [ClientAuthErrorCodes.keyIdMissing]:
84
+ "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.",
85
+ [ClientAuthErrorCodes.noNetworkConnectivity]:
86
+ "No network connectivity. Check your internet connection.",
87
+ [ClientAuthErrorCodes.userCanceled]: "User cancelled the flow.",
88
+ [ClientAuthErrorCodes.missingTenantIdError]:
89
+ "A tenant id - not common, organizations, or consumers - must be specified when using the client_credentials flow.",
90
+ [ClientAuthErrorCodes.methodNotImplemented]:
91
+ "This method has not been implemented",
92
+ };
93
+
94
+ /**
95
+ * String constants used by error codes and messages.
96
+ * @deprecated Use ClientAuthErrorCodes instead
97
+ */
11
98
  export const ClientAuthErrorMessage = {
12
99
  clientInfoDecodingError: {
13
- code: "client_info_decoding_error",
14
- desc: "The client info could not be parsed/decoded correctly. Please review the trace to determine the root cause.",
100
+ code: ClientAuthErrorCodes.clientInfoDecodingError,
101
+ desc: ClientAuthErrorMessages[
102
+ ClientAuthErrorCodes.clientInfoDecodingError
103
+ ],
15
104
  },
16
105
  clientInfoEmptyError: {
17
- code: "client_info_empty_error",
18
- desc: "The client info was empty. Please review the trace to determine the root cause.",
106
+ code: ClientAuthErrorCodes.clientInfoEmptyError,
107
+ desc: ClientAuthErrorMessages[
108
+ ClientAuthErrorCodes.clientInfoEmptyError
109
+ ],
19
110
  },
20
111
  tokenParsingError: {
21
- code: "token_parsing_error",
22
- desc: "Token cannot be parsed. Please review stack trace to determine root cause.",
112
+ code: ClientAuthErrorCodes.tokenParsingError,
113
+ desc: ClientAuthErrorMessages[ClientAuthErrorCodes.tokenParsingError],
23
114
  },
24
115
  nullOrEmptyToken: {
25
- code: "null_or_empty_token",
26
- desc: "The token is null or empty. Please review the trace to determine the root cause.",
116
+ code: ClientAuthErrorCodes.nullOrEmptyToken,
117
+ desc: ClientAuthErrorMessages[ClientAuthErrorCodes.nullOrEmptyToken],
27
118
  },
28
119
  endpointResolutionError: {
29
- code: "endpoints_resolution_error",
30
- desc: "Error: could not resolve endpoints. Please check network and try again.",
120
+ code: ClientAuthErrorCodes.endpointResolutionError,
121
+ desc: ClientAuthErrorMessages[
122
+ ClientAuthErrorCodes.endpointResolutionError
123
+ ],
31
124
  },
32
125
  networkError: {
33
- code: "network_error",
34
- desc: "Network request failed. Please check network trace to determine root cause.",
126
+ code: ClientAuthErrorCodes.networkError,
127
+ desc: ClientAuthErrorMessages[ClientAuthErrorCodes.networkError],
35
128
  },
36
129
  unableToGetOpenidConfigError: {
37
- code: "openid_config_error",
38
- desc: "Could not retrieve endpoints. Check your authority and verify the .well-known/openid-configuration endpoint returns the required endpoints.",
130
+ code: ClientAuthErrorCodes.openIdConfigError,
131
+ desc: ClientAuthErrorMessages[ClientAuthErrorCodes.openIdConfigError],
39
132
  },
40
133
  hashNotDeserialized: {
41
- code: "hash_not_deserialized",
42
- desc: "The hash parameters could not be deserialized. Please review the trace to determine the root cause.",
43
- },
44
- blankGuidGenerated: {
45
- code: "blank_guid_generated",
46
- desc: "The guid generated was blank. Please review the trace to determine the root cause.",
134
+ code: ClientAuthErrorCodes.hashNotDeserialized,
135
+ desc: ClientAuthErrorMessages[ClientAuthErrorCodes.hashNotDeserialized],
47
136
  },
48
137
  invalidStateError: {
49
- code: "invalid_state",
50
- desc: "State was not the expected format. Please check the logs to determine whether the request was sent using ProtocolUtils.setRequestState().",
138
+ code: ClientAuthErrorCodes.invalidState,
139
+ desc: ClientAuthErrorMessages[ClientAuthErrorCodes.invalidState],
51
140
  },
52
141
  stateMismatchError: {
53
- code: "state_mismatch",
54
- desc: "State mismatch error. Please check your network. Continued requests may cause cache overflow.",
142
+ code: ClientAuthErrorCodes.stateMismatch,
143
+ desc: ClientAuthErrorMessages[ClientAuthErrorCodes.stateMismatch],
55
144
  },
56
145
  stateNotFoundError: {
57
- code: "state_not_found",
58
- desc: "State not found",
146
+ code: ClientAuthErrorCodes.stateNotFound,
147
+ desc: ClientAuthErrorMessages[ClientAuthErrorCodes.stateNotFound],
59
148
  },
60
149
  nonceMismatchError: {
61
- code: "nonce_mismatch",
62
- desc: "Nonce mismatch error. This may be caused by a race condition in concurrent requests.",
63
- },
64
- nonceNotFoundError: {
65
- code: "nonce_not_found",
66
- desc: "nonce not found",
150
+ code: ClientAuthErrorCodes.nonceMismatch,
151
+ desc: ClientAuthErrorMessages[ClientAuthErrorCodes.nonceMismatch],
67
152
  },
68
153
  authTimeNotFoundError: {
69
- code: "auth_time_not_found",
70
- desc:
71
- "Max Age was requested and the ID token is missing the auth_time variable." +
72
- " auth_time is an optional claim and is not enabled by default - it must be enabled." +
73
- " See https://aka.ms/msaljs/optional-claims for more information.",
74
- },
75
- maxAgeTranspiredError: {
76
- code: "max_age_transpired",
77
- desc: "Max Age is set to 0, or too much time has elapsed since the last end-user authentication.",
154
+ code: ClientAuthErrorCodes.authTimeNotFound,
155
+ desc: ClientAuthErrorMessages[ClientAuthErrorCodes.authTimeNotFound],
78
156
  },
79
- noTokensFoundError: {
80
- code: "no_tokens_found",
81
- 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().",
157
+ maxAgeTranspired: {
158
+ code: ClientAuthErrorCodes.maxAgeTranspired,
159
+ desc: ClientAuthErrorMessages[ClientAuthErrorCodes.maxAgeTranspired],
82
160
  },
83
161
  multipleMatchingTokens: {
84
- code: "multiple_matching_tokens",
85
- desc:
86
- "The cache contains multiple tokens satisfying the requirements. " +
87
- "Call AcquireToken again providing more requirements such as authority or account.",
162
+ code: ClientAuthErrorCodes.multipleMatchingTokens,
163
+ desc: ClientAuthErrorMessages[
164
+ ClientAuthErrorCodes.multipleMatchingTokens
165
+ ],
88
166
  },
89
167
  multipleMatchingAccounts: {
90
- code: "multiple_matching_accounts",
91
- desc: "The cache contains multiple accounts satisfying the given parameters. Please pass more info to obtain the correct account",
168
+ code: ClientAuthErrorCodes.multipleMatchingAccounts,
169
+ desc: ClientAuthErrorMessages[
170
+ ClientAuthErrorCodes.multipleMatchingAccounts
171
+ ],
92
172
  },
93
173
  multipleMatchingAppMetadata: {
94
- code: "multiple_matching_appMetadata",
95
- desc: "The cache contains multiple appMetadata satisfying the given parameters. Please pass more info to obtain the correct appMetadata",
174
+ code: ClientAuthErrorCodes.multipleMatchingAppMetadata,
175
+ desc: ClientAuthErrorMessages[
176
+ ClientAuthErrorCodes.multipleMatchingAppMetadata
177
+ ],
96
178
  },
97
179
  tokenRequestCannotBeMade: {
98
- code: "request_cannot_be_made",
99
- desc: "Token request cannot be made without authorization code or refresh token.",
100
- },
101
- appendEmptyScopeError: {
102
- code: "cannot_append_empty_scope",
103
- desc: "Cannot append null or empty scope to ScopeSet. Please check the stack trace for more info.",
180
+ code: ClientAuthErrorCodes.requestCannotBeMade,
181
+ desc: ClientAuthErrorMessages[ClientAuthErrorCodes.requestCannotBeMade],
104
182
  },
105
183
  removeEmptyScopeError: {
106
- code: "cannot_remove_empty_scope",
107
- desc: "Cannot remove null or empty scope from ScopeSet. Please check the stack trace for more info.",
184
+ code: ClientAuthErrorCodes.cannotRemoveEmptyScope,
185
+ desc: ClientAuthErrorMessages[
186
+ ClientAuthErrorCodes.cannotRemoveEmptyScope
187
+ ],
108
188
  },
109
189
  appendScopeSetError: {
110
- code: "cannot_append_scopeset",
111
- desc: "Cannot append ScopeSet due to error.",
190
+ code: ClientAuthErrorCodes.cannotAppendScopeSet,
191
+ desc: ClientAuthErrorMessages[
192
+ ClientAuthErrorCodes.cannotAppendScopeSet
193
+ ],
112
194
  },
113
195
  emptyInputScopeSetError: {
114
- code: "empty_input_scopeset",
115
- desc: "Empty input ScopeSet cannot be processed.",
196
+ code: ClientAuthErrorCodes.emptyInputScopeSet,
197
+ desc: ClientAuthErrorMessages[ClientAuthErrorCodes.emptyInputScopeSet],
116
198
  },
117
199
  DeviceCodePollingCancelled: {
118
- code: "device_code_polling_cancelled",
119
- desc: "Caller has cancelled token endpoint polling during device code flow by setting DeviceCodeRequest.cancel = true.",
200
+ code: ClientAuthErrorCodes.deviceCodePollingCancelled,
201
+ desc: ClientAuthErrorMessages[
202
+ ClientAuthErrorCodes.deviceCodePollingCancelled
203
+ ],
120
204
  },
121
205
  DeviceCodeExpired: {
122
- code: "device_code_expired",
123
- desc: "Device code is expired.",
206
+ code: ClientAuthErrorCodes.deviceCodeExpired,
207
+ desc: ClientAuthErrorMessages[ClientAuthErrorCodes.deviceCodeExpired],
124
208
  },
125
209
  DeviceCodeUnknownError: {
126
- code: "device_code_unknown_error",
127
- desc: "Device code stopped polling for unknown reasons.",
210
+ code: ClientAuthErrorCodes.deviceCodeUnknownError,
211
+ desc: ClientAuthErrorMessages[
212
+ ClientAuthErrorCodes.deviceCodeUnknownError
213
+ ],
128
214
  },
129
215
  NoAccountInSilentRequest: {
130
- code: "no_account_in_silent_request",
131
- desc: "Please pass an account object, silent flow is not supported without account information",
216
+ code: ClientAuthErrorCodes.noAccountInSilentRequest,
217
+ desc: ClientAuthErrorMessages[
218
+ ClientAuthErrorCodes.noAccountInSilentRequest
219
+ ],
132
220
  },
133
221
  invalidCacheRecord: {
134
- code: "invalid_cache_record",
135
- desc: "Cache record object was null or undefined.",
222
+ code: ClientAuthErrorCodes.invalidCacheRecord,
223
+ desc: ClientAuthErrorMessages[ClientAuthErrorCodes.invalidCacheRecord],
136
224
  },
137
225
  invalidCacheEnvironment: {
138
- code: "invalid_cache_environment",
139
- desc: "Invalid environment when attempting to create cache entry",
226
+ code: ClientAuthErrorCodes.invalidCacheEnvironment,
227
+ desc: ClientAuthErrorMessages[
228
+ ClientAuthErrorCodes.invalidCacheEnvironment
229
+ ],
140
230
  },
141
231
  noAccountFound: {
142
- code: "no_account_found",
143
- desc: "No account found in cache for given key.",
144
- },
145
- CachePluginError: {
146
- code: "no cache plugin set on CacheManager",
147
- desc: "ICachePlugin needs to be set before using readFromStorage or writeFromStorage",
232
+ code: ClientAuthErrorCodes.noAccountFound,
233
+ desc: ClientAuthErrorMessages[ClientAuthErrorCodes.noAccountFound],
148
234
  },
149
235
  noCryptoObj: {
150
- code: "no_crypto_object",
151
- desc: "No crypto object detected. This is required for the following operation: ",
152
- },
153
- invalidCacheType: {
154
- code: "invalid_cache_type",
155
- desc: "Invalid cache type",
156
- },
157
- unexpectedAccountType: {
158
- code: "unexpected_account_type",
159
- desc: "Unexpected account type.",
236
+ code: ClientAuthErrorCodes.noCryptoObject,
237
+ desc: ClientAuthErrorMessages[ClientAuthErrorCodes.noCryptoObject],
160
238
  },
161
239
  unexpectedCredentialType: {
162
- code: "unexpected_credential_type",
163
- desc: "Unexpected credential type.",
240
+ code: ClientAuthErrorCodes.unexpectedCredentialType,
241
+ desc: ClientAuthErrorMessages[
242
+ ClientAuthErrorCodes.unexpectedCredentialType
243
+ ],
164
244
  },
165
245
  invalidAssertion: {
166
- code: "invalid_assertion",
167
- desc: "Client assertion must meet requirements described in https://tools.ietf.org/html/rfc7515",
246
+ code: ClientAuthErrorCodes.invalidAssertion,
247
+ desc: ClientAuthErrorMessages[ClientAuthErrorCodes.invalidAssertion],
168
248
  },
169
249
  invalidClientCredential: {
170
- code: "invalid_client_credential",
171
- desc: "Client credential (secret, certificate, or assertion) must not be empty when creating a confidential client. An application should at most have one credential",
250
+ code: ClientAuthErrorCodes.invalidClientCredential,
251
+ desc: ClientAuthErrorMessages[
252
+ ClientAuthErrorCodes.invalidClientCredential
253
+ ],
172
254
  },
173
255
  tokenRefreshRequired: {
174
- code: "token_refresh_required",
175
- 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.",
256
+ code: ClientAuthErrorCodes.tokenRefreshRequired,
257
+ desc: ClientAuthErrorMessages[
258
+ ClientAuthErrorCodes.tokenRefreshRequired
259
+ ],
176
260
  },
177
261
  userTimeoutReached: {
178
- code: "user_timeout_reached",
179
- desc: "User defined timeout for device code polling reached",
262
+ code: ClientAuthErrorCodes.userTimeoutReached,
263
+ desc: ClientAuthErrorMessages[ClientAuthErrorCodes.userTimeoutReached],
180
264
  },
181
265
  tokenClaimsRequired: {
182
- code: "token_claims_cnf_required_for_signedjwt",
183
- desc: "Cannot generate a POP jwt if the token_claims are not populated",
266
+ code: ClientAuthErrorCodes.tokenClaimsCnfRequiredForSignedJwt,
267
+ desc: ClientAuthErrorMessages[
268
+ ClientAuthErrorCodes.tokenClaimsCnfRequiredForSignedJwt
269
+ ],
184
270
  },
185
271
  noAuthorizationCodeFromServer: {
186
- code: "authorization_code_missing_from_server_response",
187
- desc: "Server response does not contain an authorization code to proceed",
188
- },
189
- noAzureRegionDetected: {
190
- code: "no_azure_region_detected",
191
- desc: "No azure region was detected and no fallback was made available",
192
- },
193
- accessTokenEntityNullError: {
194
- code: "access_token_entity_null",
195
- desc: "Access token entity is null, please check logs and cache to ensure a valid access token is present.",
272
+ code: ClientAuthErrorCodes.authorizationCodeMissingFromServerResponse,
273
+ desc: ClientAuthErrorMessages[
274
+ ClientAuthErrorCodes.authorizationCodeMissingFromServerResponse
275
+ ],
196
276
  },
197
277
  bindingKeyNotRemovedError: {
198
- code: "binding_key_not_removed",
199
- desc: "Could not remove the credential's binding key from storage.",
278
+ code: ClientAuthErrorCodes.bindingKeyNotRemoved,
279
+ desc: ClientAuthErrorMessages[
280
+ ClientAuthErrorCodes.bindingKeyNotRemoved
281
+ ],
200
282
  },
201
283
  logoutNotSupported: {
202
- code: "end_session_endpoint_not_supported",
203
- desc: "Provided authority does not support logout.",
284
+ code: ClientAuthErrorCodes.endSessionEndpointNotSupported,
285
+ desc: ClientAuthErrorMessages[
286
+ ClientAuthErrorCodes.endSessionEndpointNotSupported
287
+ ],
204
288
  },
205
289
  keyIdMissing: {
206
- code: "key_id_missing",
207
- 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.",
290
+ code: ClientAuthErrorCodes.keyIdMissing,
291
+ desc: ClientAuthErrorMessages[ClientAuthErrorCodes.keyIdMissing],
208
292
  },
209
293
  noNetworkConnectivity: {
210
- code: "no_network_connectivity",
211
- desc: "No network connectivity. Check your internet connection.",
294
+ code: ClientAuthErrorCodes.noNetworkConnectivity,
295
+ desc: ClientAuthErrorMessages[
296
+ ClientAuthErrorCodes.noNetworkConnectivity
297
+ ],
212
298
  },
213
299
  userCanceledError: {
214
- code: "user_canceled",
215
- desc: "User canceled the flow.",
300
+ code: ClientAuthErrorCodes.userCanceled,
301
+ desc: ClientAuthErrorMessages[ClientAuthErrorCodes.userCanceled],
216
302
  },
217
303
  missingTenantIdError: {
218
- code: "missing_tenant_id_error",
219
- desc: "A tenant id - not common, organizations, or consumers - must be specified when using the client_credentials flow.",
304
+ code: ClientAuthErrorCodes.missingTenantIdError,
305
+ desc: ClientAuthErrorMessages[
306
+ ClientAuthErrorCodes.missingTenantIdError
307
+ ],
220
308
  },
221
309
  };
222
310
 
@@ -224,515 +312,22 @@ export const ClientAuthErrorMessage = {
224
312
  * Error thrown when there is an error in the client code running on the browser.
225
313
  */
226
314
  export class ClientAuthError extends AuthError {
227
- constructor(errorCode: string, errorMessage?: string) {
228
- super(errorCode, errorMessage);
315
+ constructor(errorCode: string, additionalMessage?: string) {
316
+ super(
317
+ errorCode,
318
+ additionalMessage
319
+ ? `${ClientAuthErrorMessages[errorCode]}: ${additionalMessage}`
320
+ : ClientAuthErrorMessages[errorCode]
321
+ );
229
322
  this.name = "ClientAuthError";
230
323
 
231
324
  Object.setPrototypeOf(this, ClientAuthError.prototype);
232
325
  }
326
+ }
233
327
 
234
- /**
235
- * Creates an error thrown when client info object doesn't decode correctly.
236
- * @param caughtError
237
- */
238
- static createClientInfoDecodingError(caughtError: string): ClientAuthError {
239
- return new ClientAuthError(
240
- ClientAuthErrorMessage.clientInfoDecodingError.code,
241
- `${ClientAuthErrorMessage.clientInfoDecodingError.desc} Failed with error: ${caughtError}`
242
- );
243
- }
244
-
245
- /**
246
- * Creates an error thrown if the client info is empty.
247
- * @param rawClientInfo
248
- */
249
- static createClientInfoEmptyError(): ClientAuthError {
250
- return new ClientAuthError(
251
- ClientAuthErrorMessage.clientInfoEmptyError.code,
252
- `${ClientAuthErrorMessage.clientInfoEmptyError.desc}`
253
- );
254
- }
255
-
256
- /**
257
- * Creates an error thrown when the id token extraction errors out.
258
- * @param err
259
- */
260
- static createTokenParsingError(
261
- caughtExtractionError: string
262
- ): ClientAuthError {
263
- return new ClientAuthError(
264
- ClientAuthErrorMessage.tokenParsingError.code,
265
- `${ClientAuthErrorMessage.tokenParsingError.desc} Failed with error: ${caughtExtractionError}`
266
- );
267
- }
268
-
269
- /**
270
- * Creates an error thrown when the id token string is null or empty.
271
- * @param invalidRawTokenString
272
- */
273
- static createTokenNullOrEmptyError(
274
- invalidRawTokenString: string
275
- ): ClientAuthError {
276
- return new ClientAuthError(
277
- ClientAuthErrorMessage.nullOrEmptyToken.code,
278
- `${ClientAuthErrorMessage.nullOrEmptyToken.desc} Raw Token Value: ${invalidRawTokenString}`
279
- );
280
- }
281
-
282
- /**
283
- * Creates an error thrown when the endpoint discovery doesn't complete correctly.
284
- */
285
- static createEndpointDiscoveryIncompleteError(
286
- errDetail: string
287
- ): ClientAuthError {
288
- return new ClientAuthError(
289
- ClientAuthErrorMessage.endpointResolutionError.code,
290
- `${ClientAuthErrorMessage.endpointResolutionError.desc} Detail: ${errDetail}`
291
- );
292
- }
293
-
294
- /**
295
- * Creates an error thrown when the fetch client throws
296
- */
297
- static createNetworkError(
298
- endpoint: string,
299
- errDetail: string
300
- ): ClientAuthError {
301
- return new ClientAuthError(
302
- ClientAuthErrorMessage.networkError.code,
303
- `${
304
- ClientAuthErrorMessage.networkError.desc
305
- } | Fetch client threw: ${errDetail} | Attempted to reach: ${
306
- endpoint.split("?")[0]
307
- }`
308
- );
309
- }
310
-
311
- /**
312
- * Creates an error thrown when the openid-configuration endpoint cannot be reached or does not contain the required data
313
- */
314
- static createUnableToGetOpenidConfigError(
315
- errDetail: string
316
- ): ClientAuthError {
317
- return new ClientAuthError(
318
- ClientAuthErrorMessage.unableToGetOpenidConfigError.code,
319
- `${ClientAuthErrorMessage.unableToGetOpenidConfigError.desc} Attempted to retrieve endpoints from: ${errDetail}`
320
- );
321
- }
322
-
323
- /**
324
- * Creates an error thrown when the hash cannot be deserialized.
325
- * @param hashParamObj
326
- */
327
- static createHashNotDeserializedError(
328
- hashParamObj: string
329
- ): ClientAuthError {
330
- return new ClientAuthError(
331
- ClientAuthErrorMessage.hashNotDeserialized.code,
332
- `${ClientAuthErrorMessage.hashNotDeserialized.desc} Given Object: ${hashParamObj}`
333
- );
334
- }
335
-
336
- /**
337
- * Creates an error thrown when the state cannot be parsed.
338
- * @param invalidState
339
- */
340
- static createInvalidStateError(
341
- invalidState: string,
342
- errorString?: string
343
- ): ClientAuthError {
344
- return new ClientAuthError(
345
- ClientAuthErrorMessage.invalidStateError.code,
346
- `${ClientAuthErrorMessage.invalidStateError.desc} Invalid State: ${invalidState}, Root Err: ${errorString}`
347
- );
348
- }
349
-
350
- /**
351
- * Creates an error thrown when two states do not match.
352
- */
353
- static createStateMismatchError(): ClientAuthError {
354
- return new ClientAuthError(
355
- ClientAuthErrorMessage.stateMismatchError.code,
356
- ClientAuthErrorMessage.stateMismatchError.desc
357
- );
358
- }
359
-
360
- /**
361
- * Creates an error thrown when the state is not present
362
- * @param missingState
363
- */
364
- static createStateNotFoundError(missingState: string): ClientAuthError {
365
- return new ClientAuthError(
366
- ClientAuthErrorMessage.stateNotFoundError.code,
367
- `${ClientAuthErrorMessage.stateNotFoundError.desc}: ${missingState}`
368
- );
369
- }
370
-
371
- /**
372
- * Creates an error thrown when the nonce does not match.
373
- */
374
- static createNonceMismatchError(): ClientAuthError {
375
- return new ClientAuthError(
376
- ClientAuthErrorMessage.nonceMismatchError.code,
377
- ClientAuthErrorMessage.nonceMismatchError.desc
378
- );
379
- }
380
-
381
- /**
382
- * Creates an error thrown when max_age was provided in the request, but auth_time is not in the token claims
383
- * @param missingNonce
384
- */
385
- static createAuthTimeNotFoundError(): ClientAuthError {
386
- return new ClientAuthError(
387
- ClientAuthErrorMessage.authTimeNotFoundError.code,
388
- ClientAuthErrorMessage.authTimeNotFoundError.desc
389
- );
390
- }
391
-
392
- /**
393
- * Creates an error thrown when too much time has elapsed since the last end-user authentication
394
- */
395
- static createMaxAgeTranspiredError(): ClientAuthError {
396
- return new ClientAuthError(
397
- ClientAuthErrorMessage.maxAgeTranspiredError.code,
398
- ClientAuthErrorMessage.maxAgeTranspiredError.desc
399
- );
400
- }
401
-
402
- /**
403
- * Creates an error thrown when the mnonce is not present
404
- * @param missingNonce
405
- */
406
- static createNonceNotFoundError(missingNonce: string): ClientAuthError {
407
- return new ClientAuthError(
408
- ClientAuthErrorMessage.nonceNotFoundError.code,
409
- `${ClientAuthErrorMessage.nonceNotFoundError.desc}: ${missingNonce}`
410
- );
411
- }
412
-
413
- /**
414
- * Throws error when multiple tokens are in cache.
415
- */
416
- static createMultipleMatchingTokensInCacheError(): ClientAuthError {
417
- return new ClientAuthError(
418
- ClientAuthErrorMessage.multipleMatchingTokens.code,
419
- `${ClientAuthErrorMessage.multipleMatchingTokens.desc}.`
420
- );
421
- }
422
-
423
- /**
424
- * Throws error when multiple accounts are in cache for the given params
425
- */
426
- static createMultipleMatchingAccountsInCacheError(): ClientAuthError {
427
- return new ClientAuthError(
428
- ClientAuthErrorMessage.multipleMatchingAccounts.code,
429
- ClientAuthErrorMessage.multipleMatchingAccounts.desc
430
- );
431
- }
432
-
433
- /**
434
- * Throws error when multiple appMetada are in cache for the given clientId.
435
- */
436
- static createMultipleMatchingAppMetadataInCacheError(): ClientAuthError {
437
- return new ClientAuthError(
438
- ClientAuthErrorMessage.multipleMatchingAppMetadata.code,
439
- ClientAuthErrorMessage.multipleMatchingAppMetadata.desc
440
- );
441
- }
442
-
443
- /**
444
- * Throws error when no auth code or refresh token is given to ServerTokenRequestParameters.
445
- */
446
- static createTokenRequestCannotBeMadeError(): ClientAuthError {
447
- return new ClientAuthError(
448
- ClientAuthErrorMessage.tokenRequestCannotBeMade.code,
449
- ClientAuthErrorMessage.tokenRequestCannotBeMade.desc
450
- );
451
- }
452
-
453
- /**
454
- * Throws error when attempting to append a null, undefined or empty scope to a set
455
- * @param givenScope
456
- */
457
- static createAppendEmptyScopeToSetError(
458
- givenScope: string
459
- ): ClientAuthError {
460
- return new ClientAuthError(
461
- ClientAuthErrorMessage.appendEmptyScopeError.code,
462
- `${ClientAuthErrorMessage.appendEmptyScopeError.desc} Given Scope: ${givenScope}`
463
- );
464
- }
465
-
466
- /**
467
- * Throws error when attempting to append a null, undefined or empty scope to a set
468
- * @param givenScope
469
- */
470
- static createRemoveEmptyScopeFromSetError(
471
- givenScope: string
472
- ): ClientAuthError {
473
- return new ClientAuthError(
474
- ClientAuthErrorMessage.removeEmptyScopeError.code,
475
- `${ClientAuthErrorMessage.removeEmptyScopeError.desc} Given Scope: ${givenScope}`
476
- );
477
- }
478
-
479
- /**
480
- * Throws error when attempting to append null or empty ScopeSet.
481
- * @param appendError
482
- */
483
- static createAppendScopeSetError(appendError: string): ClientAuthError {
484
- return new ClientAuthError(
485
- ClientAuthErrorMessage.appendScopeSetError.code,
486
- `${ClientAuthErrorMessage.appendScopeSetError.desc} Detail Error: ${appendError}`
487
- );
488
- }
489
-
490
- /**
491
- * Throws error if ScopeSet is null or undefined.
492
- * @param givenScopeSet
493
- */
494
- static createEmptyInputScopeSetError(): ClientAuthError {
495
- return new ClientAuthError(
496
- ClientAuthErrorMessage.emptyInputScopeSetError.code,
497
- `${ClientAuthErrorMessage.emptyInputScopeSetError.desc}`
498
- );
499
- }
500
-
501
- /**
502
- * Throws error if user sets CancellationToken.cancel = true during polling of token endpoint during device code flow
503
- */
504
- static createDeviceCodeCancelledError(): ClientAuthError {
505
- return new ClientAuthError(
506
- ClientAuthErrorMessage.DeviceCodePollingCancelled.code,
507
- `${ClientAuthErrorMessage.DeviceCodePollingCancelled.desc}`
508
- );
509
- }
510
-
511
- /**
512
- * Throws error if device code is expired
513
- */
514
- static createDeviceCodeExpiredError(): ClientAuthError {
515
- return new ClientAuthError(
516
- ClientAuthErrorMessage.DeviceCodeExpired.code,
517
- `${ClientAuthErrorMessage.DeviceCodeExpired.desc}`
518
- );
519
- }
520
-
521
- /**
522
- * Throws error if device code is expired
523
- */
524
- static createDeviceCodeUnknownError(): ClientAuthError {
525
- return new ClientAuthError(
526
- ClientAuthErrorMessage.DeviceCodeUnknownError.code,
527
- `${ClientAuthErrorMessage.DeviceCodeUnknownError.desc}`
528
- );
529
- }
530
-
531
- /**
532
- * Throws error when silent requests are made without an account object
533
- */
534
- static createNoAccountInSilentRequestError(): ClientAuthError {
535
- return new ClientAuthError(
536
- ClientAuthErrorMessage.NoAccountInSilentRequest.code,
537
- `${ClientAuthErrorMessage.NoAccountInSilentRequest.desc}`
538
- );
539
- }
540
-
541
- /**
542
- * Throws error when cache record is null or undefined.
543
- */
544
- static createNullOrUndefinedCacheRecord(): ClientAuthError {
545
- return new ClientAuthError(
546
- ClientAuthErrorMessage.invalidCacheRecord.code,
547
- ClientAuthErrorMessage.invalidCacheRecord.desc
548
- );
549
- }
550
-
551
- /**
552
- * Throws error when provided environment is not part of the CloudDiscoveryMetadata object
553
- */
554
- static createInvalidCacheEnvironmentError(): ClientAuthError {
555
- return new ClientAuthError(
556
- ClientAuthErrorMessage.invalidCacheEnvironment.code,
557
- ClientAuthErrorMessage.invalidCacheEnvironment.desc
558
- );
559
- }
560
-
561
- /**
562
- * Throws error when account is not found in cache.
563
- */
564
- static createNoAccountFoundError(): ClientAuthError {
565
- return new ClientAuthError(
566
- ClientAuthErrorMessage.noAccountFound.code,
567
- ClientAuthErrorMessage.noAccountFound.desc
568
- );
569
- }
570
-
571
- /**
572
- * Throws error if ICachePlugin not set on CacheManager.
573
- */
574
- static createCachePluginError(): ClientAuthError {
575
- return new ClientAuthError(
576
- ClientAuthErrorMessage.CachePluginError.code,
577
- `${ClientAuthErrorMessage.CachePluginError.desc}`
578
- );
579
- }
580
-
581
- /**
582
- * Throws error if crypto object not found.
583
- * @param operationName
584
- */
585
- static createNoCryptoObjectError(operationName: string): ClientAuthError {
586
- return new ClientAuthError(
587
- ClientAuthErrorMessage.noCryptoObj.code,
588
- `${ClientAuthErrorMessage.noCryptoObj.desc}${operationName}`
589
- );
590
- }
591
-
592
- /**
593
- * Throws error if cache type is invalid.
594
- */
595
- static createInvalidCacheTypeError(): ClientAuthError {
596
- return new ClientAuthError(
597
- ClientAuthErrorMessage.invalidCacheType.code,
598
- `${ClientAuthErrorMessage.invalidCacheType.desc}`
599
- );
600
- }
601
-
602
- /**
603
- * Throws error if unexpected account type.
604
- */
605
- static createUnexpectedAccountTypeError(): ClientAuthError {
606
- return new ClientAuthError(
607
- ClientAuthErrorMessage.unexpectedAccountType.code,
608
- `${ClientAuthErrorMessage.unexpectedAccountType.desc}`
609
- );
610
- }
611
-
612
- /**
613
- * Throws error if unexpected credential type.
614
- */
615
- static createUnexpectedCredentialTypeError(): ClientAuthError {
616
- return new ClientAuthError(
617
- ClientAuthErrorMessage.unexpectedCredentialType.code,
618
- `${ClientAuthErrorMessage.unexpectedCredentialType.desc}`
619
- );
620
- }
621
-
622
- /**
623
- * Throws error if client assertion is not valid.
624
- */
625
- static createInvalidAssertionError(): ClientAuthError {
626
- return new ClientAuthError(
627
- ClientAuthErrorMessage.invalidAssertion.code,
628
- `${ClientAuthErrorMessage.invalidAssertion.desc}`
629
- );
630
- }
631
-
632
- /**
633
- * Throws error if client assertion is not valid.
634
- */
635
- static createInvalidCredentialError(): ClientAuthError {
636
- return new ClientAuthError(
637
- ClientAuthErrorMessage.invalidClientCredential.code,
638
- `${ClientAuthErrorMessage.invalidClientCredential.desc}`
639
- );
640
- }
641
-
642
- /**
643
- * Throws error if token cannot be retrieved from cache due to refresh being required.
644
- */
645
- static createRefreshRequiredError(): ClientAuthError {
646
- return new ClientAuthError(
647
- ClientAuthErrorMessage.tokenRefreshRequired.code,
648
- ClientAuthErrorMessage.tokenRefreshRequired.desc
649
- );
650
- }
651
-
652
- /**
653
- * Throws error if the user defined timeout is reached.
654
- */
655
- static createUserTimeoutReachedError(): ClientAuthError {
656
- return new ClientAuthError(
657
- ClientAuthErrorMessage.userTimeoutReached.code,
658
- ClientAuthErrorMessage.userTimeoutReached.desc
659
- );
660
- }
661
-
662
- /*
663
- * Throws error if token claims are not populated for a signed jwt generation
664
- */
665
- static createTokenClaimsRequiredError(): ClientAuthError {
666
- return new ClientAuthError(
667
- ClientAuthErrorMessage.tokenClaimsRequired.code,
668
- ClientAuthErrorMessage.tokenClaimsRequired.desc
669
- );
670
- }
671
-
672
- /**
673
- * Throws error when the authorization code is missing from the server response
674
- */
675
- static createNoAuthCodeInServerResponseError(): ClientAuthError {
676
- return new ClientAuthError(
677
- ClientAuthErrorMessage.noAuthorizationCodeFromServer.code,
678
- ClientAuthErrorMessage.noAuthorizationCodeFromServer.desc
679
- );
680
- }
681
-
682
- static createBindingKeyNotRemovedError(): ClientAuthError {
683
- return new ClientAuthError(
684
- ClientAuthErrorMessage.bindingKeyNotRemovedError.code,
685
- ClientAuthErrorMessage.bindingKeyNotRemovedError.desc
686
- );
687
- }
688
-
689
- /**
690
- * Thrown when logout is attempted for an authority that doesnt have an end_session_endpoint
691
- */
692
- static createLogoutNotSupportedError(): ClientAuthError {
693
- return new ClientAuthError(
694
- ClientAuthErrorMessage.logoutNotSupported.code,
695
- ClientAuthErrorMessage.logoutNotSupported.desc
696
- );
697
- }
698
-
699
- /**
700
- * Create an error when kid attribute is missing from a PoP token's cache record
701
- */
702
- static createKeyIdMissingError(): ClientAuthError {
703
- return new ClientAuthError(
704
- ClientAuthErrorMessage.keyIdMissing.code,
705
- ClientAuthErrorMessage.keyIdMissing.desc
706
- );
707
- }
708
-
709
- /**
710
- * Create an error when the client does not have network connectivity
711
- */
712
- static createNoNetworkConnectivityError(): ClientAuthError {
713
- return new ClientAuthError(
714
- ClientAuthErrorMessage.noNetworkConnectivity.code,
715
- ClientAuthErrorMessage.noNetworkConnectivity.desc
716
- );
717
- }
718
-
719
- /**
720
- * Create an error when the user cancels the flow
721
- */
722
- static createUserCanceledError(): ClientAuthError {
723
- return new ClientAuthError(
724
- ClientAuthErrorMessage.userCanceledError.code,
725
- ClientAuthErrorMessage.userCanceledError.desc
726
- );
727
- }
728
-
729
- /**
730
- * Creates an error for during acquireTokenByClientCredential when TenantId is set to "common" or "organizations"
731
- */
732
- static createMissingTenantIdError(): ClientAuthError {
733
- return new AuthError(
734
- ClientAuthErrorMessage.missingTenantIdError.code,
735
- ClientAuthErrorMessage.missingTenantIdError.desc
736
- );
737
- }
328
+ export function createClientAuthError(
329
+ errorCode: string,
330
+ additionalMessage?: string
331
+ ): ClientAuthError {
332
+ return new ClientAuthError(errorCode, additionalMessage);
738
333
  }