@azure/msal-node 2.0.1 → 2.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 (193) hide show
  1. package/README.md +3 -1
  2. package/dist/cache/NodeStorage.cjs +1 -1
  3. package/dist/cache/NodeStorage.cjs.map +1 -1
  4. package/dist/cache/NodeStorage.d.ts +1 -1
  5. package/dist/cache/NodeStorage.d.ts.map +1 -1
  6. package/dist/cache/NodeStorage.mjs +1 -1
  7. package/dist/cache/NodeStorage.mjs.map +1 -1
  8. package/dist/cache/TokenCache.cjs +5 -9
  9. package/dist/cache/TokenCache.cjs.map +1 -1
  10. package/dist/cache/TokenCache.d.ts +3 -3
  11. package/dist/cache/TokenCache.d.ts.map +1 -1
  12. package/dist/cache/TokenCache.mjs +6 -10
  13. package/dist/cache/TokenCache.mjs.map +1 -1
  14. package/dist/cache/distributed/DistributedCachePlugin.cjs +1 -1
  15. package/dist/cache/distributed/DistributedCachePlugin.cjs.map +1 -1
  16. package/dist/cache/distributed/DistributedCachePlugin.d.ts +2 -2
  17. package/dist/cache/distributed/DistributedCachePlugin.d.ts.map +1 -1
  18. package/dist/cache/distributed/DistributedCachePlugin.mjs +1 -1
  19. package/dist/cache/distributed/DistributedCachePlugin.mjs.map +1 -1
  20. package/dist/cache/serializer/Deserializer.cjs +2 -4
  21. package/dist/cache/serializer/Deserializer.cjs.map +1 -1
  22. package/dist/cache/serializer/Deserializer.d.ts +1 -1
  23. package/dist/cache/serializer/Deserializer.d.ts.map +1 -1
  24. package/dist/cache/serializer/Deserializer.mjs +3 -5
  25. package/dist/cache/serializer/Deserializer.mjs.map +1 -1
  26. package/dist/cache/serializer/Serializer.cjs +1 -1
  27. package/dist/cache/serializer/Serializer.cjs.map +1 -1
  28. package/dist/cache/serializer/Serializer.d.ts +1 -1
  29. package/dist/cache/serializer/Serializer.d.ts.map +1 -1
  30. package/dist/cache/serializer/Serializer.mjs +1 -1
  31. package/dist/cache/serializer/Serializer.mjs.map +1 -1
  32. package/dist/client/ClientApplication.cjs +2 -2
  33. package/dist/client/ClientApplication.cjs.map +1 -1
  34. package/dist/client/ClientApplication.d.ts +10 -10
  35. package/dist/client/ClientApplication.d.ts.map +1 -1
  36. package/dist/client/ClientApplication.mjs +2 -2
  37. package/dist/client/ClientApplication.mjs.map +1 -1
  38. package/dist/client/ClientAssertion.cjs +3 -3
  39. package/dist/client/ClientAssertion.cjs.map +1 -1
  40. package/dist/client/ClientAssertion.d.ts +1 -1
  41. package/dist/client/ClientAssertion.d.ts.map +1 -1
  42. package/dist/client/ClientAssertion.mjs +3 -3
  43. package/dist/client/ClientAssertion.mjs.map +1 -1
  44. package/dist/client/ClientCredentialClient.cjs +26 -4
  45. package/dist/client/ClientCredentialClient.cjs.map +1 -1
  46. package/dist/client/ClientCredentialClient.d.ts +1 -0
  47. package/dist/client/ClientCredentialClient.d.ts.map +1 -1
  48. package/dist/client/ClientCredentialClient.mjs +27 -5
  49. package/dist/client/ClientCredentialClient.mjs.map +1 -1
  50. package/dist/client/ConfidentialClientApplication.cjs +4 -5
  51. package/dist/client/ConfidentialClientApplication.cjs.map +1 -1
  52. package/dist/client/ConfidentialClientApplication.d.ts +5 -5
  53. package/dist/client/ConfidentialClientApplication.d.ts.map +1 -1
  54. package/dist/client/ConfidentialClientApplication.mjs +5 -6
  55. package/dist/client/ConfidentialClientApplication.mjs.map +1 -1
  56. package/dist/client/DeviceCodeClient.cjs +3 -3
  57. package/dist/client/DeviceCodeClient.cjs.map +1 -1
  58. package/dist/client/DeviceCodeClient.d.ts.map +1 -1
  59. package/dist/client/DeviceCodeClient.mjs +4 -4
  60. package/dist/client/DeviceCodeClient.mjs.map +1 -1
  61. package/dist/client/IConfidentialClientApplication.d.ts +8 -8
  62. package/dist/client/IConfidentialClientApplication.d.ts.map +1 -1
  63. package/dist/client/IPublicClientApplication.d.ts +9 -9
  64. package/dist/client/IPublicClientApplication.d.ts.map +1 -1
  65. package/dist/client/OnBehalfOfClient.cjs +7 -8
  66. package/dist/client/OnBehalfOfClient.cjs.map +1 -1
  67. package/dist/client/OnBehalfOfClient.d.ts.map +1 -1
  68. package/dist/client/OnBehalfOfClient.mjs +7 -8
  69. package/dist/client/OnBehalfOfClient.mjs.map +1 -1
  70. package/dist/client/PublicClientApplication.cjs +36 -29
  71. package/dist/client/PublicClientApplication.cjs.map +1 -1
  72. package/dist/client/PublicClientApplication.d.ts +7 -7
  73. package/dist/client/PublicClientApplication.d.ts.map +1 -1
  74. package/dist/client/PublicClientApplication.mjs +40 -33
  75. package/dist/client/PublicClientApplication.mjs.map +1 -1
  76. package/dist/client/UsernamePasswordClient.cjs +2 -2
  77. package/dist/client/UsernamePasswordClient.cjs.map +1 -1
  78. package/dist/client/UsernamePasswordClient.d.ts.map +1 -1
  79. package/dist/client/UsernamePasswordClient.mjs +2 -2
  80. package/dist/client/UsernamePasswordClient.mjs.map +1 -1
  81. package/dist/config/Configuration.cjs +2 -2
  82. package/dist/config/Configuration.cjs.map +1 -1
  83. package/dist/config/Configuration.d.ts +5 -4
  84. package/dist/config/Configuration.d.ts.map +1 -1
  85. package/dist/config/Configuration.mjs +2 -2
  86. package/dist/config/Configuration.mjs.map +1 -1
  87. package/dist/crypto/CryptoProvider.cjs +1 -1
  88. package/dist/crypto/CryptoProvider.cjs.map +1 -1
  89. package/dist/crypto/CryptoProvider.mjs +1 -1
  90. package/dist/crypto/CryptoProvider.mjs.map +1 -1
  91. package/dist/crypto/GuidGenerator.cjs +1 -1
  92. package/dist/crypto/GuidGenerator.cjs.map +1 -1
  93. package/dist/crypto/GuidGenerator.mjs +1 -1
  94. package/dist/crypto/GuidGenerator.mjs.map +1 -1
  95. package/dist/crypto/HashUtils.cjs +1 -1
  96. package/dist/crypto/HashUtils.cjs.map +1 -1
  97. package/dist/crypto/HashUtils.mjs +1 -1
  98. package/dist/crypto/HashUtils.mjs.map +1 -1
  99. package/dist/crypto/PkceGenerator.cjs +1 -1
  100. package/dist/crypto/PkceGenerator.cjs.map +1 -1
  101. package/dist/crypto/PkceGenerator.mjs +1 -1
  102. package/dist/crypto/PkceGenerator.mjs.map +1 -1
  103. package/dist/error/NodeAuthError.cjs +1 -1
  104. package/dist/error/NodeAuthError.cjs.map +1 -1
  105. package/dist/error/NodeAuthError.mjs +1 -1
  106. package/dist/error/NodeAuthError.mjs.map +1 -1
  107. package/dist/index.cjs +1 -1
  108. package/dist/index.d.ts +32 -31
  109. package/dist/index.d.ts.map +1 -1
  110. package/dist/index.mjs +1 -1
  111. package/dist/internals.cjs +1 -1
  112. package/dist/internals.cjs.map +1 -1
  113. package/dist/internals.d.ts +2 -2
  114. package/dist/internals.d.ts.map +1 -1
  115. package/dist/internals.mjs +1 -1
  116. package/dist/internals.mjs.map +1 -1
  117. package/dist/network/HttpClient.cjs +10 -9
  118. package/dist/network/HttpClient.cjs.map +1 -1
  119. package/dist/network/HttpClient.d.ts.map +1 -1
  120. package/dist/network/HttpClient.mjs +3 -2
  121. package/dist/network/HttpClient.mjs.map +1 -1
  122. package/dist/network/LoopbackClient.cjs +2 -2
  123. package/dist/network/LoopbackClient.cjs.map +1 -1
  124. package/dist/network/LoopbackClient.d.ts +1 -1
  125. package/dist/network/LoopbackClient.d.ts.map +1 -1
  126. package/dist/network/LoopbackClient.mjs +5 -5
  127. package/dist/network/LoopbackClient.mjs.map +1 -1
  128. package/dist/packageMetadata.cjs +2 -2
  129. package/dist/packageMetadata.cjs.map +1 -1
  130. package/dist/packageMetadata.d.ts +1 -1
  131. package/dist/packageMetadata.mjs +2 -2
  132. package/dist/packageMetadata.mjs.map +1 -1
  133. package/dist/request/InteractiveRequest.d.ts +2 -2
  134. package/dist/request/InteractiveRequest.d.ts.map +1 -1
  135. package/dist/utils/Constants.cjs +1 -11
  136. package/dist/utils/Constants.cjs.map +1 -1
  137. package/dist/utils/Constants.d.ts +0 -10
  138. package/dist/utils/Constants.d.ts.map +1 -1
  139. package/dist/utils/Constants.mjs +2 -11
  140. package/dist/utils/Constants.mjs.map +1 -1
  141. package/dist/utils/EncodingUtils.cjs +1 -1
  142. package/dist/utils/EncodingUtils.cjs.map +1 -1
  143. package/dist/utils/EncodingUtils.mjs +1 -1
  144. package/dist/utils/EncodingUtils.mjs.map +1 -1
  145. package/dist/utils/NetworkUtils.cjs +1 -1
  146. package/dist/utils/NetworkUtils.cjs.map +1 -1
  147. package/dist/utils/NetworkUtils.mjs +1 -1
  148. package/dist/utils/NetworkUtils.mjs.map +1 -1
  149. package/package.json +9 -6
  150. package/src/cache/ITokenCache.ts +24 -0
  151. package/src/cache/NodeStorage.ts +533 -0
  152. package/src/cache/TokenCache.ts +358 -0
  153. package/src/cache/distributed/DistributedCachePlugin.ts +56 -0
  154. package/src/cache/distributed/ICacheClient.ts +23 -0
  155. package/src/cache/distributed/IPartitionManager.ts +35 -0
  156. package/src/cache/serializer/Deserializer.ts +218 -0
  157. package/src/cache/serializer/Serializer.ts +173 -0
  158. package/src/cache/serializer/SerializerTypes.ts +121 -0
  159. package/src/client/ClientApplication.ts +595 -0
  160. package/src/client/ClientAssertion.ts +160 -0
  161. package/src/client/ClientCredentialClient.ts +348 -0
  162. package/src/client/ConfidentialClientApplication.ts +261 -0
  163. package/src/client/DeviceCodeClient.ts +360 -0
  164. package/src/client/IConfidentialClientApplication.ts +72 -0
  165. package/src/client/IPublicClientApplication.ts +72 -0
  166. package/src/client/OnBehalfOfClient.ts +361 -0
  167. package/src/client/PublicClientApplication.ts +283 -0
  168. package/src/client/UsernamePasswordClient.ts +180 -0
  169. package/src/config/Configuration.ts +201 -0
  170. package/src/crypto/CryptoProvider.ts +98 -0
  171. package/src/crypto/GuidGenerator.ts +28 -0
  172. package/src/crypto/HashUtils.ts +17 -0
  173. package/src/crypto/PkceGenerator.ts +63 -0
  174. package/src/error/NodeAuthError.ts +117 -0
  175. package/src/index.ts +121 -0
  176. package/src/internals.ts +12 -0
  177. package/src/network/HttpClient.ts +425 -0
  178. package/src/network/ILoopbackClient.ts +19 -0
  179. package/src/network/LoopbackClient.ts +126 -0
  180. package/src/packageMetadata.ts +3 -0
  181. package/src/request/AuthorizationCodeRequest.ts +39 -0
  182. package/src/request/AuthorizationUrlRequest.ts +50 -0
  183. package/src/request/ClientCredentialRequest.ts +29 -0
  184. package/src/request/DeviceCodeRequest.ts +34 -0
  185. package/src/request/InteractiveRequest.ts +39 -0
  186. package/src/request/OnBehalfOfRequest.ts +30 -0
  187. package/src/request/RefreshTokenRequest.ts +34 -0
  188. package/src/request/SignOutRequest.ts +11 -0
  189. package/src/request/SilentFlowRequest.ts +32 -0
  190. package/src/request/UsernamePasswordRequest.ts +36 -0
  191. package/src/utils/Constants.ts +103 -0
  192. package/src/utils/EncodingUtils.ts +50 -0
  193. package/src/utils/NetworkUtils.ts +49 -0
