playwright-ms-auth 0.0.10
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/LICENSE +21 -0
- package/README.md +525 -0
- package/bin/ms-auth +2 -0
- package/lib/authenticate.d.ts +10 -0
- package/lib/authenticate.d.ts.map +1 -0
- package/lib/authenticate.js +213 -0
- package/lib/authenticate.js.map +1 -0
- package/lib/certAuth.d.ts +21 -0
- package/lib/certAuth.d.ts.map +1 -0
- package/lib/certAuth.js +82 -0
- package/lib/certAuth.js.map +1 -0
- package/lib/cli.d.ts +3 -0
- package/lib/cli.d.ts.map +1 -0
- package/lib/cli.js +109 -0
- package/lib/cli.js.map +1 -0
- package/lib/config.d.ts +10 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +115 -0
- package/lib/config.js.map +1 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +17 -0
- package/lib/index.js.map +1 -0
- package/lib/providers/AzureKeyVaultProvider.d.ts +17 -0
- package/lib/providers/AzureKeyVaultProvider.d.ts.map +1 -0
- package/lib/providers/AzureKeyVaultProvider.js +105 -0
- package/lib/providers/AzureKeyVaultProvider.js.map +1 -0
- package/lib/providers/CredentialProvider.d.ts +24 -0
- package/lib/providers/CredentialProvider.d.ts.map +1 -0
- package/lib/providers/CredentialProvider.js +10 -0
- package/lib/providers/CredentialProvider.js.map +1 -0
- package/lib/providers/CredentialProviderFactory.d.ts +20 -0
- package/lib/providers/CredentialProviderFactory.d.ts.map +1 -0
- package/lib/providers/CredentialProviderFactory.js +37 -0
- package/lib/providers/CredentialProviderFactory.js.map +1 -0
- package/lib/providers/EnvironmentProvider.d.ts +13 -0
- package/lib/providers/EnvironmentProvider.d.ts.map +1 -0
- package/lib/providers/EnvironmentProvider.js +52 -0
- package/lib/providers/EnvironmentProvider.js.map +1 -0
- package/lib/providers/GitHubSecretsProvider.d.ts +13 -0
- package/lib/providers/GitHubSecretsProvider.d.ts.map +1 -0
- package/lib/providers/GitHubSecretsProvider.js +59 -0
- package/lib/providers/GitHubSecretsProvider.js.map +1 -0
- package/lib/providers/LocalFileProvider.d.ts +13 -0
- package/lib/providers/LocalFileProvider.d.ts.map +1 -0
- package/lib/providers/LocalFileProvider.js +77 -0
- package/lib/providers/LocalFileProvider.js.map +1 -0
- package/lib/providers/index.d.ts +7 -0
- package/lib/providers/index.d.ts.map +1 -0
- package/lib/providers/index.js +7 -0
- package/lib/providers/index.js.map +1 -0
- package/lib/types.d.ts +111 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +37 -0
- package/lib/types.js.map +1 -0
- package/lib/utils.d.ts +30 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +75 -0
- package/lib/utils.js.map +1 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +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.
|
package/README.md
ADDED
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
# Playwright Microsoft Authentication
|
|
2
|
+
|
|
3
|
+
[](https://github.com/deepakkamboj/playwright-ms-auth/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/playwright-ms-auth)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://nodejs.org/)
|
|
7
|
+
|
|
8
|
+
[](https://www.typescriptlang.org/)
|
|
9
|
+
[](https://playwright.dev/)
|
|
10
|
+
[](https://azure.microsoft.com/)
|
|
11
|
+
|
|
12
|
+
> Enterprise-grade authentication solution for Playwright E2E tests with Microsoft Entra ID (formerly Azure AD)
|
|
13
|
+
|
|
14
|
+
A robust, production-ready authentication framework that simplifies Microsoft identity integration in Playwright test suites. Built with the Abstract Factory pattern, it supports both password and certificate-based authentication across multiple credential providers including Azure KeyVault, local files, environment variables, and GitHub Secrets.
|
|
15
|
+
|
|
16
|
+
Perfect for enterprise test automation requiring secure, reusable authentication flows with multi-region support and smart session caching.
|
|
17
|
+
|
|
18
|
+
## Tech Stack
|
|
19
|
+
|
|
20
|
+
### Core Dependencies
|
|
21
|
+
|
|
22
|
+
- **[Playwright](https://playwright.dev/)** (v1.44.1) - Browser automation framework
|
|
23
|
+
- **[TypeScript](https://www.typescriptlang.org/)** (v5.4.4) - Type-safe development
|
|
24
|
+
- **[Commander.js](https://github.com/tj/commander.js)** (v11.0.0) - CLI framework
|
|
25
|
+
- **[@azure/keyvault-secrets](https://www.npmjs.com/package/@azure/keyvault-secrets)** (v4.8.0) - Azure KeyVault integration
|
|
26
|
+
- **[@azure/identity](https://www.npmjs.com/package/@azure/identity)** (v4.2.1) - Azure authentication
|
|
27
|
+
|
|
28
|
+
### Runtime Requirements
|
|
29
|
+
|
|
30
|
+
- **Node.js** ≥18
|
|
31
|
+
- **Playwright Chromium** browser
|
|
32
|
+
|
|
33
|
+
### Build & Development
|
|
34
|
+
|
|
35
|
+
- **TypeScript Compiler** - ES2020 target, ESM modules
|
|
36
|
+
- **Rimraf** - Cross-platform file cleanup
|
|
37
|
+
|
|
38
|
+
## Features
|
|
39
|
+
|
|
40
|
+
- 🔐 **Multiple Authentication Methods**: Password and certificate-based authentication
|
|
41
|
+
- 🏭 **Abstract Factory Pattern**: Easily extensible credential provider system
|
|
42
|
+
- ☁️ **Multiple Providers**: Azure KeyVault, Local File, Environment Variables, GitHub Secrets
|
|
43
|
+
- 🌍 **Multi-Region Support**: Works with different Microsoft Entra endpoints
|
|
44
|
+
- 🔧 **CLI Tool**: Full-featured command-line interface
|
|
45
|
+
- 🌳 **Environment Variables**: Complete configuration via environment variables
|
|
46
|
+
- 💾 **Smart Caching**: Automatic storage state management with expiration
|
|
47
|
+
- 📝 **TypeScript**: Full type safety and IntelliSense support
|
|
48
|
+
- 🐛 **Debug Logging**: Comprehensive logging for troubleshooting
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm install playwright-ms-auth
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Quick Start
|
|
57
|
+
|
|
58
|
+
### Using CLI
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# Authenticate with Azure KeyVault
|
|
62
|
+
npx ms-auth login \
|
|
63
|
+
--url https://your-app.com \
|
|
64
|
+
--email user@company.com \
|
|
65
|
+
--credential-provider azure-keyvault \
|
|
66
|
+
--keyvault-endpoint https://your-vault.vault.azure.net \
|
|
67
|
+
--keyvault-secret your-secret-name \
|
|
68
|
+
--debug
|
|
69
|
+
|
|
70
|
+
# Authenticate with local certificate file
|
|
71
|
+
npx ms-auth login \
|
|
72
|
+
--url https://your-app.com \
|
|
73
|
+
--email user@company.com \
|
|
74
|
+
--credential-type certificate \
|
|
75
|
+
--credential-provider local-file \
|
|
76
|
+
--local-file ./cert.pfx
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Using Programmatically
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { authenticate, loadConfigFromEnv } from "playwright-ms-auth";
|
|
83
|
+
|
|
84
|
+
// Load configuration from environment variables
|
|
85
|
+
const config = loadConfigFromEnv();
|
|
86
|
+
|
|
87
|
+
// Perform authentication
|
|
88
|
+
await authenticate(config, "https://your-app.com");
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### In Playwright Tests
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import { test as base } from "@playwright/test";
|
|
95
|
+
import { loadStorageState, type MsAuthConfig } from "playwright-ms-auth";
|
|
96
|
+
|
|
97
|
+
const config: MsAuthConfig = {
|
|
98
|
+
email: "user@company.com",
|
|
99
|
+
credentialType: "certificate",
|
|
100
|
+
credentialProvider: "azure-keyvault",
|
|
101
|
+
providerConfig: {
|
|
102
|
+
keyVaultEndpoint: "https://your-vault.vault.azure.net",
|
|
103
|
+
secretName: "your-cert-secret",
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const test = base.extend({
|
|
108
|
+
context: async ({ browser }, use) => {
|
|
109
|
+
const storagePath = await loadStorageState(config);
|
|
110
|
+
const context = await browser.newContext({ storageState: storagePath });
|
|
111
|
+
await use(context);
|
|
112
|
+
await context.close();
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("authenticated test", async ({ page }) => {
|
|
117
|
+
await page.goto("https://your-app.com");
|
|
118
|
+
// You're already authenticated!
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Credential Providers
|
|
123
|
+
|
|
124
|
+
### Azure KeyVault
|
|
125
|
+
|
|
126
|
+
Store credentials securely in Azure KeyVault.
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
const config: MsAuthConfig = {
|
|
130
|
+
email: "user@company.com",
|
|
131
|
+
credentialType: "certificate", // or 'password'
|
|
132
|
+
credentialProvider: "azure-keyvault",
|
|
133
|
+
providerConfig: {
|
|
134
|
+
keyVaultEndpoint: "https://your-vault.vault.azure.net",
|
|
135
|
+
secretName: "your-secret-name",
|
|
136
|
+
secretVersion: "latest", // optional
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**Environment Variables:**
|
|
142
|
+
|
|
143
|
+
- `MS_AUTH_KEYVAULT_ENDPOINT`
|
|
144
|
+
- `MS_AUTH_KEYVAULT_SECRET_NAME`
|
|
145
|
+
|
|
146
|
+
### Local File
|
|
147
|
+
|
|
148
|
+
Read credentials from local file system.
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
const config: MsAuthConfig = {
|
|
152
|
+
email: "user@company.com",
|
|
153
|
+
credentialType: "certificate",
|
|
154
|
+
credentialProvider: "local-file",
|
|
155
|
+
providerConfig: {
|
|
156
|
+
filePath: "./path/to/cert.pfx",
|
|
157
|
+
certificatePassword: "optional-password", // for encrypted certificates
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
**Environment Variables:**
|
|
163
|
+
|
|
164
|
+
- `MS_AUTH_LOCAL_FILE_PATH`
|
|
165
|
+
- `MS_AUTH_CERTIFICATE_PASSWORD`
|
|
166
|
+
|
|
167
|
+
### Environment Variables
|
|
168
|
+
|
|
169
|
+
Read credentials directly from environment variables.
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
const config: MsAuthConfig = {
|
|
173
|
+
email: "user@company.com",
|
|
174
|
+
credentialType: "password",
|
|
175
|
+
credentialProvider: "environment",
|
|
176
|
+
providerConfig: {
|
|
177
|
+
variableName: "MY_PASSWORD_VAR",
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
**Environment Variables:**
|
|
183
|
+
|
|
184
|
+
- `MS_AUTH_ENV_VARIABLE_NAME`
|
|
185
|
+
|
|
186
|
+
### GitHub Secrets
|
|
187
|
+
|
|
188
|
+
Use GitHub Actions secrets (reads from environment).
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
const config: MsAuthConfig = {
|
|
192
|
+
email: "user@company.com",
|
|
193
|
+
credentialType: "certificate",
|
|
194
|
+
credentialProvider: "github-secrets",
|
|
195
|
+
providerConfig: {
|
|
196
|
+
repository: "owner/repo",
|
|
197
|
+
secretName: "MY_CERT_SECRET",
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
**Environment Variables:**
|
|
203
|
+
|
|
204
|
+
- `MS_AUTH_GITHUB_REPOSITORY`
|
|
205
|
+
- `MS_AUTH_GITHUB_SECRET_NAME`
|
|
206
|
+
- `MS_AUTH_GITHUB_TOKEN` (optional)
|
|
207
|
+
|
|
208
|
+
## Environment Variables
|
|
209
|
+
|
|
210
|
+
All configuration can be provided via environment variables. Run `npx ms-auth env-help` for complete list.
|
|
211
|
+
|
|
212
|
+
### Core Configuration
|
|
213
|
+
|
|
214
|
+
- `MS_AUTH_EMAIL` - User email address
|
|
215
|
+
- `MS_AUTH_CREDENTIAL_TYPE` - `password` or `certificate`
|
|
216
|
+
- `MS_AUTH_CREDENTIAL_PROVIDER` - Provider type
|
|
217
|
+
- `MS_AUTH_OUTPUT_DIR` - Directory for storage state files
|
|
218
|
+
- `MS_AUTH_LOGIN_ENDPOINT` - Entra endpoint (default: `login.microsoftonline.com`)
|
|
219
|
+
- `MS_AUTH_STORAGE_STATE_EXPIRATION` - Hours until state expires (default: 24)
|
|
220
|
+
- `SYSTEM_DEBUG` - Enable debug logging (`true`/`false`)
|
|
221
|
+
|
|
222
|
+
## Architecture
|
|
223
|
+
|
|
224
|
+
### High-Level Architecture
|
|
225
|
+
|
|
226
|
+
```mermaid
|
|
227
|
+
flowchart TB
|
|
228
|
+
subgraph CLI["CLI Layer"]
|
|
229
|
+
CMD[ms-auth CLI]
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
subgraph Core["Core Authentication"]
|
|
233
|
+
AUTH[authenticate.ts]
|
|
234
|
+
CERT[certAuth.ts]
|
|
235
|
+
CONFIG[config.ts]
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
subgraph Factory["Factory Pattern"]
|
|
239
|
+
FACTORY[CredentialProviderFactory]
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
subgraph Providers["Credential Providers"]
|
|
243
|
+
AKV[AzureKeyVaultProvider]
|
|
244
|
+
LOCAL[LocalFileProvider]
|
|
245
|
+
ENV[EnvironmentProvider]
|
|
246
|
+
GH[GitHubSecretsProvider]
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
subgraph Storage["State Management"]
|
|
250
|
+
UTILS[utils.ts]
|
|
251
|
+
CACHE[(Storage State Cache)]
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
subgraph Browser["Playwright Browser"]
|
|
255
|
+
PW[Chromium Browser]
|
|
256
|
+
ENTRA[Microsoft Entra ID]
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
CMD --> CONFIG
|
|
260
|
+
CONFIG --> AUTH
|
|
261
|
+
AUTH --> FACTORY
|
|
262
|
+
FACTORY --> AKV
|
|
263
|
+
FACTORY --> LOCAL
|
|
264
|
+
FACTORY --> ENV
|
|
265
|
+
FACTORY --> GH
|
|
266
|
+
AUTH --> CERT
|
|
267
|
+
AUTH --> UTILS
|
|
268
|
+
UTILS --> CACHE
|
|
269
|
+
AUTH --> PW
|
|
270
|
+
PW --> ENTRA
|
|
271
|
+
ENTRA --> CACHE
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### Authentication Flow
|
|
275
|
+
|
|
276
|
+
```mermaid
|
|
277
|
+
sequenceDiagram
|
|
278
|
+
participant User
|
|
279
|
+
participant CLI
|
|
280
|
+
participant Config
|
|
281
|
+
participant Factory
|
|
282
|
+
participant Provider
|
|
283
|
+
participant Auth
|
|
284
|
+
participant Browser
|
|
285
|
+
participant Entra
|
|
286
|
+
participant Storage
|
|
287
|
+
|
|
288
|
+
User->>CLI: ms-auth login
|
|
289
|
+
CLI->>Config: Load configuration
|
|
290
|
+
Config->>Factory: Create provider
|
|
291
|
+
Factory->>Provider: Instantiate
|
|
292
|
+
|
|
293
|
+
Auth->>Storage: Check cached state
|
|
294
|
+
alt State valid
|
|
295
|
+
Storage-->>Auth: Return cached state
|
|
296
|
+
else State expired/missing
|
|
297
|
+
Auth->>Provider: Get credential
|
|
298
|
+
Provider-->>Auth: Return credential
|
|
299
|
+
Auth->>Browser: Launch browser
|
|
300
|
+
Browser->>Entra: Navigate to login
|
|
301
|
+
|
|
302
|
+
alt Certificate Auth
|
|
303
|
+
Auth->>Browser: Intercept cert request
|
|
304
|
+
Browser->>Entra: Present certificate
|
|
305
|
+
else Password Auth
|
|
306
|
+
Auth->>Browser: Fill password
|
|
307
|
+
Browser->>Entra: Submit password
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
Entra-->>Browser: Authentication success
|
|
311
|
+
Browser-->>Auth: Session cookies
|
|
312
|
+
Auth->>Storage: Save storage state
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
Storage-->>User: Authentication complete
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### Factory Pattern Implementation
|
|
319
|
+
|
|
320
|
+
```mermaid
|
|
321
|
+
classDiagram
|
|
322
|
+
class CredentialProvider {
|
|
323
|
+
<<abstract>>
|
|
324
|
+
+getProviderName() string
|
|
325
|
+
+validateConfig() void
|
|
326
|
+
+getCredential()* CredentialResult
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
class AzureKeyVaultProvider {
|
|
330
|
+
-keyVaultEndpoint: string
|
|
331
|
+
-secretName: string
|
|
332
|
+
+getCredential() CredentialResult
|
|
333
|
+
-createKeyVaultClient() SecretClient
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
class LocalFileProvider {
|
|
337
|
+
-filePath: string
|
|
338
|
+
-certificatePassword?: string
|
|
339
|
+
+getCredential() CredentialResult
|
|
340
|
+
-detectCredentialType() CredentialType
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
class EnvironmentProvider {
|
|
344
|
+
-variableName: string
|
|
345
|
+
+getCredential() CredentialResult
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
class GitHubSecretsProvider {
|
|
349
|
+
-repository: string
|
|
350
|
+
-secretName: string
|
|
351
|
+
+getCredential() CredentialResult
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
class CredentialProviderFactory {
|
|
355
|
+
+createProvider(type, config) CredentialProvider
|
|
356
|
+
+getSupportedProviders() string[]
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
class MsAuthConfig {
|
|
360
|
+
+email: string
|
|
361
|
+
+credentialType: CredentialType
|
|
362
|
+
+credentialProvider: ProviderType
|
|
363
|
+
+providerConfig: ProviderConfig
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
CredentialProvider <|-- AzureKeyVaultProvider
|
|
367
|
+
CredentialProvider <|-- LocalFileProvider
|
|
368
|
+
CredentialProvider <|-- EnvironmentProvider
|
|
369
|
+
CredentialProvider <|-- GitHubSecretsProvider
|
|
370
|
+
CredentialProviderFactory ..> CredentialProvider : creates
|
|
371
|
+
MsAuthConfig ..> CredentialProviderFactory : configures
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
### Data Flow Diagram
|
|
375
|
+
|
|
376
|
+
```mermaid
|
|
377
|
+
flowchart LR
|
|
378
|
+
subgraph Input["Configuration Sources"]
|
|
379
|
+
ENV_VARS[Environment Variables]
|
|
380
|
+
CLI_ARGS[CLI Arguments]
|
|
381
|
+
CODE[Programmatic Config]
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
subgraph Processing["Processing"]
|
|
385
|
+
CONFIG_LOADER[Config Loader]
|
|
386
|
+
VALIDATOR[Config Validator]
|
|
387
|
+
end
|
|
388
|
+
|
|
389
|
+
subgraph Credential["Credential Retrieval"]
|
|
390
|
+
KV[(Azure KeyVault)]
|
|
391
|
+
FS[(File System)]
|
|
392
|
+
ENV_SYS[(Environment)]
|
|
393
|
+
GH_API[(GitHub API)]
|
|
394
|
+
end
|
|
395
|
+
|
|
396
|
+
subgraph Auth["Authentication"]
|
|
397
|
+
BROWSER[Browser Session]
|
|
398
|
+
CERT_HANDLER[Certificate Handler]
|
|
399
|
+
PWD_HANDLER[Password Handler]
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
subgraph Output["Output"]
|
|
403
|
+
STATE_FILE[Storage State File]
|
|
404
|
+
LOGS[Debug Logs]
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
ENV_VARS --> CONFIG_LOADER
|
|
408
|
+
CLI_ARGS --> CONFIG_LOADER
|
|
409
|
+
CODE --> CONFIG_LOADER
|
|
410
|
+
CONFIG_LOADER --> VALIDATOR
|
|
411
|
+
|
|
412
|
+
VALIDATOR --> KV
|
|
413
|
+
VALIDATOR --> FS
|
|
414
|
+
VALIDATOR --> ENV_SYS
|
|
415
|
+
VALIDATOR --> GH_API
|
|
416
|
+
|
|
417
|
+
KV --> CERT_HANDLER
|
|
418
|
+
FS --> CERT_HANDLER
|
|
419
|
+
ENV_SYS --> PWD_HANDLER
|
|
420
|
+
GH_API --> CERT_HANDLER
|
|
421
|
+
|
|
422
|
+
CERT_HANDLER --> BROWSER
|
|
423
|
+
PWD_HANDLER --> BROWSER
|
|
424
|
+
|
|
425
|
+
BROWSER --> STATE_FILE
|
|
426
|
+
BROWSER --> LOGS
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
### Provider Hierarchy
|
|
430
|
+
|
|
431
|
+
```mermaid
|
|
432
|
+
graph TD
|
|
433
|
+
A[CredentialProvider<br/>Abstract Base Class] --> B[AzureKeyVaultProvider]
|
|
434
|
+
A --> C[LocalFileProvider]
|
|
435
|
+
A --> D[EnvironmentProvider]
|
|
436
|
+
A --> E[GitHubSecretsProvider]
|
|
437
|
+
|
|
438
|
+
B --> B1[Uses ChainedTokenCredential]
|
|
439
|
+
B --> B2[Supports AzureCLI, PowerShell,<br/>Developer, Interactive]
|
|
440
|
+
|
|
441
|
+
C --> C1[Auto-detects file type]
|
|
442
|
+
C --> C2[Supports .pfx, .p12, .txt, .pwd]
|
|
443
|
+
|
|
444
|
+
D --> D1[Direct env var access]
|
|
445
|
+
D --> D2[Auto-detects credential type]
|
|
446
|
+
|
|
447
|
+
E --> E1[Reads GitHub Actions secrets]
|
|
448
|
+
E --> E2[Converts to env vars]
|
|
449
|
+
|
|
450
|
+
style A fill:#e1f5ff
|
|
451
|
+
style B fill:#d4edda
|
|
452
|
+
style C fill:#d4edda
|
|
453
|
+
style D fill:#d4edda
|
|
454
|
+
style E fill:#d4edda
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
### Code Structure
|
|
458
|
+
|
|
459
|
+
```
|
|
460
|
+
playwright-ms-auth/
|
|
461
|
+
├── src/
|
|
462
|
+
│ ├── types.ts # Type definitions & interfaces
|
|
463
|
+
│ ├── config.ts # Environment variable loader
|
|
464
|
+
│ ├── authenticate.ts # Main authentication orchestration
|
|
465
|
+
│ ├── certAuth.ts # Certificate auth route handler
|
|
466
|
+
│ ├── utils.ts # Logging & storage utilities
|
|
467
|
+
│ ├── cli.ts # Command-line interface
|
|
468
|
+
│ ├── index.ts # Public API exports
|
|
469
|
+
│ └── providers/
|
|
470
|
+
│ ├── CredentialProvider.ts # Abstract base class
|
|
471
|
+
│ ├── AzureKeyVaultProvider.ts # KeyVault implementation
|
|
472
|
+
│ ├── LocalFileProvider.ts # File system implementation
|
|
473
|
+
│ ├── EnvironmentProvider.ts # Environment var implementation
|
|
474
|
+
│ ├── GitHubSecretsProvider.ts # GitHub secrets implementation
|
|
475
|
+
│ ├── CredentialProviderFactory.ts # Factory pattern
|
|
476
|
+
│ └── index.ts # Provider exports
|
|
477
|
+
├── bin/
|
|
478
|
+
│ └── ms-auth # CLI executable
|
|
479
|
+
├── package.json
|
|
480
|
+
├── tsconfig.json
|
|
481
|
+
└── README.md
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
## Abstract Factory Pattern
|
|
485
|
+
|
|
486
|
+
The package uses the **Abstract Factory Pattern** for extensibility:
|
|
487
|
+
|
|
488
|
+
```
|
|
489
|
+
CredentialProvider (abstract)
|
|
490
|
+
├── AzureKeyVaultProvider
|
|
491
|
+
├── LocalFileProvider
|
|
492
|
+
├── EnvironmentProvider
|
|
493
|
+
└── GitHubSecretsProvider
|
|
494
|
+
|
|
495
|
+
CredentialProviderFactory
|
|
496
|
+
└── createProvider(type, config)
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
### Adding Custom Providers
|
|
500
|
+
|
|
501
|
+
```typescript
|
|
502
|
+
import { CredentialProvider, type CredentialResult } from "playwright-ms-auth";
|
|
503
|
+
|
|
504
|
+
class MyCustomProvider extends CredentialProvider {
|
|
505
|
+
getProviderName(): string {
|
|
506
|
+
return "My Custom Provider";
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
validateConfig(): void {
|
|
510
|
+
// Validate your config
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
async getCredential(): Promise<CredentialResult> {
|
|
514
|
+
// Retrieve credential from your source
|
|
515
|
+
return {
|
|
516
|
+
type: "password",
|
|
517
|
+
value: "my-password",
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
## License
|
|
524
|
+
|
|
525
|
+
MIT
|
package/bin/ms-auth
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MsAuthConfig } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Perform Microsoft Entra authentication and save storage state
|
|
4
|
+
*/
|
|
5
|
+
export declare function authenticate(config: MsAuthConfig, targetUrl: string): Promise<void>;
|
|
6
|
+
/**
|
|
7
|
+
* Load existing storage state into a browser context
|
|
8
|
+
*/
|
|
9
|
+
export declare function loadStorageState(config: MsAuthConfig): Promise<string>;
|
|
10
|
+
//# sourceMappingURL=authenticate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authenticate.d.ts","sourceRoot":"","sources":["../src/authenticate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAoB,MAAM,SAAS,CAAC;AAc9D;;GAEG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,YAAY,EACpB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CAsDf;AAmOD;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAe5E"}
|