dh-auth-library 1.0.0 → 1.1.0
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/README.md +23 -12
- package/dist/auth/api/apiAuthentication.js +13 -0
- package/dist/auth/api/apiTokenHelper.d.ts +2 -2
- package/dist/auth/api/apiTokenHelper.js +68 -0
- package/dist/auth/api/index.d.ts +0 -1
- package/dist/auth/api/index.js +2 -0
- package/dist/auth/api/sessionHandlerResolvers.d.ts +3 -6
- package/dist/auth/api/sessionHandlerResolvers.js +5 -0
- package/dist/auth/getLoginHandler.js +25 -0
- package/dist/auth/index.js +6 -0
- package/dist/auth/loginhandlers/adLoginHandler.js +7 -0
- package/dist/auth/loginhandlers/digidGemachtigdeLoginHandler.js +7 -0
- package/dist/auth/loginhandlers/digidLoginHandler.js +7 -0
- package/dist/auth/loginhandlers/eHerkenningBewindvoerderLoginHandler.js +7 -0
- package/dist/auth/loginhandlers/eHerkenningLoginHandler.js +7 -0
- package/dist/auth/loginhandlers/index.js +6 -0
- package/dist/auth/loginhandlers/localhostLoginHandler.js +7 -0
- package/dist/auth/pages/adLoginPage.js +94 -0
- package/dist/auth/pages/digidLoginPage.d.ts +1 -1
- package/dist/auth/pages/digidLoginPage.js +73 -0
- package/dist/auth/pages/eHerkenningLoginPage.d.ts +6 -7
- package/dist/auth/pages/eHerkenningLoginPage.js +94 -0
- package/dist/auth/pages/index.js +4 -0
- package/dist/auth/pages/loginOverzichtPage.js +70 -0
- package/dist/auth/sessionHandler.d.ts +1 -1
- package/dist/auth/sessionHandler.js +88 -0
- package/dist/auth/utils/index.js +1 -0
- package/dist/auth/utils/sessionFileHelper.d.ts +9 -8
- package/dist/auth/utils/sessionFileHelper.js +33 -0
- package/dist/constants/accountTypes.d.ts +7 -29
- package/dist/constants/accountTypes.js +1 -0
- package/dist/constants/accounts.js +40 -0
- package/dist/constants/authTypes.d.ts +3 -0
- package/dist/constants/authTypes.js +1 -0
- package/dist/constants/index.d.ts +1 -4
- package/dist/constants/index.js +3 -0
- package/dist/constants/loginHandler.js +1 -0
- package/dist/constants/testAccounts.js +39 -0
- package/dist/constants/testProfiles.js +27 -0
- package/dist/index.js +2 -0
- package/package.json +7 -11
- package/dist/index.cjs.js +0 -860
- package/dist/index.es.js +0 -806
- package/dist/sha-B5xpXfPW.mjs +0 -911
- package/dist/sha-Eh0BcCJ_.js +0 -911
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { getUrl, Url } from 'nl-portal-playwright-libraries';
|
|
2
|
+
import { SessionFileHelper } from './utils/sessionFileHelper';
|
|
3
|
+
export const MAX_SESSION_TIME_IN_MINUTES = 10;
|
|
4
|
+
/**
|
|
5
|
+
* This class creates the correct SessionHandler
|
|
6
|
+
* It will also perform the process of setting op the session
|
|
7
|
+
*
|
|
8
|
+
* @param authType type of login
|
|
9
|
+
* @param account with login details
|
|
10
|
+
* @param loginHandler that will handle the login itself
|
|
11
|
+
*/
|
|
12
|
+
export function createSessionHandler(authType, account, loginHandler) {
|
|
13
|
+
return {
|
|
14
|
+
// Get the file where the session will be stored
|
|
15
|
+
getFile: (browser) => {
|
|
16
|
+
switch (authType) {
|
|
17
|
+
case 'digid':
|
|
18
|
+
return SessionFileHelper.getDigidFileName(browser, account);
|
|
19
|
+
case 'digid_gemachtigde':
|
|
20
|
+
return SessionFileHelper.getDigidGemachtigdeFileName(browser, account);
|
|
21
|
+
case 'eherkenning':
|
|
22
|
+
return SessionFileHelper.getEHerkenningFileName(browser, account);
|
|
23
|
+
case 'eherkenning_vestiging':
|
|
24
|
+
return SessionFileHelper.getEHerkenningVestigingFileName(browser, account);
|
|
25
|
+
case 'eherkenning_bewindvoerder':
|
|
26
|
+
return SessionFileHelper.getEHerkenningBewindvoerderFileName(browser, account);
|
|
27
|
+
case 'ad-session':
|
|
28
|
+
return SessionFileHelper.getADFileName(browser, account);
|
|
29
|
+
default:
|
|
30
|
+
throw new Error(`Unsupported auth type: ${authType}`);
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
/**
|
|
34
|
+
* Setup the new session
|
|
35
|
+
* If needed the AD Session if used (Needed outside the firewall)
|
|
36
|
+
*
|
|
37
|
+
* @param browser
|
|
38
|
+
* @param file
|
|
39
|
+
*/
|
|
40
|
+
setupSession: async (browser, file) => {
|
|
41
|
+
const useADSession = process.env.WITH_AD_SESSION === 'true';
|
|
42
|
+
const page = await browser.newPage({
|
|
43
|
+
ignoreHTTPSErrors: true,
|
|
44
|
+
storageState: useADSession && authType !== 'ad-session' ?
|
|
45
|
+
SessionFileHelper.getADFileName(browser, { username: `${process.env.AD_USER}`, password: `${process.env.AD_PASSWORD}` }) : undefined,
|
|
46
|
+
});
|
|
47
|
+
console.log(`New session will be created: ${file}`);
|
|
48
|
+
try {
|
|
49
|
+
await loginHandler.loginAndCreateSessionStorage(page, account, file);
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
await page.close();
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
/**
|
|
56
|
+
* Refresh the current session by opening a page and storing that session
|
|
57
|
+
* The UI should have refreshed the session meanwhile
|
|
58
|
+
*
|
|
59
|
+
* This is being called from the nl-portal-base-library
|
|
60
|
+
*
|
|
61
|
+
* @param browser
|
|
62
|
+
* @param file
|
|
63
|
+
*/
|
|
64
|
+
refreshSession: async (browser, file) => {
|
|
65
|
+
const page = await browser.newPage({
|
|
66
|
+
ignoreHTTPSErrors: true,
|
|
67
|
+
storageState: file,
|
|
68
|
+
});
|
|
69
|
+
console.log(`Refresh of session started for : ${file}`);
|
|
70
|
+
await page.goto(getUrl(Url.PortalBaseUrl));
|
|
71
|
+
await page.waitForLoadState('networkidle');
|
|
72
|
+
if (page.url().match(/authn/)) {
|
|
73
|
+
console.log(`New session will be created as the current one is no longer valid: ${file}`);
|
|
74
|
+
try {
|
|
75
|
+
await loginHandler.loginAndCreateSessionStorage(page, account, file);
|
|
76
|
+
}
|
|
77
|
+
catch (_error) {
|
|
78
|
+
console.error(_error);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
console.log(`Current session was still valid and will be refreshed now: ${file}`);
|
|
83
|
+
await page.context().storageState({ path: file });
|
|
84
|
+
}
|
|
85
|
+
await page.close();
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SessionFileHelper } from './sessionFileHelper';
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { Browser } from '@playwright/test';
|
|
2
|
+
import { Account } from 'nl-portal-playwright-libraries';
|
|
2
3
|
/**
|
|
3
4
|
* Easy way to create the filenames for the sessions
|
|
4
5
|
*/
|
|
5
6
|
export declare class SessionFileHelper {
|
|
6
|
-
static getLocalhostFileName(browser: Browser): string;
|
|
7
|
-
static getLocalhostFileNameBedrijf(browser: Browser): string;
|
|
8
|
-
static getDigidFileName(browser: Browser): string;
|
|
9
|
-
static getDigidGemachtigdeFileName(browser: Browser): string;
|
|
10
|
-
static getEHerkenningFileName(browser: Browser): string;
|
|
11
|
-
static getEHerkenningVestigingFileName(browser: Browser): string;
|
|
12
|
-
static getEHerkenningBewindvoerderFileName(browser: Browser): string;
|
|
13
|
-
static getADFileName(browser: Browser): string;
|
|
7
|
+
static getLocalhostFileName(browser: Browser, account: Account): string;
|
|
8
|
+
static getLocalhostFileNameBedrijf(browser: Browser, account: Account): string;
|
|
9
|
+
static getDigidFileName(browser: Browser, account: Account): string;
|
|
10
|
+
static getDigidGemachtigdeFileName(browser: Browser, account: Account): string;
|
|
11
|
+
static getEHerkenningFileName(browser: Browser, account: Account): string;
|
|
12
|
+
static getEHerkenningVestigingFileName(browser: Browser, account: Account): string;
|
|
13
|
+
static getEHerkenningBewindvoerderFileName(browser: Browser, account: Account): string;
|
|
14
|
+
static getADFileName(browser: Browser, account: Account): string;
|
|
14
15
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as path from 'node:path';
|
|
2
|
+
import * as process from 'node:process';
|
|
3
|
+
const sessionsDir = process.env.SESSIONS_DIR ?? path.resolve(process.cwd(), 'sessions');
|
|
4
|
+
const environment = process.env.ENV ?? 'test';
|
|
5
|
+
/**
|
|
6
|
+
* Easy way to create the filenames for the sessions
|
|
7
|
+
*/
|
|
8
|
+
export class SessionFileHelper {
|
|
9
|
+
static getLocalhostFileName(browser, account) {
|
|
10
|
+
return path.join(sessionsDir, `${browser.browserType().name()}-${environment}-${account.username}.json`);
|
|
11
|
+
}
|
|
12
|
+
static getLocalhostFileNameBedrijf(browser, account) {
|
|
13
|
+
return path.join(sessionsDir, `${browser.browserType().name()}-${environment}-${account.username}.json`);
|
|
14
|
+
}
|
|
15
|
+
static getDigidFileName(browser, account) {
|
|
16
|
+
return path.join(sessionsDir, `${browser.browserType().name()}-digid-${environment}-${account.username}.json`);
|
|
17
|
+
}
|
|
18
|
+
static getDigidGemachtigdeFileName(browser, account) {
|
|
19
|
+
return path.join(sessionsDir, `${browser.browserType().name()}-digid-gemachtigde-${environment}-${account.username}.json`);
|
|
20
|
+
}
|
|
21
|
+
static getEHerkenningFileName(browser, account) {
|
|
22
|
+
return path.join(sessionsDir, `${browser.browserType().name()}-eherkenning-${environment}-${account.username}.json`);
|
|
23
|
+
}
|
|
24
|
+
static getEHerkenningVestigingFileName(browser, account) {
|
|
25
|
+
return path.join(sessionsDir, `${browser.browserType().name()}-eherkenning-vestiging-${environment}-${account.username}.json`);
|
|
26
|
+
}
|
|
27
|
+
static getEHerkenningBewindvoerderFileName(browser, account) {
|
|
28
|
+
return path.join(sessionsDir, `${browser.browserType().name()}-eherkenning-bewindvoerder-${environment}-${account.username}.json`);
|
|
29
|
+
}
|
|
30
|
+
static getADFileName(browser, account) {
|
|
31
|
+
return path.join(sessionsDir, `${browser.browserType().name()}-ad-${environment}-${account.username}.json`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -1,34 +1,12 @@
|
|
|
1
1
|
import { AuthType } from './authTypes';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Interface for TestProfiles
|
|
4
|
+
* accountId should be used for identifying the account
|
|
5
|
+
* authType is used to determine the type of authentication (digid, eHerkenning etc)
|
|
6
|
+
* id can be used for extra information like bsn number or kvk number
|
|
7
|
+
*/
|
|
3
8
|
export interface TestProfile {
|
|
4
|
-
|
|
9
|
+
accountId: string;
|
|
5
10
|
authType: AuthType;
|
|
6
11
|
id: string;
|
|
7
12
|
}
|
|
8
|
-
export declare const profiles: {
|
|
9
|
-
burger: {
|
|
10
|
-
accountType: "burger";
|
|
11
|
-
authType: "digid";
|
|
12
|
-
id: string;
|
|
13
|
-
};
|
|
14
|
-
bedrijf: {
|
|
15
|
-
accountType: "bedrijf";
|
|
16
|
-
authType: "eherkenning";
|
|
17
|
-
id: string;
|
|
18
|
-
};
|
|
19
|
-
vestiging: {
|
|
20
|
-
accountType: "vestiging";
|
|
21
|
-
authType: "eherkenning_vestiging";
|
|
22
|
-
id: string;
|
|
23
|
-
};
|
|
24
|
-
gemachtigde: {
|
|
25
|
-
accountType: "digid-gemachtigde";
|
|
26
|
-
authType: "digid_gemachtigde";
|
|
27
|
-
id: string;
|
|
28
|
-
};
|
|
29
|
-
bewindvoerder: {
|
|
30
|
-
accountType: "bedrijf";
|
|
31
|
-
authType: "eherkenning_bewindvoerder";
|
|
32
|
-
id: string;
|
|
33
|
-
};
|
|
34
|
-
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* To use these accounts they should be available as environment variables
|
|
3
|
+
*/
|
|
4
|
+
export const localhostBurgerAccount = {
|
|
5
|
+
username: `${process.env.LOCAL_BURGER_USERNAME}`,
|
|
6
|
+
password: `${process.env.LOCAL_BURGER_PASSWORD}`,
|
|
7
|
+
};
|
|
8
|
+
export const localhostBedrijfAccount = {
|
|
9
|
+
username: `${process.env.LOCAL_BEDRIJF_USERNAME}`,
|
|
10
|
+
password: `${process.env.LOCAL_BEDRIJF_PASSWORD}`,
|
|
11
|
+
};
|
|
12
|
+
export const defaultDigidAccount = {
|
|
13
|
+
username: `${process.env.DIGID_USER}`,
|
|
14
|
+
password: `${process.env.DIGID_PASSWORD}`,
|
|
15
|
+
bsn: `${process.env.DIGID_BSN}`,
|
|
16
|
+
};
|
|
17
|
+
export const defaultDigidGemachtigdAccount = {
|
|
18
|
+
username: `${process.env.DIGID_GEMACHTIGDE_USER}`,
|
|
19
|
+
password: `${process.env.DIGID_GEMACHTIGDE_PASSWORD}`,
|
|
20
|
+
bsn: `${process.env.DIGID_GEMACHTIGDE_BSN}`,
|
|
21
|
+
};
|
|
22
|
+
export const defaultEHerkenningAccount = {
|
|
23
|
+
username: `${process.env.EHERKENNING_USER}`,
|
|
24
|
+
password: `${process.env.EHERKENNING_PASSWORD}`,
|
|
25
|
+
bsn: `${process.env.EHERKENNING_NUMMER}`,
|
|
26
|
+
};
|
|
27
|
+
export const defaultVestigingAccount = {
|
|
28
|
+
username: `${process.env.EHERKENNING_VESTIGING_NAME}`,
|
|
29
|
+
password: `${process.env.EHERKENNING_VESTIGING_PASSWORD}`,
|
|
30
|
+
bsn: `${process.env.EHERKENNING_VESTIGING_NUMMER}`,
|
|
31
|
+
};
|
|
32
|
+
export const defaultProfessioneelBewindvoerderAccount = {
|
|
33
|
+
username: `${process.env.EHERKENNING_BEWINDVOERDER_USER}`,
|
|
34
|
+
password: `${process.env.EHERKENNING_BEWINDVOERDER_PASSWORD}`,
|
|
35
|
+
bsn: `${process.env.EHERKENNING_BEWINDVOERDER_BSN}`,
|
|
36
|
+
};
|
|
37
|
+
export const defaultADAccount = {
|
|
38
|
+
username: `${process.env.AD_USER}`,
|
|
39
|
+
password: `${process.env.AD_PASSWORD}`,
|
|
40
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// These are all the accounts that we have for testing
|
|
2
|
+
export const TestAccounts = {
|
|
3
|
+
zgwdigiduser1: {
|
|
4
|
+
id: '999991954',
|
|
5
|
+
type: 'burger',
|
|
6
|
+
},
|
|
7
|
+
zgwdigiduser2: {
|
|
8
|
+
id: '999991115',
|
|
9
|
+
type: 'burger',
|
|
10
|
+
},
|
|
11
|
+
zgwdigiduser3: {
|
|
12
|
+
id: '999991966',
|
|
13
|
+
type: 'burger',
|
|
14
|
+
},
|
|
15
|
+
zgwdigiduser4: {
|
|
16
|
+
id: '999992922',
|
|
17
|
+
type: 'burger',
|
|
18
|
+
},
|
|
19
|
+
zgwdigiduser5: {
|
|
20
|
+
id: '999991322',
|
|
21
|
+
type: 'burger',
|
|
22
|
+
},
|
|
23
|
+
testautomatisering: {
|
|
24
|
+
id: '999994499',
|
|
25
|
+
type: 'burger',
|
|
26
|
+
},
|
|
27
|
+
localhostaccount: {
|
|
28
|
+
id: '999993847',
|
|
29
|
+
type: 'burger',
|
|
30
|
+
},
|
|
31
|
+
kvkAccount: {
|
|
32
|
+
id: '90002768',
|
|
33
|
+
type: 'bedrijf',
|
|
34
|
+
},
|
|
35
|
+
kvkVestiging: {
|
|
36
|
+
id: '990000262129',
|
|
37
|
+
type: 'vestiging',
|
|
38
|
+
},
|
|
39
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export const testProfiles = {
|
|
2
|
+
burger: {
|
|
3
|
+
accountType: 'burger',
|
|
4
|
+
authType: 'digid',
|
|
5
|
+
id: '999994499',
|
|
6
|
+
},
|
|
7
|
+
bedrijf: {
|
|
8
|
+
accountType: 'bedrijf',
|
|
9
|
+
authType: 'eherkenning',
|
|
10
|
+
id: '90002768',
|
|
11
|
+
},
|
|
12
|
+
vestiging: {
|
|
13
|
+
accountType: 'vestiging',
|
|
14
|
+
authType: 'eherkenning_vestiging',
|
|
15
|
+
id: '990000262129',
|
|
16
|
+
},
|
|
17
|
+
gemachtigde: {
|
|
18
|
+
accountType: 'digid-gemachtigde',
|
|
19
|
+
authType: 'digid_gemachtigde',
|
|
20
|
+
id: '',
|
|
21
|
+
},
|
|
22
|
+
bewindvoerder: {
|
|
23
|
+
accountType: 'bedrijf',
|
|
24
|
+
authType: 'eherkenning_bewindvoerder',
|
|
25
|
+
id: '999994499',
|
|
26
|
+
},
|
|
27
|
+
};
|
package/dist/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dh-auth-library",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/Gemeente-DenHaag/dh-auth-library.git"
|
|
@@ -8,22 +8,19 @@
|
|
|
8
8
|
"packageManager": "pnpm@11.5.2",
|
|
9
9
|
"description": "Authentication package for all types of login on DH applications",
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"main": "dist/index.
|
|
12
|
-
"module": "dist/index.es.js",
|
|
11
|
+
"main": "dist/index.js",
|
|
13
12
|
"types": "dist/index.d.ts",
|
|
14
13
|
"exports": {
|
|
15
14
|
".": {
|
|
16
15
|
"types": "./dist/index.d.ts",
|
|
17
|
-
"
|
|
18
|
-
"require": "./dist/index.cjs.js"
|
|
16
|
+
"default": "./dist/index.js"
|
|
19
17
|
}
|
|
20
18
|
},
|
|
21
19
|
"files": [
|
|
22
20
|
"dist"
|
|
23
21
|
],
|
|
24
22
|
"scripts": {
|
|
25
|
-
"
|
|
26
|
-
"build": "vite build && tsc -p tsconfig.build.json",
|
|
23
|
+
"build": "tsc -p tsconfig.build.json",
|
|
27
24
|
"prepublishOnly": "pnpm build",
|
|
28
25
|
"lint": "eslint ."
|
|
29
26
|
},
|
|
@@ -37,12 +34,11 @@
|
|
|
37
34
|
"@types/node": "^25.9.4",
|
|
38
35
|
"eslint": "^10.5.0",
|
|
39
36
|
"typescript": "^6.0.3",
|
|
40
|
-
"typescript-eslint": "8.60.1"
|
|
41
|
-
"vite": "^8.1.0",
|
|
42
|
-
"totp-generator": "^2.0.1"
|
|
37
|
+
"typescript-eslint": "8.60.1"
|
|
43
38
|
},
|
|
44
39
|
"dependencies": {
|
|
45
|
-
"nl-portal-playwright-libraries": "^1.1.3"
|
|
40
|
+
"nl-portal-playwright-libraries": "^1.1.3",
|
|
41
|
+
"totp-generator": "^2.0.1"
|
|
46
42
|
},
|
|
47
43
|
"keywords": [
|
|
48
44
|
"playwright",
|