@azure/msal-node-extensions 1.0.0-alpha.11 → 1.0.0-alpha.15

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 (34) hide show
  1. package/CHANGELOG.json +325 -211
  2. package/CHANGELOG.md +128 -94
  3. package/LICENSE +21 -21
  4. package/README.md +192 -192
  5. package/binding.gyp +29 -29
  6. package/dist/msal-node-extensions.cjs.development.js +7 -7
  7. package/dist/msal-node-extensions.cjs.development.js.map +1 -1
  8. package/dist/msal-node-extensions.cjs.production.min.js +1 -1
  9. package/dist/msal-node-extensions.cjs.production.min.js.map +1 -1
  10. package/dist/msal-node-extensions.esm.js +7 -7
  11. package/dist/msal-node-extensions.esm.js.map +1 -1
  12. package/dist/persistence/PersistenceCreator.d.ts +1 -1
  13. package/package.json +65 -59
  14. package/src/dpapi-addon/Dpapi.ts +17 -17
  15. package/src/dpapi-addon/dpapi_addon.h +6 -6
  16. package/src/dpapi-addon/dpapi_not_supported.cpp +19 -19
  17. package/src/dpapi-addon/dpapi_win.cpp +114 -114
  18. package/src/dpapi-addon/main.cpp +32 -32
  19. package/src/error/PersistenceError.ts +101 -101
  20. package/src/index.ts +16 -16
  21. package/src/lock/CrossPlatformLock.ts +89 -89
  22. package/src/lock/CrossPlatformLockOptions.ts +15 -15
  23. package/src/persistence/BasePersistence.ts +41 -41
  24. package/src/persistence/DataProtectionScope.ts +20 -20
  25. package/src/persistence/FilePersistence.ts +140 -140
  26. package/src/persistence/FilePersistenceWithDataProtection.ts +92 -92
  27. package/src/persistence/IPersistence.ts +17 -17
  28. package/src/persistence/IPersistenceConfiguration.ts +14 -14
  29. package/src/persistence/KeychainPersistence.ts +86 -86
  30. package/src/persistence/LibSecretPersistence.ts +87 -87
  31. package/src/persistence/PersistenceCachePlugin.ts +106 -106
  32. package/src/persistence/PersistenceCreator.ts +73 -73
  33. package/src/utils/Constants.ts +62 -62
  34. package/src/utils/Environment.ts +99 -99
