@equinor/fusion-framework-module-msal-node 1.0.1 → 1.0.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 CHANGED
@@ -1,5 +1,35 @@
1
1
  # @equinor/fusion-framework-module-msal-node
2
2
 
3
+ ## 1.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#3343](https://github.com/equinor/fusion-framework/pull/3343) [`c1cd89a`](https://github.com/equinor/fusion-framework/commit/c1cd89abad4ca8f232a497316232d1f5ac8c530a) Thanks [@odinr](https://github.com/odinr)! - Comprehensive documentation overhaul with enhanced developer experience and platform-specific guidance.
8
+
9
+ - **Complete README rewrite** with modern structure and comprehensive examples
10
+ - **Added detailed API reference** with TypeScript interfaces and method documentation
11
+ - **Enhanced authentication mode documentation** with clear use cases and examples
12
+ - **Added comprehensive configuration guide** with required/optional settings tables
13
+ - **Created platform-specific libsecret setup guide** with Windows, macOS, and Linux instructions
14
+ - **Improved troubleshooting section** with common issues and platform-specific solutions
15
+ - **Added quick start examples** for all authentication modes (token_only, silent, interactive)
16
+ - **Enhanced security documentation** explaining platform keychains and encryption
17
+
18
+ **New Documentation:**
19
+
20
+ - `docs/libsecret.md` - Platform-specific credential storage setup guide
21
+ - Comprehensive Windows build tools installation instructions
22
+ - Enhanced Linux libsecret installation for multiple distributions
23
+ - macOS troubleshooting and setup guidance
24
+
25
+ **Key Improvements:**
26
+
27
+ - Clear separation between authentication modes with practical examples
28
+ - Platform-specific installation and troubleshooting guidance
29
+ - Better developer onboarding with quick start examples
30
+ - Comprehensive API reference with TypeScript interfaces
31
+ - Enhanced security documentation explaining credential storage
32
+
3
33
  ## 1.0.1
4
34
 
5
35
  ### Patch Changes
package/README.md CHANGED
@@ -1,125 +1,224 @@
1
- # Fusion MSAL Node Module
2
-
3
- `@equinor/fusion-framework-msal-node` enables secure authentication for the Fusion Framework in Node.js environments using Microsoft's MSAL (Microsoft Authentication Library) to integrate with Azure Active Directory (Azure AD).
1
+ `@equinor/fusion-framework-module-msal-node` provides secure Azure AD authentication for Node.js applications using Microsoft's MSAL (Microsoft Authentication Library). Perfect for CLI tools, background services, and automated processes that need to authenticate with Microsoft services.
4
2
 
5
3
  ## Features
6
4
 
7
- - **Simple Token Acquisition**: Easy-to-use API for acquiring authentication tokens.
8
- - **Multiple Auth Flows**: Supports client credentials and other Azure AD authentication flows.
9
- - **Token Caching**: Built-in caching for improved performance and security.
10
- - **Fusion Framework Integration**: Seamless authentication across Fusion Framework applications.
11
- - **Authentication Modes**:
12
- - `token_only`: Uses a pre-provided token for authentication (e.g., CI/CD, automation).
13
- - `silent`: Acquires tokens silently using cached or refresh tokens (background services, scripts).
14
- - `interactive`: Prompts users for authentication via a local HTTP server (CLI tools, development).
5
+ - **Multiple Authentication Modes**: Choose the right auth flow for your use case
6
+ - **Secure Token Storage**: Encrypted credential storage using platform keychains
7
+ - **Easy Integration**: Simple API that works seamlessly with Fusion Framework
8
+ - **Token Management**: Automatic token refresh and caching
9
+ - **Cross-Platform**: Works on Windows, macOS, and Linux
10
+ - **Zero Configuration**: Sensible defaults with optional customization
15
11
 
16
- ## Authentication Modes
12
+ ## Quick Start
17
13
 
18
- The module supports three authentication modes to suit different use cases:
14
+ ```bash
15
+ pnpm add @equinor/fusion-framework-module-msal-node
16
+ ```
19
17
 
