@azure/msal-node-extensions 1.0.0-alpha.9 → 1.0.0-beta.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 (117) hide show
  1. package/README.md +174 -8
  2. package/bin/arm64/dpapi.node +0 -0
  3. package/bin/ia32/dpapi.node +0 -0
  4. package/bin/x64/dpapi.node +0 -0
  5. package/dist/{dpapi-addon/Dpapi.d.ts → Dpapi.d.ts} +4 -4
  6. package/dist/Dpapi.esm.js +24 -0
  7. package/dist/Dpapi.esm.js.map +1 -0
  8. package/dist/Dpapi.js +24 -0
  9. package/dist/Dpapi.js.map +1 -0
  10. package/dist/broker/NativeBrokerPlugin.d.ts +20 -0
  11. package/dist/broker/NativeBrokerPlugin.esm.js +408 -0
  12. package/dist/broker/NativeBrokerPlugin.esm.js.map +1 -0
  13. package/dist/broker/NativeBrokerPlugin.js +410 -0
  14. package/dist/broker/NativeBrokerPlugin.js.map +1 -0
  15. package/dist/error/NativeAuthError.d.ts +6 -0
  16. package/dist/error/NativeAuthError.esm.js +20 -0
  17. package/dist/error/NativeAuthError.esm.js.map +1 -0
  18. package/dist/error/NativeAuthError.js +22 -0
  19. package/dist/error/NativeAuthError.js.map +1 -0
  20. package/dist/error/PersistenceError.esm.js +89 -0
  21. package/dist/error/PersistenceError.esm.js.map +1 -0
  22. package/{src/error/PersistenceError.ts → dist/error/PersistenceError.js} +23 -33
  23. package/dist/error/PersistenceError.js.map +1 -0
  24. package/dist/index.d.ts +1 -0
  25. package/dist/index.esm.js +12 -0
  26. package/dist/index.esm.js.map +1 -0
  27. package/dist/index.js +24 -6
  28. package/dist/index.js.map +1 -0
  29. package/dist/lock/CrossPlatformLock.esm.js +94 -0
  30. package/dist/lock/CrossPlatformLock.esm.js.map +1 -0
  31. package/dist/lock/CrossPlatformLock.js +96 -0
  32. package/dist/lock/CrossPlatformLock.js.map +1 -0
  33. package/dist/lock/CrossPlatformLockOptions.d.ts +1 -1
  34. package/dist/packageMetadata.d.ts +2 -0
  35. package/dist/packageMetadata.esm.js +8 -0
  36. package/dist/packageMetadata.esm.js.map +1 -0
  37. package/dist/packageMetadata.js +11 -0
  38. package/dist/packageMetadata.js.map +1 -0
  39. package/{src/persistence/BasePersistence.ts → dist/persistence/BasePersistence.esm.js} +18 -23
  40. package/dist/persistence/BasePersistence.esm.js.map +1 -0
  41. package/dist/persistence/BasePersistence.js +38 -0
  42. package/dist/persistence/BasePersistence.js.map +1 -0
  43. package/dist/persistence/DataProtectionScope.d.ts +5 -4
  44. package/{src/persistence/DataProtectionScope.ts → dist/persistence/DataProtectionScope.esm.js} +9 -5
  45. package/dist/persistence/DataProtectionScope.esm.js.map +1 -0
  46. package/dist/persistence/DataProtectionScope.js +26 -0
  47. package/dist/persistence/DataProtectionScope.js.map +1 -0
  48. package/dist/persistence/FilePersistence.d.ts +1 -0
  49. package/dist/persistence/FilePersistence.esm.js +173 -0
  50. package/dist/persistence/FilePersistence.esm.js.map +1 -0
  51. package/dist/persistence/FilePersistence.js +175 -0
  52. package/dist/persistence/FilePersistence.js.map +1 -0
  53. package/dist/persistence/FilePersistenceWithDataProtection.esm.js +84 -0
  54. package/dist/persistence/FilePersistenceWithDataProtection.esm.js.map +1 -0
  55. package/dist/persistence/FilePersistenceWithDataProtection.js +86 -0
  56. package/dist/persistence/FilePersistenceWithDataProtection.js.map +1 -0
  57. package/dist/persistence/IPersistenceConfiguration.d.ts +2 -0
  58. package/dist/persistence/KeychainPersistence.d.ts +2 -2
  59. package/dist/persistence/KeychainPersistence.esm.js +90 -0
  60. package/dist/persistence/KeychainPersistence.esm.js.map +1 -0
  61. package/dist/persistence/KeychainPersistence.js +92 -0
  62. package/dist/persistence/KeychainPersistence.js.map +1 -0
  63. package/dist/persistence/LibSecretPersistence.d.ts +2 -2
  64. package/dist/persistence/LibSecretPersistence.esm.js +91 -0
  65. package/dist/persistence/LibSecretPersistence.esm.js.map +1 -0
  66. package/dist/persistence/LibSecretPersistence.js +93 -0
  67. package/dist/persistence/LibSecretPersistence.js.map +1 -0
  68. package/dist/persistence/PersistenceCachePlugin.d.ts +1 -1
  69. package/{src/persistence/PersistenceCachePlugin.ts → dist/persistence/PersistenceCachePlugin.esm.js} +27 -34
  70. package/dist/persistence/PersistenceCachePlugin.esm.js.map +1 -0
  71. package/dist/persistence/PersistenceCachePlugin.js +101 -0
  72. package/dist/persistence/PersistenceCachePlugin.js.map +1 -0
  73. package/dist/persistence/PersistenceCreator.d.ts +1 -1
  74. package/dist/persistence/PersistenceCreator.esm.js +63 -0
  75. package/dist/persistence/PersistenceCreator.esm.js.map +1 -0
  76. package/dist/persistence/PersistenceCreator.js +65 -0
  77. package/dist/persistence/PersistenceCreator.js.map +1 -0
  78. package/dist/utils/Constants.d.ts +12 -5
  79. package/{src/utils/Constants.ts → dist/utils/Constants.esm.js} +17 -17
  80. package/dist/utils/Constants.esm.js.map +1 -0
  81. package/dist/utils/Constants.js +66 -0
  82. package/dist/utils/Constants.js.map +1 -0
  83. package/dist/utils/Environment.d.ts +1 -1
  84. package/{src/utils/Environment.ts → dist/utils/Environment.esm.js} +44 -49
  85. package/dist/utils/Environment.esm.js.map +1 -0
  86. package/dist/utils/Environment.js +96 -0
  87. package/dist/utils/Environment.js.map +1 -0
  88. package/dist/utils/TypeGuards.d.ts +5 -0
  89. package/dist/utils/TypeGuards.esm.js +16 -0
  90. package/dist/utils/TypeGuards.esm.js.map +1 -0
  91. package/dist/utils/TypeGuards.js +18 -0
  92. package/dist/utils/TypeGuards.js.map +1 -0
  93. package/package.json +70 -52
  94. package/CHANGELOG.json +0 -167
  95. package/binding.gyp +0 -29
  96. package/changelog.md +0 -77
  97. package/dist/msal-node-extensions.cjs.development.js +0 -902
  98. package/dist/msal-node-extensions.cjs.development.js.map +0 -1
  99. package/dist/msal-node-extensions.cjs.production.min.js +0 -2
  100. package/dist/msal-node-extensions.cjs.production.min.js.map +0 -1
  101. package/dist/msal-node-extensions.esm.js +0 -902
  102. package/dist/msal-node-extensions.esm.js.map +0 -1
  103. package/src/dpapi-addon/Dpapi.ts +0 -12
  104. package/src/dpapi-addon/dpapi_addon.h +0 -6
  105. package/src/dpapi-addon/dpapi_not_supported.cpp +0 -19
  106. package/src/dpapi-addon/dpapi_win.cpp +0 -114
  107. package/src/dpapi-addon/main.cpp +0 -32
  108. package/src/index.ts +0 -16
  109. package/src/lock/CrossPlatformLock.ts +0 -89
  110. package/src/lock/CrossPlatformLockOptions.ts +0 -15
  111. package/src/persistence/FilePersistence.ts +0 -140
  112. package/src/persistence/FilePersistenceWithDataProtection.ts +0 -92
  113. package/src/persistence/IPersistence.ts +0 -17
  114. package/src/persistence/IPersistenceConfiguration.ts +0 -14
  115. package/src/persistence/KeychainPersistence.ts +0 -86
  116. package/src/persistence/LibSecretPersistence.ts +0 -87
  117. package/src/persistence/PersistenceCreator.ts +0 -73
