@equinor/fusion-framework-module-msal-node 4.1.1 → 4.1.2
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.
- package/CHANGELOG.md +10 -0
- package/dist/esm/create-auth-cache.js +21 -5
- package/dist/esm/create-auth-cache.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/create-auth-cache.d.ts +5 -3
- package/dist/types/version.d.ts +1 -1
- package/package.json +6 -4
- package/src/create-auth-cache.ts +28 -21
- package/src/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @equinor/fusion-framework-module-msal-node
|
|
2
2
|
|
|
3
|
+
## 4.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3e82dee: Move `@azure/msal-node-extensions` to `optionalDependencies` and convert its static import to a dynamic loader.
|
|
8
|
+
|
|
9
|
+
The native `keytar` addon (required by `msal-node-extensions` for OS keychain access) previously caused `pnpm install` to fail on Linux environments without `libsecret-1`, and the static top-level import caused the module to fail to load entirely when the optional build did not succeed.
|
|
10
|
+
|
|
11
|
+
Token cache persistence remains fully functional in interactive desktop environments. When the optional dependency is absent, a clear, actionable error is thrown at call-time instead of a raw `ERR_MODULE_NOT_FOUND` at import-time.
|
|
12
|
+
|
|
3
13
|
## 4.1.1
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
import { DataProtectionScope, Environment, PersistenceCreator, PersistenceCachePlugin, } from '@azure/msal-node-extensions';
|
|
2
1
|
import { tmpdir } from 'node:os';
|
|
3
2
|
import path from 'node:path';
|
|
3
|
+
const importMsalNodeExtensions = async () => {
|
|
4
|
+
try {
|
|
5
|
+
return await import('@azure/msal-node-extensions');
|
|
6
|
+
}
|
|
7
|
+
catch (cause) {
|
|
8
|
+
throw new Error('Failed to load @azure/msal-node-extensions. ' +
|
|
9
|
+
'Token cache persistence requires a native module (keytar/libsecret) that is only ' +
|
|
10
|
+
'available in interactive desktop environments. Install the optional dependency or ' +
|
|
11
|
+
'use a non-caching auth mode.', { cause });
|
|
12
|
+
}
|
|
13
|
+
};
|
|
4
14
|
/**
|
|
5
15
|
* Resolves the directory path for storing the authentication cache.
|
|
6
16
|
*
|
|
@@ -8,7 +18,8 @@ import path from 'node:path';
|
|
|
8
18
|
*
|
|
9
19
|
* @returns The resolved cache directory path as a string.
|
|
10
20
|
*/
|
|
11
|
-
const resolveCachePath = () => {
|
|
21
|
+
const resolveCachePath = async () => {
|
|
22
|
+
const { Environment } = await importMsalNodeExtensions();
|
|
12
23
|
return Environment?.getUserRootDirectory() ?? tmpdir();
|
|
13
24
|
};
|
|
14
25
|
/**
|
|
@@ -18,8 +29,8 @@ const resolveCachePath = () => {
|
|
|
18
29
|
* @param clientId - The Azure AD client/application ID.
|
|
19
30
|
* @returns The full file path for the cache file.
|
|
20
31
|
*/
|
|
21
|
-
const resolveCacheFilePath = (tenantId, clientId) => {
|
|
22
|
-
return path.join(resolveCachePath(), `.token-cache-${tenantId}_${clientId}`);
|
|
32
|
+
const resolveCacheFilePath = async (tenantId, clientId) => {
|
|
33
|
+
return path.join(await resolveCachePath(), `.token-cache-${tenantId}_${clientId}`);
|
|
23
34
|
};
|
|
24
35
|
/**
|
|
25
36
|
* Creates a persistence cache for storing authentication data securely on disk.
|
|
@@ -27,13 +38,17 @@ const resolveCacheFilePath = (tenantId, clientId) => {
|
|
|
27
38
|
* The cache is encrypted and scoped to the current user for security. It is uniquely identified
|
|
28
39
|
* by the provided tenant and client IDs, and is associated with the 'fusion-framework' service.
|
|
29
40
|
*
|
|
41
|
+
* Requires `@azure/msal-node-extensions` to be installed (optional dependency).
|
|
42
|
+
* Only available in interactive desktop environments with a system keychain.
|
|
43
|
+
*
|
|
30
44
|
* @param tenantId - The Azure AD tenant ID used to identify the cache.
|
|
31
45
|
* @param clientId - The Azure AD client/application ID used to identify the cache.
|
|
32
46
|
* @returns A promise that resolves to the created persistence cache instance.
|
|
33
47
|
*/
|
|
34
48
|
export const createPersistenceCache = async (tenantId, clientId) => {
|
|
49
|
+
const { DataProtectionScope, PersistenceCreator } = await importMsalNodeExtensions();
|
|
35
50
|
return PersistenceCreator.createPersistence({
|
|
36
|
-
cachePath: resolveCacheFilePath(tenantId, clientId),
|
|
51
|
+
cachePath: await resolveCacheFilePath(tenantId, clientId),
|
|
37
52
|
serviceName: 'fusion-framework',
|
|
38
53
|
accountName: [tenantId, clientId].join('_'),
|
|
39
54
|
dataProtectionScope: DataProtectionScope.CurrentUser,
|
|
@@ -62,6 +77,7 @@ export const clearPersistenceCache = async (tenantId, clientId) => {
|
|
|
62
77
|
* @returns A promise that resolves to an instance of `PersistenceCachePlugin`.
|
|
63
78
|
*/
|
|
64
79
|
export const createPersistenceCachePlugin = async (tenantId, clientId) => {
|
|
80
|
+
const { PersistenceCachePlugin } = await importMsalNodeExtensions();
|
|
65
81
|
return new PersistenceCachePlugin(await createPersistenceCache(tenantId, clientId));
|
|
66
82
|
};
|
|
67
83
|
//# sourceMappingURL=create-auth-cache.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-auth-cache.js","sourceRoot":"","sources":["../../src/create-auth-cache.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"create-auth-cache.js","sourceRoot":"","sources":["../../src/create-auth-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,wBAAwB,GAAG,KAAK,IAEpC,EAAE;IACF,IAAI,CAAC;QACH,OAAO,MAAM,MAAM,CAAC,6BAA6B,CAAC,CAAC;IACrD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,8CAA8C;YAC5C,mFAAmF;YACnF,oF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