@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,173 @@
1
+ /*! @azure/msal-node-extensions v1.0.0-beta.0 2023-06-20 */
2
+ 'use strict';
3
+ import { promises } from 'fs';
4
+ import { dirname } from 'path';
5
+ import { ErrorCodes, Constants } from '../utils/Constants.esm.js';
6
+ import { PersistenceError } from '../error/PersistenceError.esm.js';
7
+ import { Logger, LogLevel } from '@azure/msal-common';
8
+ import { BasePersistence } from './BasePersistence.esm.js';
9
+ import { isNodeError } from '../utils/TypeGuards.esm.js';
10
+
11
+ /*
12
+ * Copyright (c) Microsoft Corporation. All rights reserved.
13
+ * Licensed under the MIT License.
14
+ */
15
+ /**
16
+ * Reads and writes data to file specified by file location. File contents are not
17
+ * encrypted.
18
+ *
19
+ * If file or directory has not been created, it FilePersistence.create() will create
20
+ * file and any directories in the path recursively.
21
+ */
22
+ class FilePersistence extends BasePersistence {
23
+ constructor(fileLocation, loggerOptions) {
24
+ super();
25
+ this.logger = new Logger(loggerOptions || FilePersistence.createDefaultLoggerOptions());
26
+ this.filePath = fileLocation;
27
+ }
28
+ static async create(fileLocation, loggerOptions) {
29
+ const filePersistence = new FilePersistence(fileLocation, loggerOptions);
30
+ await filePersistence.createCacheFile();
31
+ return filePersistence;
32
+ }
33
+ async save(contents) {
34
+ try {
35
+ await promises.writeFile(this.getFilePath(), contents, "utf-8");
36
+ }
37
+ catch (err) {
38
+ if (isNodeError(err)) {
39
+ throw PersistenceError.createFileSystemError(err.code || ErrorCodes.UNKNOWN, err.message);
40
+ }
41
+ else {
42
+ throw err;
43
+ }
44
+ }
45
+ }
46
+ async saveBuffer(contents) {
47
+ try {
48
+ await promises.writeFile(this.getFilePath(), contents);
49
+ }
50
+ catch (err) {
51
+ if (isNodeError(err)) {
52
+ throw PersistenceError.createFileSystemError(err.code || ErrorCodes.UNKNOWN, err.message);
53
+ }
54
+ else {
55
+ throw err;
56
+ }
57
+ }
58
+ }
59
+ async load() {
60
+ try {
61
+ return await promises.readFile(this.getFilePath(), "utf-8");
62
+ }
63
+ catch (err) {
64
+ if (isNodeError(err)) {
65
+ throw PersistenceError.createFileSystemError(err.code || ErrorCodes.UNKNOWN, err.message);
66
+ }
67
+ else {
68
+ throw err;
69
+ }
70
+ }
71
+ }
72
+ async loadBuffer() {
73
+ try {
74
+ return await promises.readFile(this.getFilePath());
75
+ }
76
+ catch (err) {
77
+ if (isNodeError(err)) {
78
+ throw PersistenceError.createFileSystemError(err.code || ErrorCodes.UNKNOWN, err.message);
79
+ }
80
+ else {
81
+ throw err;
82
+ }
83
+ }
84
+ }
85
+ async delete() {
86
+ try {
87
+ await promises.unlink(this.getFilePath());
88
+ return true;
89
+ }
90
+ catch (err) {
91
+ if (isNodeError(err)) {
92
+ if (err.code === Constants.ENOENT_ERROR) {
93
+ // file does not exist, so it was not deleted
94
+ this.logger.warning("Cache file does not exist, so it could not be deleted");
95
+ return false;
96
+ }
97
+ throw PersistenceError.createFileSystemError(err.code || ErrorCodes.UNKNOWN, err.message);
98
+ }
99
+ else {
100
+ throw err;
101
+ }
102
+ }
103
+ }
104
+ getFilePath() {
105
+ return this.filePath;
106
+ }
107
+ async reloadNecessary(lastSync) {
108
+ return lastSync < await this.timeLastModified();
109
+ }
110
+ getLogger() {
111
+ return this.logger;
112
+ }
113
+ createForPersistenceValidation() {
114
+ const testCacheFileLocation = `${dirname(this.filePath)}/test.cache`;
115
+ return FilePersistence.create(testCacheFileLocation);
116
+ }
117
+ static createDefaultLoggerOptions() {
118
+ return {
119
+ loggerCallback: () => {
120
+ // allow users to not set loggerCallback
121
+ },
122
+ piiLoggingEnabled: false,
123
+ logLevel: LogLevel.Info
124
+ };
125
+ }
126
+ async timeLastModified() {
127
+ try {
128
+ const stats = await promises.stat(this.filePath);
129
+ return stats.mtime.getTime();
130
+ }
131
+ catch (err) {
132
+ if (isNodeError(err)) {
133
+ if (err.code === Constants.ENOENT_ERROR) {
134
+ // file does not exist, so it's never been modified
135
+ this.logger.verbose("Cache file does not exist");
136
+ return 0;
137
+ }
138
+ throw PersistenceError.createFileSystemError(err.code || ErrorCodes.UNKNOWN, err.message);
139
+ }
140
+ else {
141
+ throw err;
142
+ }
143
+ }
144
+ }
145
+ async createCacheFile() {
146
+ await this.createFileDirectory();
147
+ // File is created only if it does not exist
148
+ const fileHandle = await promises.open(this.filePath, "a");
149
+ await fileHandle.close();
150
+ this.logger.info(`File created at ${this.filePath}`);
151
+ }
152
+ async createFileDirectory() {
153
+ try {
154
+ await promises.mkdir(dirname(this.filePath), { recursive: true });
155
+ }
156
+ catch (err) {
157
+ if (isNodeError(err)) {
158
+ if (err.code === Constants.EEXIST_ERROR) {
159
+ this.logger.info(`Directory ${dirname(this.filePath)} already exists`);
160
+ }
161
+ else {
162
+ throw PersistenceError.createFileSystemError(err.code || ErrorCodes.UNKNOWN, err.message);
163
+ }
164
+ }
165
+ else {
166
+ throw err;
167
+ }
168
+ }
169
+ }
170
+ }
171
+
172
+ export { FilePersistence };
173
+ //# sourceMappingURL=FilePersistence.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FilePersistence.esm.js","sources":["../../src/persistence/FilePersistence.ts"],"sourcesContent":[null],"names":["fs"],"mapp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AAC,IAAI,CAAC,QAAQ,CAAC,CAAA,gBAAA,CAAkB,CAAC,CAAC;AAC3E,iBAAA;AAAM,qBAAA;AACH,oBAAA,MAAM,gBAAgB,CAAC,qBAAqB,CAAC,GAAG,CAAC,IAAI,IAAI,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;AAC7F,iBAAA;AACJ,aAAA;AAAM,iBAAA;AACH,gBAAA,MAAM,GAAG,CAAC;AACb,aAAA;AACJ,SAAA;KACJ;AACJ;;;;"}
@@ -0,0 +1,175 @@
1
+ /*! @azure/msal-node-extensions v1.0.0-beta.0 2023-06-20 */
2
+ 'use strict';
3
+ 'use strict';
4
+
5
+ var fs = require('fs');
6
+ var path = require('path');
7
+ var Constants = require('../utils/Constants.js');
8
+ var PersistenceError = require('../error/PersistenceError.js');
9
+ var msalCommon = require('@azure/msal-common');
10
+ var BasePersistence = require('./BasePersistence.js');
11
+ var TypeGuards = require('../utils/TypeGuards.js');
12
+
13
+ /*
14
+ * Copyright (c) Microsoft Corporation. All rights reserved.
15
+ * Licensed under the MIT License.
16
+ */
17
+ /**
18
+ * Reads and writes data to file specified by file location. File contents are not
19
+ * encrypted.
20
+ *
21
+ * If file or directory has not been created, it FilePersistence.create() will create
22
+ * file and any directories in the path recursively.
23
+ */
24
+ class FilePersistence extends BasePersistence.BasePersistence {
25
+ constructor(fileLocation, loggerOptions) {
26
+ super();
27
+ this.logger = new msalCommon.Logger(loggerOptions || FilePersistence.createDefaultLoggerOptions());
28
+ this.filePath = fileLocation;
29
+ }
30
+ static async create(fileLocation, loggerOptions) {
31
+ const filePersistence = new FilePersistence(fileLocation, loggerOptions);
32
+ await filePersistence.createCacheFile();
33
+ return filePersistence;
34
+ }
35
+ async save(contents) {
36
+ try {
37
+ await fs.promises.writeFile(this.getFilePath(), contents, "utf-8");
38
+ }
39
+ catch (err) {
40
+ if (TypeGuards.isNodeError(err)) {
41
+ throw PersistenceError.PersistenceError.createFileSystemError(err.code || Constants.ErrorCodes.UNKNOWN, err.message);
42
+ }
43
+ else {
44
+ throw err;
45
+ }
46
+ }
47
+ }
48
+ async saveBuffer(contents) {
49
+ try {
50
+ await fs.promises.writeFile(this.getFilePath(), contents);
51
+ }
52
+ catch (err) {
53
+ if (TypeGuards.isNodeError(err)) {
54
+ throw PersistenceError.PersistenceError.createFileSystemError(err.code || Constants.ErrorCodes.UNKNOWN, err.message);
55
+ }
56
+ else {
57
+ throw err;
58
+ }
59
+ }
60
+ }
61
+ async load() {
62
+ try {
63
+ return await fs.promises.readFile(this.getFilePath(), "utf-8");
64
+ }
65
+ catch (err) {
66
+ if (TypeGuards.isNodeError(err)) {
67
+ throw PersistenceError.PersistenceError.createFileSystemError(err.code || Constants.ErrorCodes.UNKNOWN, err.message);
68
+ }
69
+ else {
70
+ throw err;
71
+ }
72
+ }
73
+ }
74
+ async loadBuffer() {
75
+ try {
76
+ return await fs.promises.readFile(this.getFilePath());
77
+ }
78
+ catch (err) {
79
+ if (TypeGuards.isNodeError(err)) {
80
+ throw PersistenceError.PersistenceError.createFileSystemError(err.code || Constants.ErrorCodes.UNKNOWN, err.message);
81
+ }
82
+ else {
83
+ throw err;
84
+ }
85
+ }
86
+ }
87
+ async delete() {
88
+ try {
89
+ await fs.promises.unlink(this.getFilePath());
90
+ return true;
91
+ }
92
+ catch (err) {
93
+ if (TypeGuards.isNodeError(err)) {
94
+ if (err.code === Constants.Constants.ENOENT_ERROR) {
95
+ // file does not exist, so it was not deleted
96
+ this.logger.warning("Cache file does not exist, so it could not be deleted");
97
+ return false;
98
+ }
99
+ throw PersistenceError.PersistenceError.createFileSystemError(err.code || Constants.ErrorCodes.UNKNOWN, err.message);
100
+ }
101
+ else {
102
+ throw err;
103
+ }
104
+ }
105
+ }
106
+ getFilePath() {
107
+ return this.filePath;
108
+ }
109
+ async reloadNecessary(lastSync) {
110
+ return lastSync < await this.timeLastModified();
111
+ }
112
+ getLogger() {
113
+ return this.logger;
114
+ }
115
+ createForPersistenceValidation() {
116
+ const testCacheFileLocation = `${path.dirname(this.filePath)}/test.cache`;
117
+ return FilePersistence.create(testCacheFileLocation);
118
+ }
119
+ static createDefaultLoggerOptions() {
120
+ return {
121
+ loggerCallback: () => {
122
+ // allow users to not set loggerCallback
123
+ },
124
+ piiLoggingEnabled: false,
125
+ logLevel: msalCommon.LogLevel.Info
126
+ };
127
+ }
128
+ async timeLastModified() {
129
+ try {
130
+ const stats = await fs.promises.stat(this.filePath);
131
+ return stats.mtime.getTime();
132
+ }
133
+ catch (err) {
134
+ if (TypeGuards.isNodeError(err)) {
135
+ if (err.code === Constants.Constants.ENOENT_ERROR) {
136
+ // file does not exist, so it's never been modified
137
+ this.logger.verbose("Cache file does not exist");
138
+ return 0;
139
+ }
140
+ throw PersistenceError.PersistenceError.createFileSystemError(err.code || Constants.ErrorCodes.UNKNOWN, err.message);
141
+ }
142
+ else {
143
+ throw err;
144
+ }
145
+ }
146
+ }
147
+ async createCacheFile() {
148
+ await this.createFileDirectory();
149
+ // File is created only if it does not exist
150
+ const fileHandle = await fs.promises.open(this.filePath, "a");
151
+ await fileHandle.close();
152
+ this.logger.info(`File created at ${this.filePath}`);
153
+ }
154
+ async createFileDirectory() {
155
+ try {
156
+ await fs.promises.mkdir(path.dirname(this.filePath), { recursive: true });
157
+ }
158
+ catch (err) {
159
+ if (TypeGuards.isNodeError(err)) {
160
+ if (err.code === Constants.Constants.EEXIST_ERROR) {
161
+ this.logger.info(`Directory ${path.dirname(this.filePath)} already exists`);
162
+ }
163
+ else {
164
+ throw PersistenceError.PersistenceError.createFileSystemError(err.code || Constants.ErrorCodes.UNKNOWN, err.message);
165
+ }
166
+ }
167
+ else {
168
+ throw err;
169
+ }
170
+ }
171
+ }
172
+ }
173
+
174
+ exports.FilePersistence = FilePersistence;
175
+ //# sourceMappingURL=FilePersistence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FilePersistence.js","sources":["../../src/persistence/FilePersistence.ts"],"sourcesContent":[null],"names":["BasePersistence","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AAI,KAAKG,mBAAS,CAAC,YAAY,EAAE;AACrC,oBAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAa,UAAA,EAAAC,YAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA,gBAAA,CAAkB,CAAC,CAAC;AAC3E,iBAAA;AAAM,qBAAA;AACH,oBAAA,MAAMH,iCAAgB,CAAC,qBAAqB,CAAC,GAAG,CAAC,IAAI,IAAIC,oBAAU,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;AAC7F,iBAAA;AACJ,aAAA;AAAM,iBAAA;AACH,gBAAA,MAAM,GAAG,CAAC;AACb,aAAA;AACJ,SAAA;KACJ;AACJ;;;;"}
@@ -0,0 +1,84 @@
1
+ /*! @azure/msal-node-extensions v1.0.0-beta.0 2023-06-20 */
2
+ 'use strict';
3
+ import { FilePersistence } from './FilePersistence.esm.js';
4
+ import { PersistenceError } from '../error/PersistenceError.esm.js';
5
+ import { Dpapi } from '../Dpapi.esm.js';
6
+ import { DataProtectionScope } from './DataProtectionScope.esm.js';
7
+ import { dirname } from 'path';
8
+ import { BasePersistence } from './BasePersistence.esm.js';
9
+ import { isNodeError } from '../utils/TypeGuards.esm.js';
10
+
11
+ /*
12
+ * Copyright (c) Microsoft Corporation. All rights reserved.
13
+ * Licensed under the MIT License.
14
+ */
15
+ /**
16
+ * Uses CryptProtectData and CryptUnprotectData on Windows to encrypt and decrypt file contents.
17
+ *
18
+ * scope: Scope of the data protection. Either local user or the current machine
19
+ * optionalEntropy: Password or other additional entropy used to encrypt the data
20
+ */
21
+ class FilePersistenceWithDataProtection extends BasePersistence {
22
+ constructor(filePersistence, scope, optionalEntropy) {
23
+ super();
24
+ this.scope = scope;
25
+ this.optionalEntropy = optionalEntropy ? Buffer.from(optionalEntropy, "utf-8") : null;
26
+ this.filePersistence = filePersistence;
27
+ }
28
+ static async create(fileLocation, scope, optionalEntropy, loggerOptions) {
29
+ const filePersistence = await FilePersistence.create(fileLocation, loggerOptions);
30
+ const persistence = new FilePersistenceWithDataProtection(filePersistence, scope, optionalEntropy);
31
+ return persistence;
32
+ }
33
+ async save(contents) {
34
+ try {
35
+ const encryptedContents = Dpapi.protectData(Buffer.from(contents, "utf-8"), this.optionalEntropy, this.scope.toString());
36
+ await this.filePersistence.saveBuffer(encryptedContents);
37
+ }
38
+ catch (err) {
39
+ if (isNodeError(err)) {
40
+ throw PersistenceError.createFilePersistenceWithDPAPIError(err.message);
41
+ }
42
+ else {
43
+ throw err;
44
+ }
45
+ }
46
+ }
47
+ async load() {
48
+ try {
49
+ const encryptedContents = await this.filePersistence.loadBuffer();
50
+ if (typeof encryptedContents === "undefined" || !encryptedContents || 0 === encryptedContents.length) {
51
+ this.filePersistence.getLogger().info("Encrypted contents loaded from file were null or empty");
52
+ return null;
53
+ }
54
+ return Dpapi.unprotectData(encryptedContents, this.optionalEntropy, this.scope.toString()).toString();
55
+ }
56
+ catch (err) {
57
+ if (isNodeError(err)) {
58
+ throw PersistenceError.createFilePersistenceWithDPAPIError(err.message);
59
+ }
60
+ else {
61
+ throw err;
62
+ }
63
+ }
64
+ }
65
+ async delete() {
66
+ return this.filePersistence.delete();
67
+ }
68
+ async reloadNecessary(lastSync) {
69
+ return this.filePersistence.reloadNecessary(lastSync);
70
+ }
71
+ getFilePath() {
72
+ return this.filePersistence.getFilePath();
73
+ }
74
+ getLogger() {
75
+ return this.filePersistence.getLogger();
76
+ }
77
+ createForPersistenceValidation() {
78
+ const testCacheFileLocation = `${dirname(this.filePersistence.getFilePath())}/test.cache`;
79
+ return FilePersistenceWithDataProtection.create(testCacheFileLocation, DataProtectionScope.CurrentUser);
80
+ }
81
+ }
82
+
83
+ export { FilePersistenceWithDataProtection };
84
+ //# sourceMappingURL=FilePersistenceWithDataProtection.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FilePersistenceWithDataProtection.esm.js","sources":["../../src/persistence/FilePersistenceWithDataProtection.ts"],"sourcesContent":[null],"names":[],"mappings":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,CAAC;QAC1F,OAAO,iCAAiC,CAAC,MAAM,CAAC,qBAAqB,EAAE,mBAAmB,CAAC,WAAW,CAAC,CAAC;KAC3G;AACJ;;;;"}
@@ -0,0 +1,86 @@
1
+ /*! @azure/msal-node-extensions v1.0.0-beta.0 2023-06-20 */
2
+ 'use strict';
3
+ 'use strict';
4
+
5
+ var FilePersistence = require('./FilePersistence.js');
6
+ var PersistenceError = require('../error/PersistenceError.js');
7
+ var Dpapi = require('../Dpapi.js');
8
+ var DataProtectionScope = require('./DataProtectionScope.js');
9
+ var path = require('path');
10
+ var BasePersistence = require('./BasePersistence.js');
11
+ var TypeGuards = require('../utils/TypeGuards.js');
12
+
13
+ /*
14
+ * Copyright (c) Microsoft Corporation. All rights reserved.
15
+ * Licensed under the MIT License.
16
+ */
17
+ /**
18
+ * Uses CryptProtectData and CryptUnprotectData on Windows to encrypt and decrypt file contents.
19
+ *
20
+ * scope: Scope of the data protection. Either local user or the current machine
21
+ * optionalEntropy: Password or other additional entropy used to encrypt the data
22
+ */
23
+ class FilePersistenceWithDataProtection extends BasePersistence.BasePersistence {
24
+ constructor(filePersistence, scope, optionalEntropy) {
25
+ super();
26
+ this.scope = scope;
27
+ this.optionalEntropy = optionalEntropy ? Buffer.from(optionalEntropy, "utf-8") : null;
28
+ this.filePersistence = filePersistence;
29
+ }
30
+ static async create(fileLocation, scope, optionalEntropy, loggerOptions) {
31
+ const filePersistence = await FilePersistence.FilePersistence.create(fileLocation, loggerOptions);
32
+ const persistence = new FilePersistenceWithDataProtection(filePersistence, scope, optionalEntropy);
33
+ return persistence;
34
+ }
35
+ async save(contents) {
36
+ try {
37
+ const encryptedContents = Dpapi.Dpapi.protectData(Buffer.from(contents, "utf-8"), this.optionalEntropy, this.scope.toString());
38
+ await this.filePersistence.saveBuffer(encryptedContents);
39
+ }
40
+ catch (err) {
41
+ if (TypeGuards.isNodeError(err)) {
42
+ throw PersistenceError.PersistenceError.createFilePersistenceWithDPAPIError(err.message);
43
+ }
44
+ else {
45
+ throw err;
46
+ }
47
+ }
48
+ }
49
+ async load() {
50
+ try {
51
+ const encryptedContents = await this.filePersistence.loadBuffer();
52
+ if (typeof encryptedContents === "undefined" || !encryptedContents || 0 === encryptedContents.length) {
53
+ this.filePersistence.getLogger().info("Encrypted contents loaded from file were null or empty");
54
+ return null;
55
+ }
56
+ return Dpapi.Dpapi.unprotectData(encryptedContents, this.optionalEntropy, this.scope.toString()).toString();
57
+ }
58
+ catch (err) {
59
+ if (TypeGuards.isNodeError(err)) {
60
+ throw PersistenceError.PersistenceError.createFilePersistenceWithDPAPIError(err.message);
61
+ }
62
+ else {
63
+ throw err;
64
+ }
65
+ }
66
+ }
67
+ async delete() {
68
+ return this.filePersistence.delete();
69
+ }
70
+ async reloadNecessary(lastSync) {
71
+ return this.filePersistence.reloadNecessary(lastSync);
72
+ }
73
+ getFilePath() {
74
+ return this.filePersistence.getFilePath();
75
+ }
76
+ getLogger() {
77
+ return this.filePersistence.getLogger();
78
+ }
79
+ createForPersistenceValidation() {
80
+ const testCacheFileLocation = `${path.dirname(this.filePersistence.getFilePath())}/test.cache`;
81
+ return FilePersistenceWithDataProtection.create(testCacheFileLocation, DataProtectionScope.DataProtectionScope.CurrentUser);
82
+ }
83
+ }
84
+
85
+ exports.FilePersistenceWithDataProtection = FilePersistenceWithDataProtection;
86
+ //# sourceMappingURL=FilePersistenceWithDataProtection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FilePersistenceWithDataProtection.js","sources":["../../src/persistence/FilePersistenceWithDataProtection.ts"],"sourcesContent":[null],"names":["BasePersistence","FilePersistence","Dpapi","isNodeError","PersistenceError","dirname","DataProtectionScope"],"mappings":";;;;;;;;;;;;AAAA;;;AAGG;AAYH;;;;;AAKG;AACG,MAAO,iCAAkC,SAAQA,+BAAe,CAAA;AAMlE,IAAA,WAAA,CAAoB,eAAgC,EAAE,KAA0B,EAAE,eAAwB,EAAA;AACtG,QAAA,KAAK,EAAE,CAAC;AACR,QAAA,IA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ProtectionScope } from "./DataProtectionScope";
2
3
  export interface IPersistenceConfiguration {
3
4
  cachePath?: string;
@@ -5,4 +6,5 @@ export interface IPersistenceConfiguration {
5
6
  serviceName?: string;
6
7
  accountName?: string;
7
8
  usePlaintextFileOnLinux?: boolean;
9
+ loggerOptions?: LoggerOptions;
8
10
  }
@@ -8,8 +8,8 @@ import { BasePersistence } from "./BasePersistence";
8
8
  * accountName: Account under which password should be stored
9
9
  */
10
10
  export declare class KeychainPersistence extends BasePersistence implements IPersistence {
11
- protected readonly serviceName: any;
12
- protected readonly accountName: any;
11
+ protected readonly serviceName: string;
12
+ protected readonly accountName: string;
13
13
  private filePersistence;
14
14
  private constructor();
15
15
  static create(fileLocation: string, serviceName: string, accountName: string, loggerOptions?: LoggerOptions): Promise<KeychainPersistence>;
@@ -0,0 +1,90 @@
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 macOS keychain
16
+ *
17
+ * serviceName: Identifier used as key for whatever value is stored
18
+ * accountName: Account under which password should be stored
19
+ */
20
+ class KeychainPersistence extends BasePersistence {
21
+ constructor(filePersistence, serviceName, accountName) {
22
+ super();
23
+ this.filePersistence = filePersistence;
24
+ this.serviceName = serviceName;
25
+ this.accountName = accountName;
26
+ }
27
+ static async create(fileLocation, serviceName, accountName, loggerOptions) {
28
+ const filePersistence = await FilePersistence.create(fileLocation, loggerOptions);
29
+ const persistence = new KeychainPersistence(filePersistence, serviceName, accountName);
30
+ return persistence;
31
+ }
32
+ async save(contents) {
33
+ try {
34
+ await setPassword(this.serviceName, this.accountName, contents);
35
+ }
36
+ catch (err) {
37
+ if (isNodeError(err)) {
38
+ throw PersistenceError.createKeychainPersistenceError(err.message);
39
+ }
40
+ else {
41
+ throw err;
42
+ }
43
+ }
44
+ // Write dummy data to update file mtime
45
+ await this.filePersistence.save("{}");
46
+ }
47
+ async load() {
48
+ try {
49
+ return await getPassword(this.serviceName, this.accountName);
50
+ }
51
+ catch (err) {
52
+ if (isNodeError(err)) {
53
+ throw PersistenceError.createKeychainPersistenceError(err.message);
54
+ }
55
+ else {
56
+ throw err;
57
+ }
58
+ }
59
+ }
60
+ async delete() {
61
+ try {
62
+ await this.filePersistence.delete();
63
+ return await deletePassword(this.serviceName, this.accountName);
64
+ }
65
+ catch (err) {
66
+ if (isNodeError(err)) {
67
+ throw PersistenceError.createKeychainPersistenceError(err.message);
68
+ }
69
+ else {
70
+ throw err;
71
+ }
72
+ }
73
+ }
74
+ async reloadNecessary(lastSync) {
75
+ return this.filePersistence.reloadNecessary(lastSync);
76
+ }
77
+ getFilePath() {
78
+ return this.filePersistence.getFilePath();
79
+ }
80
+ getLogger() {
81
+ return this.filePersistence.getLogger();
82
+ }
83
+ createForPersistenceValidation() {
84
+ const testCacheFileLocation = `${dirname(this.filePersistence.getFilePath())}/test.cache`;
85
+ return KeychainPersistence.create(testCacheFileLocation, "persistenceValidationServiceName", "persistencValidationAccountName");
86
+ }
87
+ }
88
+
89
+ export { KeychainPersistence };
90
+ //# sourceMappingURL=KeychainPersistence.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeychainPersistence.esm.js","sources":["../../src/persistence/KeychainPersistence.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;AAAA;;;AAGG;AAWH;;;;;AAKG;AACG,MAAO,mBAAoB,SAAQ,eAAe,CAAA;AAMpD,IAAA,WAAA,CAAoB,eAAgC,EAAE,WAAmB,EAAE,WAAmB,EAAA;AAC1F,QAAA,KAA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