@@ -0,0 +1,92 @@
1
+ /*! @azure/msal-node-extensions v1.0.0-beta.0 2023-06-20 */
2
+ 'use strict';
3
+ 'use strict';
4
+
5
+ var keytar = require('keytar');
6
+ var FilePersistence = require('./FilePersistence.js');
7
+ var PersistenceError = require('../error/PersistenceError.js');
8
+ var path = require('path');
9
+ var BasePersistence = require('./BasePersistence.js');
10
+ var TypeGuards = require('../utils/TypeGuards.js');
11
+
12
+ /*
13
+ * Copyright (c) Microsoft Corporation. All rights reserved.
14
+ * Licensed under the MIT License.
15
+ */
16
+ /**
17
+ * Uses reads and writes passwords to macOS keychain
18
+ *
19
+ * serviceName: Identifier used as key for whatever value is stored
20
+ * accountName: Account under which password should be stored
21
+ */
22
+ class KeychainPersistence extends BasePersistence.BasePersistence {
23
+ constructor(filePersistence, serviceName, accountName) {
24
+ super();
25
+ this.filePersistence = filePersistence;
26
+ this.serviceName = serviceName;
27
+ this.accountName = accountName;
28
+ }
29
+ static async create(fileLocation, serviceName, accountName, loggerOptions) {
30
+ const filePersistence = await FilePersistence.FilePersistence.create(fileLocation, loggerOptions);
31
+ const persistence = new KeychainPersistence(filePersistence, serviceName, accountName);
32
+ return persistence;
33
+ }
34
+ async save(contents) {
35
+ try {
36
+ await keytar.setPassword(this.serviceName, this.accountName, contents);
37
+ }
38
+ catch (err) {
39
+ if (TypeGuards.isNodeError(err)) {
40
+ throw PersistenceError.PersistenceError.createKeychainPersistenceError(err.message);
41
+ }
42
+ else {
43
+ throw err;
44
+ }
45
+ }
46
+ // Write dummy data to update file mtime
47
+ await this.filePersistence.save("{}");
48
+ }
49
+ async load() {
50
+ try {
51
+ return await keytar.getPassword(this.serviceName, this.accountName);
52
+ }
53
+ catch (err) {
54
+ if (TypeGuards.isNodeError(err)) {
55
+ throw PersistenceError.PersistenceError.createKeychainPersistenceError(err.message);
56
+ }
57
+ else {
58
+ throw err;
59
+ }
60
+ }
61
+ }
62
+ async delete() {
63
+ try {
64
+ await this.filePersistence.delete();
65
+ return await keytar.deletePassword(this.serviceName, this.accountName);
66
+ }
67
+ catch (err) {
68
+ if (TypeGuards.isNodeError(err)) {
69
+ throw PersistenceError.PersistenceError.createKeychainPersistenceError(err.message);
70
+ }
71
+ else {
72
+ throw err;
73
+ }
74
+ }
75
+ }
76
+ async reloadNecessary(lastSync) {
77
+ return this.filePersistence.reloadNecessary(lastSync);
78
+ }
79
+ getFilePath() {
80
+ return this.filePersistence.getFilePath();
81
+ }
82
+ getLogger() {
83
+ return this.filePersistence.getLogger();
84
+ }
85
+ createForPersistenceValidation() {
86
+ const testCacheFileLocation = `${path.dirname(this.filePersistence.getFilePath())}/test.cache`;
87
+ return KeychainPersistence.create(testCacheFileLocation, "persistenceValidationServiceName", "persistencValidationAccountName");
88
+ }
89
+ }
90
+
91
+ exports.KeychainPersistence = KeychainPersistence;
92
+ //# sourceMappingURL=KeychainPersistence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeychainPersistence.js","sources":["../../src/persistence/KeychainPersistence.ts"],"sourcesContent":[null],"names":["BasePersistence","FilePersistence","setPassword","isNodeError","PersistenceError","getPassword","deletePassword","dirname"],"mappings":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* accountName: Account under which password should be stored
10
10
  */