@@ -0,0 +1,173 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import {
7
+ AccountCache,
8
+ IdTokenCache,
9
+ AccessTokenCache,
10
+ RefreshTokenCache,
11
+ AppMetadataCache,
12
+ } from "@azure/msal-common";
13
+ import {
14
+ InMemoryCache,
15
+ JsonCache,
16
+ SerializedAccountEntity,
17
+ SerializedIdTokenEntity,
18
+ SerializedAccessTokenEntity,
19
+ SerializedRefreshTokenEntity,
20
+ SerializedAppMetadataEntity,
21
+ } from "./SerializerTypes.js";
22
+
23
+ export class Serializer {
24
+ /**
25
+ * serialize the JSON blob
26
+ * @param data
27
+ */
28
+ static serializeJSONBlob(data: JsonCache): string {
29
+ return JSON.stringify(data);
30
+ }
31
+
32
+ /**
33
+ * Serialize Accounts
34
+ * @param accCache
35
+ */
36
+ static serializeAccounts(
37
+ accCache: AccountCache
38
+ ): Record<string, SerializedAccountEntity> {
39
+ const accounts: Record<string, SerializedAccountEntity> = {};
40
+ Object.keys(accCache).map(function (key) {
41
+ const accountEntity = accCache[key];
42
+ accounts[key] = {
43
+ home_account_id: accountEntity.homeAccountId,
44
+ environment: accountEntity.environment,
45
+ realm: accountEntity.realm,
46
+ local_account_id: accountEntity.localAccountId,
47
+ username: accountEntity.username,
48
+ authority_type: accountEntity.authorityType,
49
+ name: accountEntity.name,
50
+ client_info: accountEntity.clientInfo,
51
+ last_modification_time: accountEntity.lastModificationTime,
52
+ last_modification_app: accountEntity.lastModificationApp,
53
+ };
54
+ });
55
+
56
+ return accounts;
57
+ }
58
+
59
+ /**
60
+ * Serialize IdTokens
61
+ * @param idTCache
62
+ */
63
+ static serializeIdTokens(
64
+ idTCache: IdTokenCache
65
+ ): Record<string, SerializedIdTokenEntity> {
66
+ const idTokens: Record<string, SerializedIdTokenEntity> = {};
67
+ Object.keys(idTCache).map(function (key) {
68
+ const idTEntity = idTCache[key];
69
+ idTokens[key] = {
70
+ home_account_id: idTEntity.homeAccountId,
71
+ environment: idTEntity.environment,
72
+ credential_type: idTEntity.credentialType,
73
+ client_id: idTEntity.clientId,
74
+ secret: idTEntity.secret,
75
+ realm: idTEntity.realm,
76
+ };
77
+ });
78
+
79
+ return idTokens;
80
+ }
81
+
82
+ /**
83
+ * Serializes AccessTokens
84
+ * @param atCache
85
+ */
86
+ static serializeAccessTokens(
87
+ atCache: AccessTokenCache
88
+ ): Record<string, SerializedAccessTokenEntity> {
89
+ const accessTokens: Record<string, SerializedAccessTokenEntity> = {};
90
+ Object.keys(atCache).map(function (key) {
91
+ const atEntity = atCache[key];
92
+ accessTokens[key] = {
93
+ home_account_id: atEntity.homeAccountId,
94
+ environment: atEntity.environment,
95
+ credential_type: atEntity.credentialType,
96
+ client_id: atEntity.clientId,
97
+ secret: atEntity.secret,
98
+ realm: atEntity.realm,
99
+ target: atEntity.target,
100
+ cached_at: atEntity.cachedAt,
101
+ expires_on: atEntity.expiresOn,
102
+ extended_expires_on: atEntity.extendedExpiresOn,
103
+ refresh_on: atEntity.refreshOn,
104
+ key_id: atEntity.keyId,
105
+ token_type: atEntity.tokenType,
106
+ requestedClaims: atEntity.requestedClaims,
107
+ requestedClaimsHash: atEntity.requestedClaimsHash,
108
+ userAssertionHash: atEntity.userAssertionHash,
109
+ };
110
+ });
111
+
112
+ return accessTokens;
113
+ }
114
+
115
+ /**
116
+ * Serialize refreshTokens
117
+ * @param rtCache
118
+ */
119
+ static serializeRefreshTokens(
120
+ rtCache: RefreshTokenCache
121
+ ): Record<string, SerializedRefreshTokenEntity> {
122
+ const refreshTokens: Record<string, SerializedRefreshTokenEntity> = {};
123
+ Object.keys(rtCache).map(function (key) {
124
+ const rtEntity = rtCache[key];
125
+ refreshTokens[key] = {
126
+ home_account_id: rtEntity.homeAccountId,
127
+ environment: rtEntity.environment,
128
+ credential_type: rtEntity.credentialType,
129
+ client_id: rtEntity.clientId,
130
+ secret: rtEntity.secret,
131
+ family_id: rtEntity.familyId,
132
+ target: rtEntity.target,
133
+ realm: rtEntity.realm,
134
+ };
135
+ });
136
+
137
+ return refreshTokens;
138
+ }
139
+
140
+ /**
141
+ * Serialize amdtCache
142
+ * @param amdtCache
143
+ */
144
+ static serializeAppMetadata(
145
+ amdtCache: AppMetadataCache
146
+ ): Record<string, SerializedAppMetadataEntity> {
147
+ const appMetadata: Record<string, SerializedAppMetadataEntity> = {};
148
+ Object.keys(amdtCache).map(function (key) {
149
+ const amdtEntity = amdtCache[key];
150
+ appMetadata[key] = {
151
+ client_id: amdtEntity.clientId,
152
+ environment: amdtEntity.environment,
153
+ family_id: amdtEntity.familyId,
154
+ };
155
+ });
156
+
157
+ return appMetadata;
158
+ }
159
+
160
+ /**
161
+ * Serialize the cache
162
+ * @param jsonContent
163
+ */
164
+ static serializeAllCache(inMemCache: InMemoryCache): JsonCache {
165
+ return {
166
+ Account: this.serializeAccounts(inMemCache.accounts),
167
+ IdToken: this.serializeIdTokens(inMemCache.idTokens),
168
+ AccessToken: this.serializeAccessTokens(inMemCache.accessTokens),
169
+ RefreshToken: this.serializeRefreshTokens(inMemCache.refreshTokens),
170
+ AppMetadata: this.serializeAppMetadata(inMemCache.appMetadata),
171
+ };
172
+ }
173
+ }
@@ -0,0 +1,121 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import {
7
+ AccountCache,
8
+ IdTokenCache,
9
+ AccessTokenCache,
10
+ RefreshTokenCache,
11
+ AppMetadataCache,
12
+ ValidCacheType,
13
+ } from "@azure/msal-common";
14
+
15
+ /**
16
+ * Key value store for in-memory cache
17
+ * @public
18
+ */
19
+ export type CacheKVStore = Record<string, ValidCacheType>;
20
+
21
+ /**
22
+ * Cache format read from the cache blob provided to the configuration during app instantiation
23
+ * @public
24
+ */
25
+ export type JsonCache = {
26
+ Account: Record<string, SerializedAccountEntity>;
27
+ IdToken: Record<string, SerializedIdTokenEntity>;
28
+ AccessToken: Record<string, SerializedAccessTokenEntity>;
29
+ RefreshToken: Record<string, SerializedRefreshTokenEntity>;
30
+ AppMetadata: Record<string, SerializedAppMetadataEntity>;
31
+ };
32
+
33
+ /**
34
+ * Intermittent type to handle in-memory data objects with defined types
35
+ * @public
36
+ */
37
+ export type InMemoryCache = {
38
+ accounts: AccountCache;
39
+ idTokens: IdTokenCache;
40
+ accessTokens: AccessTokenCache;
41
+ refreshTokens: RefreshTokenCache;
42
+ appMetadata: AppMetadataCache;
43
+ };
44
+
45
+ /**
46
+ * Account type
47
+ * @public
48
+ */
49
+ export type SerializedAccountEntity = {
50
+ home_account_id: string;
51
+ environment: string;
52
+ realm: string;
53
+ local_account_id: string;
54
+ username: string;
55
+ authority_type: string;
56
+ name?: string;
57
+ client_info?: string;
58
+ last_modification_time?: string;
59
+ last_modification_app?: string;
60
+ };
61
+
62
+ /**
63
+ * Idtoken credential type
64
+ * @public
65
+ */
66
+ export type SerializedIdTokenEntity = {
67
+ home_account_id: string;
68
+ environment: string;
69
+ credential_type: string;
70
+ client_id: string;
71
+ secret: string;
72
+ realm: string;
73
+ };
74
+
75
+ /**
76
+ * Access token credential type
77
+ * @public
78
+ */
79
+ export type SerializedAccessTokenEntity = {
80
+ home_account_id: string;
81
+ environment: string;
82
+ credential_type: string;
83
+ client_id: string;
84
+ secret: string;
85
+ realm: string;
86
+ target: string;
87
+ cached_at: string;
88
+ expires_on: string;
89
+ extended_expires_on?: string;
90
+ refresh_on?: string;
91
+ key_id?: string;
92
+ token_type?: string;
93
+ requestedClaims?: string;
94
+ requestedClaimsHash?: string;
95
+ userAssertionHash?: string;
96
+ };
97
+
98
+ /**
99
+ * Refresh token credential type
100
+ * @public
101
+ */
102
+ export type SerializedRefreshTokenEntity = {
103
+ home_account_id: string;
104
+ environment: string;
105
+ credential_type: string;
106
+ client_id: string;
107
+ secret: string;
108
+ family_id?: string;
109
+ target?: string;
110
+ realm?: string;
111
+ };
112
+
113
+ /**
114
+ * AppMetadata type
115
+ * @public
116
+ */
117
+ export type SerializedAppMetadataEntity = {
118
+ client_id: string;
119
+ environment: string;
120
+ family_id?: string;
121
+ };