@equinor/fusion-framework-module-msal-node 4.1.0 → 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.
@@ -1,15 +1,17 @@
1
- import { PersistenceCachePlugin, type IPersistence } from '@azure/msal-node-extensions';
2
1
  /**
3
2
  * Creates a persistence cache for storing authentication data securely on disk.
4
3
  *
5
4
  * The cache is encrypted and scoped to the current user for security. It is uniquely identified
6
5
  * by the provided tenant and client IDs, and is associated with the 'fusion-framework' service.
7
6
  *
7
+ * Requires `@azure/msal-node-extensions` to be installed (optional dependency).
8
+ * Only available in interactive desktop environments with a system keychain.
9
+ *
8
10
  * @param tenantId - The Azure AD tenant ID used to identify the cache.
9
11
  * @param clientId - The Azure AD client/application ID used to identify the cache.
10
12
  * @returns A promise that resolves to the created persistence cache instance.
11
13
  */
12
- export declare const createPersistenceCache: (tenantId: string, clientId: string) => Promise<IPersistence>;
14
+ export declare const createPersistenceCache: (tenantId: string, clientId: string) => Promise<import("@azure/msal-node-extensions").IPersistence>;
13
15
  /**
14
16
  * Clears the persistence cache for a specific tenant and client.
15
17
  *
@@ -29,4 +31,4 @@ export declare const clearPersistenceCache: (tenantId: string, clientId: string)
29
31
  * @param clientId - The Azure AD client/application ID.
30
32
  * @returns A promise that resolves to an instance of `PersistenceCachePlugin`.
31
33
  */
32
- export declare const createPersistenceCachePlugin: (tenantId: string, clientId: string) => Promise<PersistenceCachePlugin>;
34
+ export declare const createPersistenceCachePlugin: (tenantId: string, clientId: string) => Promise<import("@azure/msal-node-extensions").PersistenceCachePlugin>;
@@ -1 +1 @@
1
- export declare const version = "4.1.0";
1
+ export declare const version = "4.1.2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/fusion-framework-module-msal-node",
3
- "version": "4.1.0",
3
+ "version": "4.1.2",
4
4
  "description": "Fusion Framework module for secure Azure AD authentication in Node.js using MSAL. Supports interactive, silent, and token-only authentication modes with encrypted token storage.",
5
5
  "type": "module",
6
6
  "main": "dist/esm/index.js",
@@ -34,12 +34,14 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@azure/msal-node": "^5.0.2",
37
- "@azure/msal-node-extensions": "^5.0.2",
38
37
  "open": "^11.0.0",
39
- "@equinor/fusion-framework-module": "^6.0.0"
38
+ "@equinor/fusion-framework-module": "^6.1.0"
39
+ },
40
+ "optionalDependencies": {
41
+ "@azure/msal-node-extensions": "^5.0.2"
40
42
  },
41
43
  "devDependencies": {
42
- "typescript": "^5.9.3"
44
+ "typescript": "^6.0.3"
43
45
  },
44
46
  "scripts": {
45
47
  "build": "tsc -b"
@@ -1,15 +1,22 @@
1
- import {
2
- DataProtectionScope,
3
- Environment,
4
- PersistenceCreator,
5
- PersistenceCachePlugin,
6
- type IPersistence,
7
- } from '@azure/msal-node-extensions';
8
-
9
1
  import { tmpdir } from 'node:os';
10
-
11
2
  import path from 'node:path';
12
3
 
4
+ const importMsalNodeExtensions = async (): Promise<
5
+ typeof import('@azure/msal-node-extensions')
6
+ > => {
7
+ try {
8
+ return await import('@azure/msal-node-extensions');
9
+ } catch (cause) {
10
+ throw new Error(
11
+ 'Failed to load @azure/msal-node-extensions. ' +
12
+ 'Token cache persistence requires a native module (keytar/libsecret) that is only ' +
13
+ 'available in interactive desktop environments. Install the optional dependency or ' +
14
+ 'use a non-caching auth mode.',
15
+ { cause },
16
+ );
17
+ }
18
+ };
19
+
13
20
  /**
14
21
  * Resolves the directory path for storing the authentication cache.
15
22
  *
@@ -17,7 +24,8 @@ import path from 'node:path';
17
24
  *
18
25
  * @returns The resolved cache directory path as a string.
19
26
  */
20
- const resolveCachePath = () => {
27
+ const resolveCachePath = async (): Promise<string> => {
28
+ const { Environment } = await importMsalNodeExtensions();
21
29
  return Environment?.getUserRootDirectory() ?? tmpdir();
22
30
  };
23
31
 
@@ -28,8 +36,8 @@ const resolveCachePath = () => {
28
36
  * @param clientId - The Azure AD client/application ID.
29
37
  * @returns The full file path for the cache file.
30
38
  */
31
- const resolveCacheFilePath = (tenantId: string, clientId: string) => {
32
- return path.join(resolveCachePath(), `.token-cache-${tenantId}_${clientId}`);
39
+ const resolveCacheFilePath = async (tenantId: string, clientId: string): Promise<string> => {
40
+ return path.join(await resolveCachePath(), `.token-cache-${tenantId}_${clientId}`);
33
41
  };
34
42
 
35
43
  /**
@@ -38,16 +46,17 @@ const resolveCacheFilePath = (tenantId: string, clientId: string) => {
38
46
  * The cache is encrypted and scoped to the current user for security. It is uniquely identified
39
47
  * by the provided tenant and client IDs, and is associated with the 'fusion-framework' service.
40
48
  *
49
+ * Requires `@azure/msal-node-extensions` to be installed (optional dependency).
50
+ * Only available in interactive desktop environments with a system keychain.
51
+ *
41
52
  * @param tenantId - The Azure AD tenant ID used to identify the cache.
42
53
  * @param clientId - The Azure AD client/application ID used to identify the cache.
43
54
  * @returns A promise that resolves to the created persistence cache instance.
44
55
  */
45
- export const createPersistenceCache = async (
46
- tenantId: string,
47
- clientId: string,
48
- ): Promise<IPersistence> => {
56
+ export const createPersistenceCache = async (tenantId: string, clientId: string) => {
57
+ const { DataProtectionScope, PersistenceCreator } = await importMsalNodeExtensions();
49
58
  return PersistenceCreator.createPersistence({
50
- cachePath: resolveCacheFilePath(tenantId, clientId),
59
+ cachePath: await resolveCacheFilePath(tenantId, clientId),
51
60
  serviceName: 'fusion-framework',
52
61
  accountName: [tenantId, clientId].join('_'),
53
62
  dataProtectionScope: DataProtectionScope.CurrentUser,
@@ -77,9 +86,7 @@ export const clearPersistenceCache = async (tenantId: string, clientId: string):
77
86
  * @param clientId - The Azure AD client/application ID.
78
87
  * @returns A promise that resolves to an instance of `PersistenceCachePlugin`.
79
88
  */
80
- export const createPersistenceCachePlugin = async (
81
- tenantId: string,
82
- clientId: string,
83
- ): Promise<PersistenceCachePlugin> => {
89
+ export const createPersistenceCachePlugin = async (tenantId: string, clientId: string) => {
90
+ const { PersistenceCachePlugin } = await importMsalNodeExtensions();
84
91
  return new PersistenceCachePlugin(await createPersistenceCache(tenantId, clientId));
85
92
  };
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '4.1.0';
2
+ export const version = '4.1.2';