package/CHANGELOG.md CHANGED
@@ -1,94 +1,128 @@
1
- # Change Log - @azure/msal-node-extensions
2
-
3
- This log was last generated on Mon, 04 Oct 2021 23:12:35 GMT and should not be manually modified.
4
-
5
- <!-- Start content -->
6
-
7
- ## 1.0.0-alpha.11
8
-
9
- Mon, 04 Oct 2021 23:12:35 GMT
10
-
11
- ### Changes
12
-
13
- - fix: integrate forked bindings package (kamausamuel11@gmail.com)
14
- - Bump @azure/msal-common to v5.0.1
15
-
16
- ## 1.0.0-alpha.10
17
-
18
- Thu, 09 Sep 2021 23:58:01 GMT
19
-
20
- ### Changes
21
-
22
- - Upgrade msal-common to v5 for Node extensions (janutter@microsoft.com)
23
-
24
- ## 1.0.0-alpha.9
25
-
26
- Thu, 22 Jul 2021 22:50:22 GMT
27
-
28
- ### Changes
29
-
30
- - feat: add the persistence creator (#3859) (samuelkamau@microsoft.com)
31
- - fix: bump up the msal-common version (samuelkamau@microsoft.com)
32
-
33
- ## 1.0.0-alpha.8
34
-
35
- Tue, 29 Jun 2021 00:28:30 GMT
36
-
37
- ### Changes
38
-
39
- - verifyPersistence returns the right value on failure(#3787) (sameera.gajjarapu@microsoft.com)
40
-
41
- ## 1.0.0-alpha.7
42
-
43
- Wed, 23 Jun 2021 00:01:49 GMT
44
-
45
- ### Changes
46
-
47
- - Add logs to test beachball (sameera.gajjarapu@microsoft.com)
48
-
49
- ## 1.0.0-alpha.6
50
-
51
- Fri, 05 Mar 2021 21:26:46 GMT
52
-
53
- ### Changes
54
-
55
- - Fix lint in extensions to trigger version bump (janutter@microsoft.com)
56
-
57
- ## 1.0.0-alpha.5
58
-
59
- Wed, 03 Mar 2021 22:13:23 GMT
60
-
61
- ### Changes
62
-
63
- - Fix npm audit warnings (janutter@microsoft.com)
64
-
65
- ## 1.0.0-alpha.4
66
-
67
- Wed, 14 Oct 2020 23:45:07 GMT
68
-
69
- ### Changes
70
-
71
- - Update PersistenceCachePlugin (#2348) (sameera.gajjarapu@microsoft.com)
72
-
73
- ## 1.0.0-alpha.3
74
-
75
- Wed, 23 Sep 2020 21:13:48 GMT
76
-
77
- ### Changes
78
-
79
- - Update error message (#2265) (sagonzal@microsoft.com)
80
-
81
- # 1.0.0-alpha.2
82
- - Fix issue where binding.gyp was not being uploaded to npm
83
-
84
- # 1.0.0-alpha.1
85
- - Increment @azure/msal-common version to 1.1.0
86
-
87
- # 1.0.0-alpha.0
88
-
89
- - Extensions 1: Sets directory structure, adds Windows DPAPI Node addon (#1830)
90
- - Extensions 2: Add cross process lock (#1831)
91
- - Extensions 3: Add cache persistence plugin, persistence on Windows, Linux, and Mac (#1832)
92
- - Extensions 4: Add sample (#1834)
93
- - Extensions 5: Add documentation, add logger (#1835)
94
- - Extensions 6: Add tests (#1849)
1
+ # Change Log - @azure/msal-node-extensions
2
+
3
+ This log was last generated on Tue, 08 Feb 2022 00:41:06 GMT and should not be manually modified.
4
+
5
+ <!-- Start content -->
6
+
7
+ ## 1.0.0-alpha.15
8
+
9
+ Tue, 08 Feb 2022 00:41:06 GMT
10
+
11
+ ### Changes
12
+
13
+ - Update keytar dependency to ^7.8.0 #4483 (thomas.norling@microsoft.com)
14
+ - Bump @azure/msal-common to v6.1.0
15
+
16
+ ## 1.0.0-alpha.14
17
+
18
+ Tue, 04 Jan 2022 00:20:29 GMT
19
+
20
+ ### Changes
21
+
22
+ - Bump @azure/msal-common to v6.0.0
23
+
24
+ ## 1.0.0-alpha.13
25
+
26
+ Tue, 07 Dec 2021 00:17:01 GMT
27
+
28
+ ### Changes
29
+
30
+ - Use https to install bindings dependency #4234 (thomas.norling@microsoft.com)
31
+ - Bump @azure/msal-common to v5.2.0
32
+
33
+ ## 1.0.0-alpha.12
34
+
35
+ Mon, 01 Nov 2021 23:53:22 GMT
36
+
37
+ ### Changes
38
+
39
+ - Bump @azure/msal-common to v5.1.0
40
+
41
+ ## 1.0.0-alpha.11
42
+
43
+ Mon, 04 Oct 2021 23:12:35 GMT
44
+
45
+ ### Changes
46
+
47
+ - fix: integrate forked bindings package (kamausamuel11@gmail.com)
48
+ - Bump @azure/msal-common to v5.0.1
49
+
50
+ ## 1.0.0-alpha.10
51
+
52
+ Thu, 09 Sep 2021 23:58:01 GMT
53
+
54
+ ### Changes
55
+
56
+ - Upgrade msal-common to v5 for Node extensions (janutter@microsoft.com)
57
+
58
+ ## 1.0.0-alpha.9
59
+
60
+ Thu, 22 Jul 2021 22:50:22 GMT
61
+
62
+ ### Changes
63
+
64
+ - feat: add the persistence creator (#3859) (samuelkamau@microsoft.com)
65
+ - fix: bump up the msal-common version (samuelkamau@microsoft.com)
66
+
67
+ ## 1.0.0-alpha.8
68
+
69
+ Tue, 29 Jun 2021 00:28:30 GMT
70
+
71
+ ### Changes
72
+
73
+ - verifyPersistence returns the right value on failure(#3787) (sameera.gajjarapu@microsoft.com)
74
+
75
+ ## 1.0.0-alpha.7
76
+
77
+ Wed, 23 Jun 2021 00:01:49 GMT
78
+
79
+ ### Changes
80
+
81
+ - Add logs to test beachball (sameera.gajjarapu@microsoft.com)
82
+
83
+ ## 1.0.0-alpha.6
84
+
85
+ Fri, 05 Mar 2021 21:26:46 GMT
86
+
87
+ ### Changes
88
+
89
+ - Fix lint in extensions to trigger version bump (janutter@microsoft.com)
90
+
91
+ ## 1.0.0-alpha.5
92
+
93
+ Wed, 03 Mar 2021 22:13:23 GMT
94
+
95
+ ### Changes
96
+
97
+ - Fix npm audit warnings (janutter@microsoft.com)
98
+
99
+ ## 1.0.0-alpha.4
100
+
101
+ Wed, 14 Oct 2020 23:45:07 GMT
102
+
103
+ ### Changes
104
+
105
+ - Update PersistenceCachePlugin (#2348) (sameera.gajjarapu@microsoft.com)
106
+
107
+ ## 1.0.0-alpha.3
108
+
109
+ Wed, 23 Sep 2020 21:13:48 GMT
110
+
111
+ ### Changes
112
+
113
+ - Update error message (#2265) (sagonzal@microsoft.com)
114
+
115
+ # 1.0.0-alpha.2
116
+ - Fix issue where binding.gyp was not being uploaded to npm
117
+
118
+ # 1.0.0-alpha.1
119
+ - Increment @azure/msal-common version to 1.1.0
120
+
121
+ # 1.0.0-alpha.0
122
+
123
+ - Extensions 1: Sets directory structure, adds Windows DPAPI Node addon (#1830)
124
+ - Extensions 2: Add cross process lock (#1831)
125
+ - Extensions 3: Add cache persistence plugin, persistence on Windows, Linux, and Mac (#1832)
126
+ - Extensions 4: Add sample (#1834)
127
+ - Extensions 5: Add documentation, add logger (#1835)
128
+ - Extensions 6: Add tests (#1849)
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) Microsoft Corporation.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE
package/README.md CHANGED
@@ -1,193 +1,193 @@
1
- # Microsoft Authentication Extensions for Node
2
-
3
- ![npm (scoped)](https://img.shields.io/npm/v/@azure/msal-node-extensions)
4
- ![npm](https://img.shields.io/npm/dw/@azure/msal-node-extensions)
5
-
6
- | <a href="https://docs.microsoft.com/azure/active-directory/develop/tutorial-v2-react" target="blank">Getting Started</a> | <a href="https://aka.ms/aaddevv2" target="_blank">AAD Docs</a> | <a href="https://azuread.github.io/microsoft-authentication-library-for-js/ref/modules/_azure_msal_react.html" target="_blank">Library Reference</a> | <a href="https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples" target="blank">Samples</a>
7
- |--- | --- | --- | --- |
8
-
9
- 1. [About](#about)
10
- - [Goals](#goals)
11
- - [Non-Goals](#non-goals)
12
- 1. [FAQ](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/extensions/docs/faq.md)
13
- 1. [Changelog](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/extensions/msal-node-extensions/CHANGELOG.md)
14
- 1. [Prerequisites](#prerequisites)
15
- 1. [Installation](#installation)
16
- 1. [Usage](#usage)
17
- - [Getting Started](#getting-started)
18
- - [Security Boundary](#security-boundary)
19
- 1. [Build and Test](#build-and-test)
20
- - [Build package](#building-the-package-locally)
21
- - [Test package](#running-tests)
22
- 1. [Samples](#samples)
23
- 1. [Security Reporting](#security-reporting)
24
- 1. [License](#license)
25
- 1. [Contributing](#contributing)
26
- 1. [Code of Conduct](#we-value-and-adhere-to-the-microsoft-open-source-code-of-conduct)
27
-
28
- ## About
29
- The Microsoft Authentication Extensions for Node offers secure mechanisms for client applications to perform cross-platform token cache serialization and persistence. It gives additional support to the Microsoft Authentication Library for Node (MSAL).
30
-
31
- [MSAL Node](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-node) supports an in-memory cache by default and provides the ICachePlugin interface to perform cache serialization, but does not provide a default way of storing the token cache to disk. Microsoft authentication extensions for node is default implementation for persisting cache to disk across different platforms.
32
-
33
- Supported platforms are Windows, Mac and Linux:
34
-
35
- - Windows - DPAPI is used for encryption.
36
- - MAC - The MAC KeyChain is used.
37
- - Linux - LibSecret is used for storing to "Secret Service".
38
-
39
- > Note: It is recommended to use this library for cache persistence support for Public client applications such as Desktop apps only. In web applications, this may lead to scale and performance issues. Web applications are recommended to persist the cache in session.
40
-
41
- ### Goals
42
- * Provide a robust, secure and configurable token cache persistence implementation across Windows, Mac and Linux for public client applications (rich clients, CLI applications etc.)
43
- * Token cache storage can be accessed by multiple processes concurrently.
44
-
45
- ### Non Goals
46
- * This implementation is not suitable for web app / web api scenarios, where storing the cache should be done in memory, Redis, Sql Server etc. Have a look at the [web samples](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-node-samples) for server-side implementations.
47
-
48
- ## Prerequisites
49
-
50
- The extensions contain prebuild binaries.
51
- [node-gyp](https://github.com/nodejs/node-gyp) is used to compile addons for accessing system APIs. Installation requirements are listed on the [node-gyp README](https://github.com/nodejs/node-gyp#installation)
52
-
53
- On linux, the library uses `libsecret` so you may need to install it. Depending on your distribution, you will need to run the following command:
54
-
55
- - Debian/Ubuntu: `sudo apt-get install libsecret-1-dev`
56
- - Red Hat-based: `sudo yum install libsecret-devel`
57
- - Arch Linux: sudo `pacman -S libsecret`
58
-
59
- ## Installation
60
-
61
- The `msal-node-extensions` package is available on NPM.
62
-
63
- ```bash
64
- npm i @azure/msal-node-extensions --save
65
- ```
66
- ## Usage
67
- ### Getting started
68
- Here is a code snippet on how to configure the token cache.
69
-
70
- ```js
71
- const {
72
- DataProtectionScope,
73
- Environment,
74
- PersistenceCreator,
75
- PersistenceCachePlugin,
76
- } = require("@azure/msal-node-extensions");
77
-
78
- // You can use the helper functions provided through the Environment class to construct your cache path
79
- // The helper functions provide consistent implementations across Windows, Mac and Linux.
80
- const cachePath = path.join(Environment.getUserRootDirectory(), "./cache.json");
81
-
82
- const persistenceConfiguration = {
83
- cachePath,
84
- dataProtectionScope: DataProtectionScope.CurrentUser,
85
- serviceName: "<SERVICE-NAME>",
86
- accountName: "<ACCOUNT-NAME>",
87
- usePlaintextFileOnLinux: false,
88
- }
89
-
90
- // The PersistenceCreator obfuscates a lot of the complexity by doing the following actions for you :-
91
- // 1. Detects the environment the application is running on and initializes the right persistence instance for the environment.
92
- // 2. Performs persistence validation for you.
93
- // 3. Performs any fallbacks if necessary.
94
- PersistenceCreator
95
- .createPersistence(persistenceConfiguration)
96
- .then(async (persistence) => {
97
- const publicClientConfig = {
98
- auth: {
99
- clientId: "<CLIENT-ID>",
100
- authority: "<AUTHORITY>",
101
- },
102
-
103
- // This hooks up the cross-platform cache into MSAL
104
- cache: {
105
- cachePlugin: new PersistenceCachePlugin(persistence)
106
- }
107
- };
108
-
109
- const pca = new msal.PublicClientApplication(publicClientConfig);
110
-
111
- // Use the public client application as required...
112
- });
113
- ```
114
-
115
- All the arguments for the persistence configuration are explained below:
116
- | Field Name | Description | Required For |
117
- | ---------- | ----------- | ------------ |
118
- | cachePath | This is the path to the lock file the library uses to synchronize the reads and the writes | Windows, Mac and Linux |
119
- | dataProtectionScope | Specifies the scope of the data protection on Windows either the current user or the local machine. | Windows |
120
- | serviceName | This specifies the service name to be used on Mac and/or Linux | Mac and Linux |
121
- | accountName | This specifies the account name to be used on Mac and/or Linux | Mac and Linux |
122
- | usePlaintextFileOnLinux | This is a flag to default to plain text on linux if libsecret fails. Defaults to `false` | Linux |
123
-
124
- ### Security boundary
125
- On Windows and Linux, the token cache is scoped to the user session, i.e. all applications running on behalf of the user can access the cache. Mac offers a more restricted scope, ensuring that only the application that created the cache can access it, and prompting the user if others apps want access.
126
-
127
- ## Build and Test
128
-
129
- If you intend to contribute to the library visit the [`contributing section`](#contributing) for even more information on how.
130
-
131
- ### Building the package locally
132
-
133
- To build the `@azure/msal-node-extensions` library, you can do the following:
134
-
135
- ```bash
136
- // Install dev dependencies from root of repo
137
- npm install
138
- // Change to the msal-node-extensions package directory
139
- cd extensions/msal-node-extensions
140
- // To run build only for node-extensions package
141
- npm run build
142
- ```
143
-
144
- To build both the `@azure/msal-node-extensions` library and `@azure/msal-common` libraries, you can do the following:
145
-
146
- ```bash
147
- // Install dev dependencies from root of repo
148
- npm install
149
- // Change to the msal-react package directory
150
- cd lib/msal-node-extensions/
151
- // To run build for the common package
152
- npm run build:common
153
- // To run build for the msal-node-extensions package
154
- npm run build
155
- ```
156
-
157
- ### Running Tests
158
-
159
- `@azure/msal-node-extensions` uses [jest](https://jestjs.io/) to run unit tests and coverage.
160
-
161
- ```bash
162
- // To run tests
163
- npm test
164
- ```
165
-
166
- ## Samples
167
- Have a look at a [simple auth-code app](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/extensions/samples/msal-node-extensions) using this token cache. We use this for testing on Windows, Mac and Linux.
168
-
169
- ## Security Reporting
170
-
171
- If you find a security issue with our libraries or services please report it to [secure@microsoft.com](mailto:secure@microsoft.com) with as much detail as possible. Your submission may be eligible for a bounty through the [Microsoft Bounty](http://aka.ms/bugbounty) program. Please do not post security issues to GitHub Issues or any other public site. We will contact you shortly upon receiving the information. We encourage you to get notifications of when security incidents occur by visiting [this page](https://technet.microsoft.com/security/dd252948) and subscribing to Security Advisory Alerts.
172
-
173
- ## License
174
-
175
- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License.
176
-
177
- ## Contributing
178
-
179
- This project welcomes contributions and suggestions. Most contributions require you to agree to a
180
- Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
181
- the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
182
-
183
- When you submit a pull request, a CLA bot will automatically determine whether you need to provide
184
- a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
185
- provided by the bot. You will only need to do this once across all repos using our CLA.
186
-
187
- This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
188
- For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
189
- contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
190
-
191
- ## We Value and Adhere to the Microsoft Open Source Code of Conduct
192
-
1
+ # Microsoft Authentication Extensions for Node
2
+
3
+ ![npm (scoped)](https://img.shields.io/npm/v/@azure/msal-node-extensions)
4
+ ![npm](https://img.shields.io/npm/dw/@azure/msal-node-extensions)
5
+
6
+ | <a href="https://docs.microsoft.com/azure/active-directory/develop/tutorial-v2-react" target="blank">Getting Started</a> | <a href="https://aka.ms/aaddevv2" target="_blank">AAD Docs</a> | <a href="https://azuread.github.io/microsoft-authentication-library-for-js/ref/modules/_azure_msal_react.html" target="_blank">Library Reference</a> | <a href="https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples" target="blank">Samples</a>
7
+ |--- | --- | --- | --- |
8
+
9
+ 1. [About](#about)
10
+ - [Goals](#goals)
11
+ - [Non-Goals](#non-goals)
12
+ 1. [FAQ](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/extensions/docs/faq.md)
13
+ 1. [Changelog](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/extensions/msal-node-extensions/CHANGELOG.md)
14
+ 1. [Prerequisites](#prerequisites)
15
+ 1. [Installation](#installation)
16
+ 1. [Usage](#usage)
17
+ - [Getting Started](#getting-started)
18
+ - [Security Boundary](#security-boundary)
19
+ 1. [Build and Test](#build-and-test)
20
+ - [Build package](#building-the-package-locally)
21
+ - [Test package](#running-tests)
22
+ 1. [Samples](#samples)
23
+ 1. [Security Reporting](#security-reporting)
24
+ 1. [License](#license)
25
+ 1. [Contributing](#contributing)
26
+ 1. [Code of Conduct](#we-value-and-adhere-to-the-microsoft-open-source-code-of-conduct)
27
+
28
+ ## About
29
+ The Microsoft Authentication Extensions for Node offers secure mechanisms for client applications to perform cross-platform token cache serialization and persistence. It gives additional support to the Microsoft Authentication Library for Node (MSAL).
30
+
31
+ [MSAL Node](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-node) supports an in-memory cache by default and provides the ICachePlugin interface to perform cache serialization, but does not provide a default way of storing the token cache to disk. Microsoft authentication extensions for node is default implementation for persisting cache to disk across different platforms.
32
+
33
+ Supported platforms are Windows, Mac and Linux:
34
+
35
+ - Windows - DPAPI is used for encryption.
36
+ - MAC - The MAC KeyChain is used.
37
+ - Linux - LibSecret is used for storing to "Secret Service".
38
+
39
+ > Note: It is recommended to use this library for cache persistence support for Public client applications such as Desktop apps only. In web applications, this may lead to scale and performance issues. Web applications are recommended to persist the cache in session.
40
+
41
+ ### Goals
42
+ * Provide a robust, secure and configurable token cache persistence implementation across Windows, Mac and Linux for public client applications (rich clients, CLI applications etc.)
43
+ * Token cache storage can be accessed by multiple processes concurrently.
44
+
45
+ ### Non Goals
46
+ * This implementation is not suitable for web app / web api scenarios, where storing the cache should be done in memory, Redis, Sql Server etc. Have a look at the [web samples](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-node-samples) for server-side implementations.
47
+
48
+ ## Prerequisites
49
+
50
+ The extensions contain prebuild binaries.
51
+ [node-gyp](https://github.com/nodejs/node-gyp) is used to compile addons for accessing system APIs. Installation requirements are listed on the [node-gyp README](https://github.com/nodejs/node-gyp#installation)
52
+
53
+ On linux, the library uses `libsecret` so you may need to install it. Depending on your distribution, you will need to run the following command:
54
+
55
+ - Debian/Ubuntu: `sudo apt-get install libsecret-1-dev`
56
+ - Red Hat-based: `sudo yum install libsecret-devel`
57
+ - Arch Linux: sudo `pacman -S libsecret`
58
+
59
+ ## Installation
60
+
61
+ The `msal-node-extensions` package is available on NPM.
62
+
63
+ ```bash
64
+ npm i @azure/msal-node-extensions --save
65
+ ```
66
+ ## Usage
67
+ ### Getting started
68
+ Here is a code snippet on how to configure the token cache.
69
+
70
+ ```js
71
+ const {
72
+ DataProtectionScope,
73
+ Environment,
74
+ PersistenceCreator,
75
+ PersistenceCachePlugin,
76
+ } = require("@azure/msal-node-extensions");
77
+
78
+ // You can use the helper functions provided through the Environment class to construct your cache path
79
+ // The helper functions provide consistent implementations across Windows, Mac and Linux.
80
+ const cachePath = path.join(Environment.getUserRootDirectory(), "./cache.json");
81
+
82
+ const persistenceConfiguration = {
83
+ cachePath,
84
+ dataProtectionScope: DataProtectionScope.CurrentUser,
85
+ serviceName: "<SERVICE-NAME>",
86
+ accountName: "<ACCOUNT-NAME>",
87
+ usePlaintextFileOnLinux: false,
88
+ }
89
+
90
+ // The PersistenceCreator obfuscates a lot of the complexity by doing the following actions for you :-
91
+ // 1. Detects the environment the application is running on and initializes the right persistence instance for the environment.
92
+ // 2. Performs persistence validation for you.
93
+ // 3. Performs any fallbacks if necessary.
94
+ PersistenceCreator
95
+ .createPersistence(persistenceConfiguration)
96
+ .then(async (persistence) => {
97
+ const publicClientConfig = {
98
+ auth: {
99
+ clientId: "<CLIENT-ID>",
100
+ authority: "<AUTHORITY>",
101
+ },
102
+
103
+ // This hooks up the cross-platform cache into MSAL
104
+ cache: {
105
+ cachePlugin: new PersistenceCachePlugin(persistence)
106
+ }
107
+ };
108
+
109
+ const pca = new msal.PublicClientApplication(publicClientConfig);
110
+
111
+ // Use the public client application as required...
112
+ });
113
+ ```
114
+
115
+ All the arguments for the persistence configuration are explained below:
116
+ | Field Name | Description | Required For |
117
+ | ---------- | ----------- | ------------ |
118
+ | cachePath | This is the path to the lock file the library uses to synchronize the reads and the writes | Windows, Mac and Linux |
119
+ | dataProtectionScope | Specifies the scope of the data protection on Windows either the current user or the local machine. | Windows |
120
+ | serviceName | This specifies the service name to be used on Mac and/or Linux | Mac and Linux |
121
+ | accountName | This specifies the account name to be used on Mac and/or Linux | Mac and Linux |
122
+ | usePlaintextFileOnLinux | This is a flag to default to plain text on linux if libsecret fails. Defaults to `false` | Linux |
123
+
124
+ ### Security boundary
125
+ On Windows and Linux, the token cache is scoped to the user session, i.e. all applications running on behalf of the user can access the cache. Mac offers a more restricted scope, ensuring that only the application that created the cache can access it, and prompting the user if others apps want access.
126
+
127
+ ## Build and Test
128
+
129
+ If you intend to contribute to the library visit the [`contributing section`](#contributing) for even more information on how.
130
+
131
+ ### Building the package locally
132
+
133
+ To build the `@azure/msal-node-extensions` library, you can do the following:
134
+
135
+ ```bash
136
+ // Install dev dependencies from root of repo
137
+ npm install
138
+ // Change to the msal-node-extensions package directory
139
+ cd extensions/msal-node-extensions
140
+ // To run build only for node-extensions package
141
+ npm run build
142
+ ```
143
+
144
+ To build both the `@azure/msal-node-extensions` library and `@azure/msal-common` libraries, you can do the following:
145
+
146
+ ```bash
147
+ // Install dev dependencies from root of repo
148
+ npm install
149
+ // Change to the msal-react package directory
150
+ cd lib/msal-node-extensions/
151
+ // To run build for the common package
152
+ npm run build:common
153
+ // To run build for the msal-node-extensions package
154
+ npm run build
155
+ ```
156
+
157
+ ### Running Tests
158
+
159
+ `@azure/msal-node-extensions` uses [jest](https://jestjs.io/) to run unit tests and coverage.
160
+
161
+ ```bash
162
+ // To run tests
163
+ npm test
164
+ ```
165
+
166
+ ## Samples
167
+ Have a look at a [simple auth-code app](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/extensions/samples/msal-node-extensions) using this token cache. We use this for testing on Windows, Mac and Linux.
168
+
169
+ ## Security Reporting
170
+
171
+ If you find a security issue with our libraries or services please report it to [secure@microsoft.com](mailto:secure@microsoft.com) with as much detail as possible. Your submission may be eligible for a bounty through the [Microsoft Bounty](http://aka.ms/bugbounty) program. Please do not post security issues to GitHub Issues or any other public site. We will contact you shortly upon receiving the information. We encourage you to get notifications of when security incidents occur by visiting [this page](https://technet.microsoft.com/security/dd252948) and subscribing to Security Advisory Alerts.
172
+
173
+ ## License
174
+
175
+ Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License.
176
+
177
+ ## Contributing
178
+
179
+ This project welcomes contributions and suggestions. Most contributions require you to agree to a
180
+ Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
181
+ the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
182
+
183
+ When you submit a pull request, a CLA bot will automatically determine whether you need to provide
184
+ a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
185
+ provided by the bot. You will only need to do this once across all repos using our CLA.
186
+
187
+ This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
188
+ For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
189
+ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
190
+
191
+ ## We Value and Adhere to the Microsoft Open Source Code of Conduct
192
+
193
193
  This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.