20
- | Mode | Description | Use Case |
21
- | ------------- | ---------------------------------------------------------------------------- | ------------------------------------------ |
22
- | `token_only` | Uses a pre-obtained token, typically from environment variables. | CI/CD pipelines, automated processes. |
23
- | `silent` | Acquires tokens silently using cached or refresh tokens, without user input. | Background services, pre-seeding commands. |
24
- | `interactive` | Prompts user login via a browser, using a local HTTP server for callbacks. | CLI tools, development, manual operations. |
18
+ ```typescript
19
+ import { enableAuthModule } from '@equinor/fusion-framework-module-msal-node';
20
+ import { ModulesConfigurator } from '@equinor/fusion-framework-module';
25
21
 
26
- ### `token_only`
27
- Ideal for scenarios where a token is already available (e.g., via CI/CD). No interaction with Azure AD is required.
22
+ const configurator = new ModulesConfigurator();
28
23
 
29
- ### `silent`
30
- Uses cached or refresh tokens to authenticate without user interaction. Perfect for automated or background tasks.
24
+ enableAuthModule(configurator, (builder) => {
25
+ builder.setMode('interactive');
26
+ builder.setClientId('your-client-id');
27
+ builder.setTenantId('your-tenant-id');
28
+ });
31
29
 
32
- ### `interactive`
33
- Requires user interaction, launching a local HTTP server to handle browser-based authentication. Suitable for CLI or development workflows.
30
+ const framework = await initialize();
31
+ const token = await framework.auth.acquireAccessToken({
32
+ scopes: ['https://graph.microsoft.com/.default']
33
+ });
34
+ ```
34
35
 
35
- ## Secure Token Storage
36
+ ## Authentication Modes
36
37
 
37
- The module leverages `@azure/msal-node-extensions` for secure, encrypted token storage:
38
+ Choose the authentication mode that best fits your application's needs:
38
39
 
39
- - **Encryption**: Tokens are encrypted at rest using platform-specific mechanisms (e.g., DPAPI on Windows, Keychain on macOS).
40
- - **Cross-Platform**: Supports Windows, macOS, and Linux.
41
- - **Persistence**: Tokens are stored securely for reuse across sessions, minimizing re-authentication.
40
+ | Mode | Description | Best For | User Interaction |
41
+ |------|-------------|----------|------------------|
42
+ | **`token_only`** | Uses a pre-provided access token | CI/CD pipelines, serverless functions | None |
43
+ | **`silent`** | Uses cached credentials for background auth | Background services, scheduled tasks | None |
44
+ | **`interactive`** | Browser-based login with local server | CLI tools, development, user-facing apps | Required |
42
45
 
43
- This ensures sensitive token data is protected, reducing the risk of unauthorized access.
46
+ ### When to Use Each Mode
44
47
 
45
- ## Usage
48
+ - **`token_only`**: When you already have a valid access token (e.g., from environment variables, CI/CD secrets)
49
+ - **`silent`**: When you need background authentication without user interaction (e.g., scheduled jobs, background services)
50
+ - **`interactive`**: When you need user login (e.g., CLI tools, development environments, user-facing applications)
46
51
 
47
- Below are examples for enabling the module in each authentication mode.
52
+ ## Secure Token Storage
53
+
54
+ The module uses `@azure/msal-node-extensions` for enterprise-grade security:
55
+
56
+ - **🔒 Platform Keychains**: Windows Credential Manager, macOS Keychain, Linux libsecret
57
+ - **🔐 Encryption at Rest**: Tokens encrypted using platform-specific mechanisms
58
+ - **🔄 Automatic Refresh**: Seamless token renewal without user intervention
59
+ - **🌐 Cross-Platform**: Consistent security across Windows, macOS, and Linux
48
60
 
49
- ### `token_only` Mode
61
+ ## Usage Examples
50
62
 
51
- Use a pre-obtained token for authentication.
63
+ ### Token-Only Mode (CI/CD)
52
64
 
53
- ```ts
54
- import { enableAuthModule, type MsalNodeModule } from '@equinor/fusion-framework-msal-node';
65
+ Perfect for automated processes where you already have a valid token:
66
+
67
+ ```typescript
68
+ import { enableAuthModule } from '@equinor/fusion-framework-module-msal-node';
55
69
  import { ModulesConfigurator } from '@equinor/fusion-framework-module';
56
70
 
57
- const configurator = new ModulesConfigurator<[MsalNodeModule]>();
71
+ const configurator = new ModulesConfigurator();
58
72
 
