@azure/msal-node-extensions 1.0.0-alpha.3 → 1.0.0-alpha.31

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 (51) hide show
  1. package/README.md +156 -5
  2. package/binding.gyp +11 -1
  3. package/dist/broker/NativeBrokerPlugin.d.ts +20 -0
  4. package/dist/error/NativeAuthError.d.ts +6 -0
  5. package/dist/error/PersistenceError.d.ts +28 -0
  6. package/dist/index.d.ts +4 -0
  7. package/dist/msal-node-extensions.cjs.development.js +949 -932
  8. package/dist/msal-node-extensions.cjs.development.js.map +1 -1
  9. package/dist/msal-node-extensions.cjs.production.min.js +1 -1
  10. package/dist/msal-node-extensions.cjs.production.min.js.map +1 -1
  11. package/dist/msal-node-extensions.esm.js +957 -947
  12. package/dist/msal-node-extensions.esm.js.map +1 -1
  13. package/dist/packageMetadata.d.ts +2 -0
  14. package/dist/persistence/BasePersistence.d.ts +5 -0
  15. package/dist/persistence/FilePersistence.d.ts +4 -2
  16. package/dist/persistence/FilePersistenceWithDataProtection.d.ts +3 -1
  17. package/dist/persistence/IPersistence.d.ts +3 -1
  18. package/dist/persistence/IPersistenceConfiguration.d.ts +10 -0
  19. package/dist/persistence/KeychainPersistence.d.ts +3 -1
  20. package/dist/persistence/LibSecretPersistence.d.ts +3 -1
  21. package/dist/persistence/PersistenceCachePlugin.d.ts +11 -7
  22. package/dist/persistence/PersistenceCreator.d.ts +5 -0
  23. package/dist/utils/Constants.d.ts +30 -0
  24. package/dist/utils/Environment.d.ts +16 -0
  25. package/package.json +28 -15
  26. package/src/{dpapi-addon/Dpapi.ts → Dpapi.ts} +12 -12
  27. package/src/broker/NativeBrokerPlugin.ts +418 -0
  28. package/src/dpapi-addon/dpapi_addon.h +2 -1
  29. package/src/dpapi-addon/dpapi_not_supported.cpp +4 -10
  30. package/src/dpapi-addon/dpapi_win.cpp +25 -33
  31. package/src/dpapi-addon/main.cpp +14 -16
  32. package/src/error/NativeAuthError.ts +19 -0
  33. package/src/error/PersistenceError.ts +101 -61
  34. package/src/index.ts +17 -8
  35. package/src/lock/CrossPlatformLock.ts +89 -89
  36. package/src/lock/CrossPlatformLockOptions.ts +15 -15
  37. package/src/packageMetadata.ts +3 -0
  38. package/src/persistence/BasePersistence.ts +43 -0
  39. package/src/persistence/FilePersistence.ts +140 -134
  40. package/src/persistence/FilePersistenceWithDataProtection.ts +92 -84
  41. package/src/persistence/IPersistence.ts +4 -2
  42. package/src/persistence/IPersistenceConfiguration.ts +17 -0
  43. package/src/persistence/KeychainPersistence.ts +89 -78
  44. package/src/persistence/LibSecretPersistence.ts +90 -79
  45. package/src/persistence/PersistenceCachePlugin.ts +40 -30
  46. package/src/persistence/PersistenceCreator.ts +78 -0
  47. package/src/utils/Constants.ts +67 -30
  48. package/src/utils/Environment.ts +101 -0
  49. package/CHANGELOG.json +0 -50
  50. package/changelog.md +0 -28
  51. /package/dist/{dpapi-addon/Dpapi.d.ts → Dpapi.d.ts} +0 -0
package/README.md CHANGED
@@ -1,4 +1,31 @@
1
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
2
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).
3
30
 
4
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.
@@ -11,7 +38,14 @@ Supported platforms are Windows, Mac and Linux:
11
38
 
12
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.
13
40
 
14
- ## Building
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
15
49
 
16
50
  The extensions contain prebuild binaries.
17
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)
@@ -22,10 +56,123 @@ On linux, the library uses `libsecret` so you may need to install it. Depending
22
56
  - Red Hat-based: `sudo yum install libsecret-devel`
23
57
  - Arch Linux: sudo `pacman -S libsecret`
24
58
 
25
- To build msal-node-extensions:
26
- - Navigate to `extensions/msal-node-extensions`
27
- - Run `npm install`
28
- - Run `npm run build`
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.
29
176
 
30
177
  ## Contributing
31
178
 
@@ -40,3 +187,7 @@ provided by the bot. You will only need to do this once across all repos using o
40
187
  This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
41
188
  For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
42
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
@@ -2,13 +2,23 @@
2
2
  "targets": [
3
3
  {
4
4
  'target_name': 'dpapi',
5
+ 'cflags!': [ '-fno-exceptions' ],
6
+ 'cflags_cc!': [ '-fno-exceptions' ],
7
+ 'xcode_settings': { 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
8
+ 'CLANG_CXX_LIBRARY': 'libc++',
9
+ 'MACOSX_DEPLOYMENT_TARGET': '10.7',
10
+ },
11
+ 'msvs_settings': {
12
+ 'VCCLCompilerTool': { 'ExceptionHandling': 1 },
13
+ },
5
14
  'version': '0.1.0',
6
15
  'sources': [
7
16
  'src/dpapi-addon/main.cpp',
8
17
  'src/dpapi-addon/dpapi_addon.h'
9
18
  ],
10
19
  'include_dirs': [
11
- "<!(node -e \"require('nan')\")",
20
+ '<!(node -p "require(\'node-addon-api\').include_dir")',
21
+
12
22
  "include"
13
23
  ],
14
24
  'conditions': [
@@ -0,0 +1,20 @@
1
+ /// <reference types="node" />
2
+ import { AccountInfo, AuthenticationResult, INativeBrokerPlugin, LoggerOptions, NativeRequest, NativeSignOutRequest } from "@azure/msal-common";
3
+ export declare class NativeBrokerPlugin implements INativeBrokerPlugin {
4
+ private logger;
5
+ isBrokerAvailable: boolean;
6
+ constructor();
7
+ setLogger(loggerOptions: LoggerOptions): void;
8
+ getAccountById(accountId: string, correlationId: string): Promise<AccountInfo>;
9
+ getAllAccounts(clientId: string, correlationId: string): Promise<AccountInfo[]>;
10
+ acquireTokenSilent(request: NativeRequest): Promise<AuthenticationResult>;
11
+ acquireTokenInteractive(request: NativeRequest, providedWindowHandle?: Buffer): Promise<AuthenticationResult>;
12
+ signOut(request: NativeSignOutRequest): Promise<void>;
13
+ private getAccount;
14
+ private readAccountById;
15
+ private generateRequestParameters;
16
+ private getAuthenticationResult;
17
+ private generateAccountInfo;
18
+ private isMsalRuntimeError;
19
+ private wrapError;
20
+ }
@@ -0,0 +1,6 @@
1
+ import { AuthError } from "@azure/msal-common";
2
+ export declare class NativeAuthError extends AuthError {
3
+ statusCode: number;
4
+ tag: number;
5
+ constructor(errorStatus: string, errorContext: string, errorCode: number, errorTag: number);
6
+ }
@@ -26,4 +26,32 @@ export declare class PersistenceError extends Error {
26
26
  * Error thrown when using the cross platform lock.
27
27
  */
28
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,7 @@ 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";
12
+ export { NativeBrokerPlugin } from "./broker/NativeBrokerPlugin";