11
11
  export declare class LibSecretPersistence extends BasePersistence implements IPersistence {
12
- protected readonly serviceName: any;
13
- protected readonly accountName: any;
12
+ protected readonly serviceName: string;
13
+ protected readonly accountName: string;
14
14
  private filePersistence;
15
15
  private constructor();
16
16
  static create(fileLocation: string, serviceName: string, accountName: string, loggerOptions?: LoggerOptions): Promise<LibSecretPersistence>;
@@ -0,0 +1,91 @@
1
+ /*! @azure/msal-node-extensions v1.0.0-beta.0 2023-06-20 */
2
+ 'use strict';
3
+ import { setPassword, getPassword, deletePassword } from 'keytar';
4
+ import { FilePersistence } from './FilePersistence.esm.js';
5
+ import { PersistenceError } from '../error/PersistenceError.esm.js';
6
+ import { dirname } from 'path';
7
+ import { BasePersistence } from './BasePersistence.esm.js';
8
+ import { isNodeError } from '../utils/TypeGuards.esm.js';
9
+
10
+ /*
11
+ * Copyright (c) Microsoft Corporation. All rights reserved.
12
+ * Licensed under the MIT License.
13
+ */
14
+ /**
15
+ * Uses reads and writes passwords to Secret Service API/libsecret. Requires libsecret
16
+ * to be installed.
17
+ *
18
+ * serviceName: Identifier used as key for whatever value is stored
19
+ * accountName: Account under which password should be stored
20
+ */
21
+ class LibSecretPersistence extends BasePersistence {
22
+ constructor(filePersistence, serviceName, accountName) {
23
+ super();
24
+ this.filePersistence = filePersistence;
25
+ this.serviceName = serviceName;
26
+ this.accountName = accountName;
27
+ }
28
+ static async create(fileLocation, serviceName, accountName, loggerOptions) {
29
+ const filePersistence = await FilePersistence.create(fileLocation, loggerOptions);
30
+ const persistence = new LibSecretPersistence(filePersistence, serviceName, accountName);
31
+ return persistence;
32
+ }
33
+ async save(contents) {
34
+ try {
35
+ await setPassword(this.serviceName, this.accountName, contents);
36
+ }
37
+ catch (err) {
38
+ if (isNodeError(err)) {
39
+ throw PersistenceError.createLibSecretError(err.message);
40
+ }
41
+ else {
42
+ throw err;
43
+ }
44
+ }
45
+ // Write dummy data to update file mtime
46
+ await this.filePersistence.save("{}");
47
+ }
48
+ async load() {
49
+ try {
50
+ return await getPassword(this.serviceName, this.accountName);
51
+ }
52
+ catch (err) {
53
+ if (isNodeError(err)) {
54
+ throw PersistenceError.createLibSecretError(err.message);
55
+ }
56
+ else {
57
+ throw err;
58
+ }
59
+ }
60
+ }
61
+ async delete() {
62
+ try {
63
+ await this.filePersistence.delete();
64
+ return await deletePassword(this.serviceName, this.accountName);
65
+ }
66
+ catch (err) {
67
+ if (isNodeError(err)) {
68
+ throw PersistenceError.createLibSecretError(err.message);
69
+ }
70
+ else {
71
+ throw err;
72
+ }
73
+ }
74
+ }
75
+ async reloadNecessary(lastSync) {
76
+ return this.filePersistence.reloadNecessary(lastSync);
77
+ }
78
+ getFilePath() {
79
+ return this.filePersistence.getFilePath();
80
+ }
81
+ getLogger() {
82
+ return this.filePersistence.getLogger();
83
+ }
84
+ createForPersistenceValidation() {
85
+ const testCacheFileLocation = `${dirname(this.filePersistence.getFilePath())}/test.cache`;
86
+ return LibSecretPersistence.create(testCacheFileLocation, "persistenceValidationServiceName", "persistencValidationAccountName");
87
+ }
88
+ }
89
+
90
+ export { LibSecretPersistence };
91
+ //# sourceMappingURL=LibSecretPersistence.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LibSecretPersistence.esm.js","sources":["../../src/persistence/LibSecretPersistence.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;AAAA;;;AAGG;AAWH;;;;;;AAMG;AACG,MAAO,oBAAqB,SAAQ,eAAe,CAAA;AAMrD,IAAA,WAAA,CAAoB,eAAgC,EAAE,WAAmB,EAAE,WAAmB,EAAA;AAC1F,QAAA,KAAK,EAAE,CAAC;AACR,QAAA,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;AACvC,QAAA,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;AAC/B,QAAA,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;KAClC;IAEM,aAAa,MAAM,CACtB,YAAoB,EACpB,WAAmB,EACnB,WAAmB,E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C,CAAC;AACnE,SAAA;AAAC,QAAA,OAAO,GAAG,EAAE;AACV,YAAA,IAAI,WAAW,CAAC,GAAG,CAAC,EAAE;gBAClB,MAAM,gBAAgB,CAAC,oBAAoB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAC5D,aAAA;AAAM,iBAAA;AACH,gBAAA,MAAM,GAAG,CAAC;AACb,aAAA;AACJ,SAAA;KACJ;IAEM,MAAM,eAAe,CAAC,QAAgB,EAAA;QACzC,OAAO,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;KACzD;IAEM,WAAW,GAAA;AACd,QAAA,OAAO,IAAI,CAAC,eAAe,CAAC,WAAW,EAAE,CAAC;KAC7C;IAEM,SAAS,GAAA;AACZ,QAAA,OAAO,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,CAAC;KAC3C;IAEM,8BAA8B,GAAA;AACjC,QAAA,MAAM,qBAAqB,GAAG,CAAG,EAAA,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,WAAW,EAAE,CAAC,aAAa,CAAC;QAC1F,OAAO,oBAAoB,CAAC,MAAM,CAC9B,qBAAqB,EACrB,kCAAkC,EAAE,iCAAiC,CACxE,CAAC;KACL;AACJ;;;;"}
@@ -0,0 +1,93 @@
1
+ /*! @azure/msal-node-extensions v1.0.0-beta.0 2023-06-20 */
2
+ 'use strict';
3
+ 'use strict';
4
+
5
+ var keytar = require('keytar');
6
+ var FilePersistence = require('./FilePersistence.js');
7
+ var PersistenceError = require('../error/PersistenceError.js');
8
+ var path = require('path');
9
+ var BasePersistence = require('./BasePersistence.js');
10
+ var TypeGuards = require('../utils/TypeGuards.js');
11
+
12
+ /*
13
+ * Copyright (c) Microsoft Corporation. All rights reserved.
14
+ * Licensed under the MIT License.
15
+ */
16
+ /**
17
+ * Uses reads and writes passwords to Secret Service API/libsecret. Requires libsecret
18
+ * to be installed.
19
+ *
20
+ * serviceName: Identifier used as key for whatever value is stored
21
+ * accountName: Account under which password should be stored
22
+ */
23
+ class LibSecretPersistence extends BasePersistence.BasePersistence {
24
+ constructor(filePersistence, serviceName, accountName) {
25
+ super();
26
+ this.filePersistence = filePersistence;
27
+ this.serviceName = serviceName;
28
+ this.accountName = accountName;
29
+ }
30
+ static async create(fileLocation, serviceName, accountName, loggerOptions) {
31
+ const filePersistence = await FilePersistence.FilePersistence.create(fileLocation, loggerOptions);
32
+ const persistence = new LibSecretPersistence(filePersistence, serviceName, accountName);
33
+ return persistence;
34
+ }
35
+ async save(contents) {
36
+ try {
37
+ await keytar.setPassword(this.serviceName, this.accountName, contents);
38
+ }
39
+ catch (err) {
40
+ if (TypeGuards.isNodeError(err)) {
41
+ throw PersistenceError.PersistenceError.createLibSecretError(err.message);
42
+ }
43
+ else {
44
+ throw err;
45
+ }
46
+ }
47
+ // Write dummy data to update file mtime
48
+ await this.filePersistence.save("{}");
49
+ }
50
+ async load() {
51
+ try {
52
+ return await keytar.getPassword(this.serviceName, this.accountName);
53
+ }
54
+ catch (err) {
55
+ if (TypeGuards.isNodeError(err)) {
56
+ throw PersistenceError.PersistenceError.createLibSecretError(err.message);
57
+ }
58
+ else {
59
+ throw err;
60
+ }
61
+ }
62
+ }
63
+ async delete() {
64
+ try {
65
+ await this.filePersistence.delete();
66
+ return await keytar.deletePassword(this.serviceName, this.accountName);
67
+ }
68
+ catch (err) {
69
+ if (TypeGuards.isNodeError(err)) {
70
+ throw PersistenceError.PersistenceError.createLibSecretError(err.message);
71
+ }
72
+ else {
73
+ throw err;
74
+ }
75
+ }
76
+ }
77
+ async reloadNecessary(lastSync) {
78
+ return this.filePersistence.reloadNecessary(lastSync);
79
+ }
80
+ getFilePath() {
81
+ return this.filePersistence.getFilePath();
82
+ }
83
+ getLogger() {
84
+ return this.filePersistence.getLogger();
85
+ }
86
+ createForPersistenceValidation() {
87
+ const testCacheFileLocation = `${path.dirname(this.filePersistence.getFilePath())}/test.cache`;
88
+ return LibSecretPersistence.create(testCacheFileLocation, "persistenceValidationServiceName", "persistencValidationAccountName");
89
+ }
90
+ }
91
+
92
+ exports.LibSecretPersistence = LibSecretPersistence;
93
+ //# sourceMappingURL=LibSecretPersistence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LibSecretPersistence.js","sources":["../../src/persistence/LibSecretPersistence.ts"],"sourcesContent":[null],"names":["BasePersistence","FilePersistence","setPassword","isNodeError","PersistenceError","getPassword","deletePassword","dirname"],"mappings":";;;;;;;;;;;AAAA;;;AAGG;AAWH;;;;;;AAMG;AACG,MAAO,oBAAqB,SAAQA,+BAAe,CAAA;AAMrD,IAAA,WAAA,CAAoB,eAAgC,EAAE,WAAmB,EAAE,WAAmB,EAAA;AAC1F,QAAA,KAAK,EAAE,CAAC;AACR,QAAA,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;AACvC,QAAA,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;AAC/B,QAAA,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;KAClC;IAEM,aAAa,MAAM,CACtB,YAAoB,EACpB,WAAmB,EACnB,WAAmB,EACnB,aAA6B,EAAA;QAE7B,MAAM,eAAe,GAAG,MAAMC,+BAAe,CAAC,MAAM,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;QAClF,MAAM,WAAW,GAAG,IAAI,oBAAoB,CAAC,eAAe,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;AACxF,QAAA,OAAO,WAAW,CAAC;KACtB;IAEM,MAAM,IAAI,CAAC,QAAgB,EAAA;QAC9B,IAAI;AACA,YAAA,MAAMC,kBAAW,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;AACnE,SAAA;AAAC,QAAA,OAAO,GAAG,EAAE;AACV,YAAA,IAAIC,sBAAW,CAAC,GAAG,CAAC,EAAE;gBAClB,MAAMC,iCAAgB,CAAC,oBAAoB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAC5D,aAAA;AAAM,iBAAA;AACH,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;AACjC,QAAA,MAAM,qBAAqB,GAAG,CAAG,EAAAG,YAAO,CAAC,IAAI,CAAC,eAAe,CAAC,WAAW,EAAE,CAAC,aAAa,CAAC;QAC1F,OAAO,oBAAoB,CAAC,MAAM,CAC9B,qBAAqB,EACrB,kCAAkC,EAAE,iCAAiC,CACxE,CAAC;KACL;AACJ;;;;"}
@@ -17,7 +17,7 @@ import { TokenCacheContext, ICachePlugin } from "@azure/msal-common";
17
17
  export declare class PersistenceCachePlugin implements ICachePlugin {
18
18
  persistence: IPersistence;
19
19
  lastSync: number;
20
- currentCache: string;
20
+ currentCache: string | null;
21
21
  lockFilePath: string;
22
22
  private crossPlatformLock;
23
23
  private logger;
@@ -1,14 +1,12 @@
1
+ /*! @azure/msal-node-extensions v1.0.0-beta.0 2023-06-20 */
2
+ 'use strict';
3
+ import { CrossPlatformLock } from '../lock/CrossPlatformLock.esm.js';
4
+ import { pid } from 'process';
5
+
1
6
  /*
2
7
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
8
  * Licensed under the MIT License.
4
9
  */
5
-
6
- import { IPersistence } from "./IPersistence";
7
- import { CrossPlatformLock } from "../lock/CrossPlatformLock";
8
- import { CrossPlatformLockOptions } from "../lock/CrossPlatformLockOptions";
9
- import { pid } from "process";
10
- import { TokenCacheContext, ICachePlugin, Logger } from "@azure/msal-common";
11
-
12
10
  /**
13
11
  * MSAL cache plugin which enables callers to write the MSAL cache to disk on Windows,
14
12
  * macOs, and Linux.
@@ -22,32 +20,18 @@ import { TokenCacheContext, ICachePlugin, Logger } from "@azure/msal-common";
22
20
  * - LibSecretPersistence: Used on linux, writes and reads from secret service API. Requires
23
21
  * libsecret be installed.
24
22
  */
25
- export class PersistenceCachePlugin implements ICachePlugin {
26
-
27
- public persistence: IPersistence;
28
- public lastSync: number;
29
- public currentCache: string;
30
- public lockFilePath: string;
31
-
32
- private crossPlatformLock: CrossPlatformLock;
33
-
34
- private logger: Logger;
35
-
36
- constructor(persistence: IPersistence, lockOptions?: CrossPlatformLockOptions) {
23
+ class PersistenceCachePlugin {
24
+ constructor(persistence, lockOptions) {
37
25
  this.persistence = persistence;
38
-
39
26
  // initialize logger
40
27
  this.logger = persistence.getLogger();
41
-
42
28
  // create file lock
43
29
  this.lockFilePath = `${this.persistence.getFilePath()}.lockfile`;
44
30
  this.crossPlatformLock = new CrossPlatformLock(this.lockFilePath, this.logger, lockOptions);
45
-
46
31
  // initialize default values
47
32
  this.lastSync = 0;
48
33
  this.currentCache = null;
49
34
  }
50
-
51
35
  /**
52
36
  * Reads from storage and saves an in-memory copy. If persistence has not been updated
53
37
  * since last time data was read, in memory copy is used.
@@ -56,7 +40,7 @@ export class PersistenceCachePlugin implements ICachePlugin {
56
40
  * afterCacheAccess() is called, to prevent the cache file from changing in between
57
41
  * beforeCacheAccess() and afterCacheAccess().
58
42
  */
59
- public async beforeCacheAccess(cacheContext: TokenCacheContext): Promise<void> {
43
+ async beforeCacheAccess(cacheContext) {
60
44
  this.logger.info("Executing before cache access");
61
45
  const reloadNecessary = await this.persistence.reloadNecessary(this.lastSync);
62
46
  if (!reloadNecessary && this.currentCache !== null) {
@@ -69,38 +53,47 @@ export class PersistenceCachePlugin implements ICachePlugin {
69
53
  try {
70
54
  this.logger.info(`Reload necessary. Last sync time: ${this.lastSync}`);
71
55
  await this.crossPlatformLock.lock();
72
-
73
56
  this.currentCache = await this.persistence.load();
74
57
  this.lastSync = new Date().getTime();
75
- cacheContext.tokenCache.deserialize(this.currentCache);
76
-
58
+ if (this.currentCache) {
59
+ cacheContext.tokenCache.deserialize(this.currentCache);
60
+ }
61
+ else {
62
+ this.logger.info("Cache empty.");
63
+ }
77
64
  this.logger.info(`Last sync time updated to: ${this.lastSync}`);
78
- } finally {
65
+ }
66
+ finally {
79
67
  if (!cacheContext.cacheHasChanged) {
80
68
  await this.crossPlatformLock.unlock();
81
69
  this.logger.info(`Pid ${pid} released lock`);
82
- } else {
70
+ }
71
+ else {
83
72
  this.logger.info(`Pid ${pid} beforeCacheAccess did not release lock`);
84
73
  }
85
74
  }
86
75
  }
87
-
88
76
  /**
89
77
  * Writes to storage if MSAL in memory copy of cache has been changed.
90
78
  */
91
- public async afterCacheAccess(cacheContext: TokenCacheContext): Promise<void> {
79
+ async afterCacheAccess(cacheContext) {
92
80
  this.logger.info("Executing after cache access");
93
81
  try {
94
82
  if (cacheContext.cacheHasChanged) {
95
83
  this.logger.info("Msal in-memory cache has changed. Writing changes to persistence");
96
84
  this.currentCache = cacheContext.tokenCache.serialize();
97
85
  await this.persistence.save(this.currentCache);
98
- } else {
86
+ }
87
+ else {
99
88
  this.logger.info("Msal in-memory cache has not changed. Did not write to persistence");
100
89
  }
101
- } finally {
90
+ }
91
+ finally {
102
92
  await this.crossPlatformLock.unlock();
103
93
  this.logger.info(`Pid ${pid} afterCacheAccess released lock`);
104
94
  }
105
95
  }
106
- }
96
+ }
97
+
98
+ export { PersistenceCachePlugin };
99
+ //# sourceMappingURL=PersistenceCachePlugin.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PersistenceCachePlugin.esm.js","sources":["../../src/persistence/PersistenceCachePlugin.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAAA;;;AAGG;AAQH;;;;;;;;;;;;AAYG;MACU,sBAAsB,CAAA;IAW/B,WAAY,CAAA,WAAyB,EAAE,WAAsC,EAAA;AACzE,QAAA,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;;AAG/B,QAAA,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,SAAS,EAAE,CAAC;;QAGtC,IAAI,CAAC,YAAY,GAAG,CAAG,EAAA,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,CAAA,SAAA,CAAW,CAAC;AACjE,QAAA,IAAI,CAAC,iBAAiB,GAAG,IAAI,iBAAiB,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;;AAG5F,QAAA,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;AA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N,YAAA,IAAI,CAAC,YAAY,CAAC,eAAe,EAAE;AAC/B,gBAAA,MAAM,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE,CAAC;gBACtC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAO,IAAA,EAAA,GAAG,CAAgB,cAAA,CAAA,CAAC,CAAC;AAChD,aAAA;AAAM,iBAAA;gBACH,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAO,IAAA,EAAA,GAAG,CAAyC,uCAAA,CAAA,CAAC,CAAC;AACzE,aAAA;AACJ,SAAA;KACJ;AAED;;AAEG;IACI,MAAM,gBAAgB,CAAC,YAA+B,EAAA;AACzD,QAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;QACjD,IAAI;YACA,IAAI,YAAY,CAAC,eAAe,EAAE;AAC9B,gBAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,kEAAkE,CAAC,CAAC;gBACrF,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC;gBACxD,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AAClD,aAAA;AAAM,iBAAA;AACH,gBAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,oEAAoE,CAAC,CAAC;AAC1F,aAAA;AACJ,SAAA;AAAS,gBAAA;AACN,YAAA,MAAM,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE,CAAC;YACtC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAO,IAAA,EAAA,GAAG,CAAiC,+BAAA,CAAA,CAAC,CAAC;AACjE,SAAA;KACJ;AACJ;;;;"}
@@ -0,0 +1,101 @@
1
+ /*! @azure/msal-node-extensions v1.0.0-beta.0 2023-06-20 */
2
+ 'use strict';
3
+ 'use strict';
4
+
5
+ var CrossPlatformLock = require('../lock/CrossPlatformLock.js');
6
+ var process = require('process');
7
+
8
+ /*
9
+ * Copyright (c) Microsoft Corporation. All rights reserved.
10
+ * Licensed under the MIT License.
11
+ */
12
+ /**
13
+ * MSAL cache plugin which enables callers to write the MSAL cache to disk on Windows,
14
+ * macOs, and Linux.
15
+ *
16
+ * - Persistence can be one of:
17
+ * - FilePersistence: Writes and reads from an unencrypted file. Can be used on Windows,
18
+ * macOs, or Linux.
19
+ * - FilePersistenceWithDataProtection: Used on Windows, writes and reads from file encrypted
20
+ * with windows dpapi-addon.
21
+ * - KeychainPersistence: Used on macOs, writes and reads from keychain.
22
+ * - LibSecretPersistence: Used on linux, writes and reads from secret service API. Requires
23
+ * libsecret be installed.
24
+ */
25
+ class PersistenceCachePlugin {
26
+ constructor(persistence, lockOptions) {
27
+ this.persistence = persistence;
28
+ // initialize logger
29
+ this.logger = persistence.getLogger();
30
+ // create file lock
31
+ this.lockFilePath = `${this.persistence.getFilePath()}.lockfile`;
32
+ this.crossPlatformLock = new CrossPlatformLock.CrossPlatformLock(this.lockFilePath, this.logger, lockOptions);
33
+ // initialize default values
34
+ this.lastSync = 0;
35
+ this.currentCache = null;
36
+ }
37
+ /**
38
+ * Reads from storage and saves an in-memory copy. If persistence has not been updated
39
+ * since last time data was read, in memory copy is used.
40
+ *
41
+ * If cacheContext.cacheHasChanged === true, then file lock is created and not deleted until
42
+ * afterCacheAccess() is called, to prevent the cache file from changing in between
43
+ * beforeCacheAccess() and afterCacheAccess().
44
+ */
45
+ async beforeCacheAccess(cacheContext) {
46
+ this.logger.info("Executing before cache access");
47
+ const reloadNecessary = await this.persistence.reloadNecessary(this.lastSync);
48
+ if (!reloadNecessary && this.currentCache !== null) {
49
+ if (cacheContext.cacheHasChanged) {
50
+ this.logger.verbose("Cache context has changed");
51
+ await this.crossPlatformLock.lock();
52
+ }
53
+ return;
54
+ }
55
+ try {
56
+ this.logger.info(`Reload necessary. Last sync time: ${this.lastSync}`);
57
+ await this.crossPlatformLock.lock();
58
+ this.currentCache = await this.persistence.load();
59
+ this.lastSync = new Date().getTime();
60
+ if (this.currentCache) {
61
+ cacheContext.tokenCache.deserialize(this.currentCache);
62
+ }
63
+ else {
64
+ this.logger.info("Cache empty.");
65
+ }
66
+ this.logger.info(`Last sync time updated to: ${this.lastSync}`);
67
+ }
68
+ finally {
69
+ if (!cacheContext.cacheHasChanged) {
70
+ await this.crossPlatformLock.unlock();
71
+ this.logger.info(`Pid ${process.pid} released lock`);
72
+ }
73
+ else {
74
+ this.logger.info(`Pid ${process.pid} beforeCacheAccess did not release lock`);
75
+ }
76
+ }
77
+ }
78
+ /**
79
+ * Writes to storage if MSAL in memory copy of cache has been changed.
80
+ */
81
+ async afterCacheAccess(cacheContext) {
82
+ this.logger.info("Executing after cache access");
83
+ try {
84
+ if (cacheContext.cacheHasChanged) {
85
+ this.logger.info("Msal in-memory cache has changed. Writing changes to persistence");
86
+ this.currentCache = cacheContext.tokenCache.serialize();
87
+ await this.persistence.save(this.currentCache);
88
+ }
89
+ else {
90
+ this.logger.info("Msal in-memory cache has not changed. Did not write to persistence");
91
+ }
92
+ }
93
+ finally {
94
+ await this.crossPlatformLock.unlock();
95
+ this.logger.info(`Pid ${process.pid} afterCacheAccess released lock`);
96
+ }
97
+ }
98
+ }
99
+
100
+ exports.PersistenceCachePlugin = PersistenceCachePlugin;
101
+ //# sourceMappingURL=PersistenceCachePlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PersistenceCachePlugin.js","sources":["../../src/persistence/PersistenceCachePlugin.ts"],"sourcesContent":[null],"names":["CrossPlatformLock","pid"],"mappings":";;;;;;;AAAA;;;AAGG;AAQH;;;;;;;;;;;;AAYG;MACU,sBAAsB,CAAA;IAW/B,WAAY,CAAA,WAAyB,EAAE,WAAsC,EAAA;AACzE,QAAA,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;;AAG/B,QAAA,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,SAAS,EAAE,CAAC;;QAGtC,IAAI,CAAC,YAAY,GAAG,CAAG,EAAA,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AAO,IAAA,EAAAA,WAAG,CAAiC,+BAAA,CAAA,CAAC,CAAC;AACjE,SAAA;KACJ;AACJ;;;;"}
@@ -1,5 +1,5 @@
1
1
  import { IPersistence } from "./IPersistence";
2
- import { IPersistenceConfiguration } from "../persistence/IPersistenceConfiguration";
2
+ import { IPersistenceConfiguration } from "./IPersistenceConfiguration";
3
3
  export declare class PersistenceCreator {
4
4
  static createPersistence(config: IPersistenceConfiguration): Promise<IPersistence>;
5
5
  }
@@ -0,0 +1,63 @@
1
+ /*! @azure/msal-node-extensions v1.0.0-beta.0 2023-06-20 */
2
+ 'use strict';
3
+ import { FilePersistenceWithDataProtection } from './FilePersistenceWithDataProtection.esm.js';
4
+ import { LibSecretPersistence } from './LibSecretPersistence.esm.js';
5
+ import { KeychainPersistence } from './KeychainPersistence.esm.js';
6
+ import { DataProtectionScope } from './DataProtectionScope.esm.js';
7
+ import { Environment } from '../utils/Environment.esm.js';
8
+ import { FilePersistence } from './FilePersistence.esm.js';
9
+ import { PersistenceError } from '../error/PersistenceError.esm.js';
10
+
11
+ /*
12
+ * Copyright (c) Microsoft Corporation. All rights reserved.
13
+ * Licensed under the MIT License.
14
+ */
15
+ class PersistenceCreator {
16
+ static async createPersistence(config) {
17
+ let peristence;
18
+ // On Windows, uses a DPAPI encrypted file
19
+ if (Environment.isWindowsPlatform()) {
20
+ if (!config.cachePath || !config.dataProtectionScope) {
21
+ throw PersistenceError.createPersistenceNotValidatedError("Cache path and/or data protection scope not provided for the FilePersistenceWithDataProtection cache plugin");
22
+ }
23
+ peristence = await FilePersistenceWithDataProtection.create(config.cachePath, DataProtectionScope.CurrentUser, undefined, config.loggerOptions);
24
+ }
25
+ // On Mac, uses keychain.
26
+ else if (Environment.isMacPlatform()) {
27
+ if (!config.cachePath || !config.serviceName || !config.accountName) {
28
+ throw PersistenceError.createPersistenceNotValidatedError("Cache path, service name and/or account name not provided for the KeychainPersistence cache plugin");
29
+ }
30
+ peristence = await KeychainPersistence.create(config.cachePath, config.serviceName, config.accountName, config.loggerOptions);
31
+ }
32
+ // On Linux, uses libsecret to store to secret service. Libsecret has to be installed.
33
+ else if (Environment.isLinuxPlatform()) {
34
+ if (!config.cachePath || !config.serviceName || !config.accountName) {
35
+ throw PersistenceError.createPersistenceNotValidatedError("Cache path, service name and/or account name not provided for the LibSecretPersistence cache plugin");
36
+ }
37
+ peristence = await LibSecretPersistence.create(config.cachePath, config.serviceName, config.accountName, config.loggerOptions);
38
+ }
39
+ else {
40
+ throw PersistenceError.createNotSupportedError("The current environment is not supported by msal-node-extensions yet.");
41
+ }
42
+ await peristence.verifyPersistence().catch(async (e) => {
43
+ if (Environment.isLinuxPlatform() && config.usePlaintextFileOnLinux) {
44
+ if (!config.cachePath) {
45
+ throw PersistenceError.createPersistenceNotValidatedError("Cache path not provided for the FilePersistence cache plugin");
46
+ }
47
+ peristence = await FilePersistence.create(config.cachePath, config.loggerOptions);
48
+ const isFilePersistenceVerified = await peristence.verifyPersistence();
49
+ if (isFilePersistenceVerified) {
50
+ return peristence;
51
+ }
52
+ throw PersistenceError.createPersistenceNotVerifiedError("Persistence could not be verified");
53
+ }
54
+ else {
55
+ throw e;
56
+ }
57
+ });
58
+ return peristence;
59
+ }
60
+ }
61
+
62
+ export { PersistenceCreator };
63
+ //# sourceMappingURL=PersistenceCreator.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PersistenceCreator.esm.js","sources":["../../src/persistence/PersistenceCreator.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;AAAA;;;AAGG;MAYU,kBAAkB,CAAA;AAC3B,IAAA,aAAa,iBAAiB,CAAC,MAAiC,EAAA;AAC5D,QAAA,IAAI,UAAwB,CAAC;;AAG7B,QAAA,IAAI,WAAW,CAAC,iBAAiB,EAAE,EAAE;YACjC,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,MAAM,CAAC,mBAAmB,EAAE;AAClD,gBAAA,MAAM,gBAAgB,CAAC,kCAAkC,CACrD,6G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