59
73
  enableAuthModule(configurator, (builder) => {
60
74
  builder.setMode('token_only');
61
- builder.setAccessToken('your-access-token'); // Provide your token
75
+ builder.setAccessToken(process.env.ACCESS_TOKEN); // From CI/CD secrets
62
76
  });
63
77
 
64
- const instance = await initialize();
65
- console.log(typeof instance.auth); // AuthTokenProvider
66
- console.log(await instance.auth.acquireAccessToken({ scopes: ['user.read'] }));
78
+ const framework = await initialize();
79
+ const token = await framework.auth.acquireAccessToken({
80
+ scopes: ['https://graph.microsoft.com/.default']
81
+ });
67
82
  ```
68
83
 
69
- ### `silent` Mode
84
+ ### Silent Mode (Background Services)
70
85
 
71
- Authenticate silently using cached or refresh tokens.
86
+ For background services that need to authenticate without user interaction:
72
87
 
73
- ```ts
74
- import { enableAuthModule, type MsalNodeModule } from '@equinor/fusion-framework-msal-node';
88
+ ```typescript
89
+ import { enableAuthModule } from '@equinor/fusion-framework-module-msal-node';
75
90
  import { ModulesConfigurator } from '@equinor/fusion-framework-module';
76
91
 
77
- const configurator = new ModulesConfigurator<[MsalNodeModule]>();
92
+ const configurator = new ModulesConfigurator();
78
93
 
79
94
  enableAuthModule(configurator, (builder) => {
80
95
  builder.setMode('silent');
81
- builder.setClientId('your-client-id'); // Azure AD client ID
82
- builder.setTenantId('your-tenant-id'); // Azure AD tenant ID
96
+ builder.setClientId(process.env.AZURE_CLIENT_ID);
97
+ builder.setTenantId(process.env.AZURE_TENANT_ID);
83
98
  });
84
99
 
85
- const instance = await initialize();
86
- console.log(typeof instance.auth); // AuthTokenProvider
87
- console.log(await instance.auth.acquireAccessToken({ scopes: ['user.read'] }));
100
+ const framework = await initialize();
101
+
102
+ // This will use cached credentials or fail if no valid cache exists
103
+ try {
104
+ const token = await framework.auth.acquireAccessToken({
105
+ scopes: ['https://graph.microsoft.com/.default']
106
+ });
107
+ console.log('Authenticated successfully');
108
+ } catch (error) {
109
+ console.error('Silent authentication failed:', error.message);
110
+ }
88
111
  ```
89
112
 
90
- ### `interactive` Mode
113
+ ### Interactive Mode (CLI Tools)
91
114
 
92
- Prompt the user for browser-based authentication.
115
+ For CLI tools and development environments that require user login:
93
116
 
94
- ```ts
95
- import { enableAuthModule, type MsalNodeModule } from '@equinor/fusion-framework-msal-node';
117
+ ```typescript
118
+ import { enableAuthModule } from '@equinor/fusion-framework-module-msal-node';
96
119
  import { ModulesConfigurator } from '@equinor/fusion-framework-module';
97
120
 
98
- const configurator = new ModulesConfigurator<[MsalNodeModule]>();
121
+ const configurator = new ModulesConfigurator();
99
122
 
100
123
  enableAuthModule(configurator, (builder) => {
101
124
  builder.setMode('interactive');
102
- builder.setClientId('your-client-id'); // Azure AD client ID
103
- builder.setTenantId('your-tenant-id'); // Azure AD tenant ID
104
- builder.setServerPort(3000); // Local server port for auth callback
125
+ builder.setClientId(process.env.AZURE_CLIENT_ID);
126
+ builder.setTenantId(process.env.AZURE_TENANT_ID);
127
+ builder.setServerPort(3000); // Optional: custom port
105
128
  builder.setServerOnOpen((url) => {
106
- console.log(`Please navigate to: ${url}`);
129
+ console.log(`🌐 Please open your browser and navigate to: ${url}`);
107
130
  });
108
131
  });
109
132
 
