@azure/msal-node-extensions 1.0.0-alpha.2 → 1.0.0-alpha.20

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 (45) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +193 -42
  3. package/binding.gyp +29 -29
  4. package/dist/error/PersistenceError.d.ts +32 -4
  5. package/dist/index.d.ts +3 -0
  6. package/dist/msal-node-extensions.cjs.development.js +615 -849
  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 +625 -864
  11. package/dist/msal-node-extensions.esm.js.map +1 -1
  12. package/dist/persistence/BasePersistence.d.ts +5 -0
  13. package/dist/persistence/FilePersistence.d.ts +4 -2
  14. package/dist/persistence/FilePersistenceWithDataProtection.d.ts +3 -1
  15. package/dist/persistence/IPersistence.d.ts +3 -1
  16. package/dist/persistence/IPersistenceConfiguration.d.ts +8 -0
  17. package/dist/persistence/KeychainPersistence.d.ts +3 -1
  18. package/dist/persistence/LibSecretPersistence.d.ts +3 -1
  19. package/dist/persistence/PersistenceCachePlugin.d.ts +11 -7
  20. package/dist/persistence/PersistenceCreator.d.ts +5 -0
  21. package/dist/utils/Constants.d.ts +31 -0
  22. package/dist/utils/Environment.d.ts +16 -0
  23. package/package.json +27 -14
  24. package/src/dpapi-addon/Dpapi.ts +17 -12
  25. package/src/dpapi-addon/dpapi_addon.h +6 -6
  26. package/src/dpapi-addon/dpapi_not_supported.cpp +19 -19
  27. package/src/dpapi-addon/dpapi_win.cpp +114 -114
  28. package/src/dpapi-addon/main.cpp +32 -32
  29. package/src/error/PersistenceError.ts +101 -65
  30. package/src/index.ts +16 -8
  31. package/src/lock/CrossPlatformLock.ts +89 -82
  32. package/src/lock/CrossPlatformLockOptions.ts +15 -15
  33. package/src/persistence/BasePersistence.ts +41 -0
  34. package/src/persistence/DataProtectionScope.ts +20 -20
  35. package/src/persistence/FilePersistence.ts +140 -134
  36. package/src/persistence/FilePersistenceWithDataProtection.ts +92 -84
  37. package/src/persistence/IPersistence.ts +17 -15
  38. package/src/persistence/IPersistenceConfiguration.ts +14 -0
  39. package/src/persistence/KeychainPersistence.ts +86 -78
  40. package/src/persistence/LibSecretPersistence.ts +87 -79
  41. package/src/persistence/PersistenceCachePlugin.ts +106 -96
  42. package/src/persistence/PersistenceCreator.ts +73 -0
  43. package/src/utils/Constants.ts +62 -24
  44. package/src/utils/Environment.ts +99 -0
  45. package/changelog.md +0 -14
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,42 +1,193 @@
1
- # Microsoft Authentication Extensions for Node
2
- 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).
3
-
4
- [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.
5
-
6
- Supported platforms are Windows, Mac and Linux:
7
-
8
- - Windows - DPAPI is used for encryption.
9
- - MAC - The MAC KeyChain is used.
10
- - Linux - LibSecret is used for storing to "Secret Service".
11
-
12
- > 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.
13
-
14
- ## Building
15
-
16
- The extensions contain prebuild binaries.
17
- [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)
18
-
19
- 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:
20
-
21
- - Debian/Ubuntu: `sudo apt-get install libsecret-1-dev`
22
- - Red Hat-based: `sudo yum install libsecret-devel`
23
- - Arch Linux: sudo `pacman -S libsecret`
24
-
25
- To build msal-node-extensions:
26
- - Navigate to `extensions/msal-node-extensions`
27
- - Run `npm install`
28
- - Run `npm run build`
29
-
30
- ## Contributing
31
-
32
- This project welcomes contributions and suggestions. Most contributions require you to agree to a
33
- Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
34
- the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
35
-
36
- When you submit a pull request, a CLA bot will automatically determine whether you need to provide
37
- a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
38
- provided by the bot. You will only need to do this once across all repos using our CLA.
39
-
40
- This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
41
- For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
42
- contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
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
+ 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.
package/binding.gyp CHANGED
@@ -1,29 +1,29 @@
1
- {
2
- "targets": [
3
- {
4
- 'target_name': 'dpapi',
5
- 'version': '0.1.0',
6
- 'sources': [
7
- 'src/dpapi-addon/main.cpp',
8
- 'src/dpapi-addon/dpapi_addon.h'
9
- ],
10
- 'include_dirs': [
11
- "<!(node -e \"require('nan')\")",
12
- "include"
13
- ],
14
- 'conditions': [
15
- ['OS=="win"', {
16
- 'sources': [
17
- 'src/dpapi-addon/dpapi_win.cpp',
18
- ],
19
- 'libraries': [
20
- '-lcrypt32.lib'
21
- ],
22
- }],
23
- ['OS not in ["win"]', {
24
- 'sources': [ 'src/dpapi-addon/dpapi_not_supported.ccp' ]
25
- }]
26
- ]
27
- }
28
- ]
29
- }
1
+ {
2
+ "targets": [
3
+ {
4
+ 'target_name': 'dpapi',
5
+ 'version': '0.1.0',
6
+ 'sources': [
7
+ 'src/dpapi-addon/main.cpp',
8
+ 'src/dpapi-addon/dpapi_addon.h'
9
+ ],
10
+ 'include_dirs': [
11
+ "<!(node -e \"require('nan')\")",
12
+ "include"
13
+ ],
14
+ 'conditions': [
15
+ ['OS=="win"', {
16
+ 'sources': [
17
+ 'src/dpapi-addon/dpapi_win.cpp',
18
+ ],
19
+ 'libraries': [
20
+ '-lcrypt32.lib'
21
+ ],
22
+ }],
23
+ ['OS not in ["win"]', {
24
+ 'sources': [ 'src/dpapi-addon/dpapi_not_supported.ccp' ]
25
+ }]
26
+ ]
27
+ }
28
+ ]
29
+ }
@@ -13,17 +13,45 @@ export declare class PersistenceError extends Error {
13
13
  * Error thrown when trying to write, load, or delete data from secret service on linux.
14
14
  * Libsecret is used to access secret service.
15
15
  */
16
- static createLibSecretError(errorCode: string, errorMessage: string): PersistenceError;
16
+ static createLibSecretError(errorMessage: string): PersistenceError;
17
17
  /**
18
18
  * Error thrown when trying to write, load, or delete data from keychain on macOs.
19
19
  */
20
- static createKeychainPersistenceError(errorCode: string, errorMessage: string): PersistenceError;
20
+ static createKeychainPersistenceError(errorMessage: string): PersistenceError;
21
21
  /**
22
22
  * Error thrown when trying to encrypt or decrypt data using DPAPI on Windows.
23
23
  */
24
- static createFilePersistenceWithDPAPIError(errorCode: string, errorMessage: string): PersistenceError;
24
+ static createFilePersistenceWithDPAPIError(errorMessage: string): PersistenceError;
25
25
  /**
26
26
  * Error thrown when using the cross platform lock.
27
27
  */
28
- static createCrossPlatformLockError(errorCode: string, errorMessage: string): PersistenceError;
28
+ static createCrossPlatformLockError(errorMessage: string): PersistenceError;
29
+ /**
30
+ * Throw cache persistence error
31
+ *
32
+ * @param errorMessage string
33
+ * @returns PersistenceError
34
+ */
35
+ static createCachePersistenceError(errorMessage: string): PersistenceError;
36
+ /**
37
+ * Throw unsupported error
38
+ *
39
+ * @param errorMessage string
40
+ * @returns PersistenceError
41
+ */
42
+ static createNotSupportedError(errorMessage: string): PersistenceError;
43
+ /**
44
+ * Throw persistence not verified error
45
+ *
46
+ * @param errorMessage string
47
+ * @returns PersistenceError
48
+ */
49
+ static createPersistenceNotVerifiedError(errorMessage: string): PersistenceError;
50
+ /**
51
+ * Throw persistence creation validation error
52
+ *
53
+ * @param errorMessage string
54
+ * @returns PersistenceError
55
+ */
56
+ static createPersistenceNotValidatedError(errorMessage: string): PersistenceError;
29
57
  }
package/dist/index.d.ts CHANGED
@@ -6,3 +6,6 @@ export { KeychainPersistence } from "./persistence/KeychainPersistence";
6
6
  export { LibSecretPersistence } from "./persistence/LibSecretPersistence";
7
7
  export { IPersistence } from "./persistence/IPersistence";
8
8
  export { CrossPlatformLockOptions } from "./lock/CrossPlatformLockOptions";
9
+ export { PersistenceCreator } from "./persistence/PersistenceCreator";
10
+ export { IPersistenceConfiguration } from "./persistence/IPersistenceConfiguration";
11
+ export { Environment } from "./utils/Environment";