110
- const instance = await initialize();
111
- console.log(typeof instance.auth); // AuthProviderInteractive
112
- console.log(await instance.auth.login({ scopes: ['user.read'] }));
133
+ const framework = await initialize();
134
+
135
+ // This will open a browser for user login
136
+ const result = await framework.auth.login({
137
+ scopes: ['https://graph.microsoft.com/.default']
138
+ });
139
+ console.log('Login successful:', result.account?.username);
113
140
  ```
114
141
 
115
142
  ## Configuration
116
143
 
117
- - **Client ID and Tenant ID**: Obtain these from your Azure AD application registration.
118
- - **Scopes**: Specify required permissions (e.g., `['user.read']`) when acquiring tokens.
119
- - **Server Port**: For `interactive` mode, ensure the port is available and not blocked by firewalls.
144
+ ### Required Settings
145
+
146
+ | Setting | Description | Required For |
147
+ |---------|-------------|--------------|
148
+ | `clientId` | Azure AD application client ID | `silent`, `interactive` |
149
+ | `tenantId` | Azure AD tenant ID | `silent`, `interactive` |
150
+ | `accessToken` | Pre-obtained access token | `token_only` |
151
+
152
+ ### Optional Settings
153
+
154
+ | Setting | Description | Default | Mode |
155
+ |---------|-------------|---------|------|
156
+ | `serverPort` | Local server port for auth callbacks | `3000` | `interactive` |
157
+ | `serverOnOpen` | Callback when browser opens | `undefined` | `interactive` |
158
+
159
+ ### Environment Variables
160
+
161
+ ```bash
162
+ # Required for silent/interactive modes
163
+ AZURE_CLIENT_ID=your-client-id
164
+ AZURE_TENANT_ID=your-tenant-id
165
+
166
+ # Required for token_only mode
167
+ ACCESS_TOKEN=your-access-token
168
+ ```
169
+
170
+ ## API Reference
171
+
172
+ ### `enableAuthModule(configurator, configure)`
173
+
174
+ Enables the MSAL Node module in your Fusion Framework application.
175
+
176
+ **Parameters:**
177
+ - `configurator`: `ModulesConfigurator` - The modules configurator instance
178
+ - `configure`: `(builder: IAuthConfigurator) => void` - Configuration function
179
+
180
+ ### `IAuthProvider`
181
+
182
+ The authentication provider interface available at `framework.auth`:
183
+
184
+ ```typescript
185
+ interface IAuthProvider {
186
+ // Acquire an access token for the specified scopes
187
+ acquireAccessToken(options: {
188
+ scopes: string[];
189
+ interactive?: boolean
190
+ }): Promise<string>;
191
+
192
+ // Login (interactive mode only)
193
+ login(options: { scopes: string[] }): Promise<AuthenticationResult>;
194
+
195
+ // Logout (interactive mode only)
196
+ logout(): Promise<void>;
197
+ }
198
+ ```
199
+
120
200
 
121
201
  ## Troubleshooting
122
202
 
123
- - **Token Issues**: Verify your token, client ID, or tenant ID are correct.
124
- - **Interactive Mode Fails**: Check if the specified port is free and accessible.
125
- - **Silent Mode Fails**: Ensure cached tokens or refresh tokens are valid.
203
+ ### Common Issues
204
+
205
+ | Issue | Solution |
206
+ |-------|----------|
207
+ | **Invalid client/tenant ID** | Verify your Azure AD app registration settings |
208
+ | **Port already in use** | Change the `serverPort` or kill the process using the port |
209
+ | **Silent auth fails** | Ensure you've logged in interactively first to cache credentials |
210
+ | **Token expired** | The module handles refresh automatically; check your scopes |
211
+ | **Credential storage errors** | See our [credential storage guide](docs/libsecret.md) |
212
+
213
+ ### Getting Help
214
+
215
+ - 📖 [Credential Storage Troubleshooting](docs/libsecret.md) - Platform-specific setup help
216
+ - 🐛 [Report Issues](https://github.com/equinor/fusion/issues) - Bug reports and feature requests
217
+
218
+ ## Additional Resources
219
+
220
+ - [Microsoft Graph API Documentation](https://docs.microsoft.com/en-us/graph/)
221
+ - [Azure AD App Registration Guide](https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app)
222
+ - [MSAL Node Documentation](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-node)
223
+ - [Fusion Framework Documentation](https://github.com/equinor/fusion-framework)
224
+
@@ -1,3 +1,3 @@
1
1
  // Generated by genversion.
2
- export const version = '1.0.1';
2
+ export const version = '1.0.2';
3
3
  //# sourceMappingURL=version.js.map