@beinformed/ui 1.63.12 → 1.63.13
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 +7 -0
- package/esm/hooks/__tests__/useAuthentication.spec.js.flow +14 -1
- package/esm/hooks/useAuthentication.js +8 -5
- package/esm/hooks/useAuthentication.js.flow +14 -9
- package/esm/hooks/useAuthentication.js.map +1 -1
- package/esm/models/application/ApplicationModel.js +15 -2
- package/esm/models/application/ApplicationModel.js.flow +17 -0
- package/esm/models/application/ApplicationModel.js.map +1 -1
- package/lib/hooks/useAuthentication.js +7 -4
- package/lib/hooks/useAuthentication.js.map +1 -1
- package/lib/models/application/ApplicationModel.js +15 -2
- package/lib/models/application/ApplicationModel.js.map +1 -1
- package/package.json +2 -2
- package/src/hooks/__tests__/useAuthentication.spec.js +14 -1
- package/src/hooks/useAuthentication.js +14 -9
- package/src/models/application/ApplicationModel.js +17 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [1.63.13](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.63.12...v1.63.13) (2025-12-09)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **authentication:** cache `primaryAuthenticationType` for use in session ([158e7e8](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/158e7e8b810ad257653ae23489cfded365e6784c))
|
|
11
|
+
|
|
5
12
|
## [1.63.12](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.63.11...v1.63.12) (2025-12-08)
|
|
6
13
|
|
|
7
14
|
|
|
@@ -115,7 +115,12 @@ describe("authentication hooks", () => {
|
|
|
115
115
|
return res.status(200).body({ data: "ok" });
|
|
116
116
|
});
|
|
117
117
|
|
|
118
|
-
const store = mockStore({
|
|
118
|
+
const store = mockStore({
|
|
119
|
+
auth: {},
|
|
120
|
+
modularui: {},
|
|
121
|
+
router: { location: {} },
|
|
122
|
+
i18n: { locale: "en" },
|
|
123
|
+
});
|
|
119
124
|
|
|
120
125
|
/**
|
|
121
126
|
*/
|
|
@@ -135,6 +140,14 @@ describe("authentication hooks", () => {
|
|
|
135
140
|
|
|
136
141
|
expect(store.getActions()).toStrictEqual([
|
|
137
142
|
{ type: "START_PROGRESS" },
|
|
143
|
+
expect.objectContaining({
|
|
144
|
+
type: "MODULARUI/FETCH",
|
|
145
|
+
payload: expect.objectContaining({
|
|
146
|
+
key: "application(/)(en)",
|
|
147
|
+
}),
|
|
148
|
+
}),
|
|
149
|
+
{ type: "START_PROGRESS" },
|
|
150
|
+
{ type: "FINISH_PROGRESS" },
|
|
138
151
|
{ type: "MODULARUI/RESET" },
|
|
139
152
|
{ type: "START_PROGRESS" },
|
|
140
153
|
expect.objectContaining({
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { useSelector, useDispatch } from "react-redux";
|
|
2
|
-
import { getApplication } from "../redux/_modularui/ModularUISelectors";
|
|
3
2
|
import { login, logout, resetAuthErrors } from "../redux/actions";
|
|
4
3
|
import Cache from "../utils/browser/Cache";
|
|
5
|
-
import {
|
|
4
|
+
import { getBasePath, getBasePathServer, INTERNAL_LOGIN_TYPE } from "../constants";
|
|
6
5
|
import { IllegalStateException } from "../exceptions";
|
|
7
6
|
import { Authenticate } from "../modularui";
|
|
8
7
|
import { useApplication } from "./useModularUIModel";
|
|
@@ -14,9 +13,11 @@ export const useLogin = () => {
|
|
|
14
13
|
const application = useApplication();
|
|
15
14
|
const auth = useSelector(state => state.auth);
|
|
16
15
|
const isAuthenticated = application?.isLoggedIn ?? false;
|
|
16
|
+
const primaryAuthenticationType = Cache.getItem("primaryAuthenticationType");
|
|
17
17
|
return {
|
|
18
18
|
isAuthenticated,
|
|
19
|
-
|
|
19
|
+
primaryAuthenticationType: primaryAuthenticationType ?? application?.authenticationTypes[0],
|
|
20
|
+
authenticationTypes: application?.authenticationTypes ?? [],
|
|
20
21
|
errorMessage: auth.error,
|
|
21
22
|
resetErrors: () => dispatch(resetAuthErrors()),
|
|
22
23
|
login: (username, password) => dispatch(login(username, password)),
|
|
@@ -37,13 +38,15 @@ export const useLogin = () => {
|
|
|
37
38
|
*/
|
|
38
39
|
export const useLogout = () => {
|
|
39
40
|
const dispatch = useDispatch();
|
|
40
|
-
const application =
|
|
41
|
+
const application = useApplication();
|
|
41
42
|
const BASE_PATH = getBasePath();
|
|
42
43
|
const authenticate = new Authenticate();
|
|
44
|
+
const primaryAuthenticationType = Cache.getItem("primaryAuthenticationType");
|
|
43
45
|
const isAuthenticated = application?.isLoggedIn ?? false;
|
|
44
46
|
return {
|
|
45
47
|
isAuthenticated,
|
|
46
|
-
|
|
48
|
+
primaryAuthenticationType: primaryAuthenticationType ?? application?.authenticationTypes[0],
|
|
49
|
+
authenticationTypes: application?.authenticationTypes ?? [],
|
|
47
50
|
logout: () => {
|
|
48
51
|
const type = authenticate.authenticationType;
|
|
49
52
|
if (type === INTERNAL_LOGIN_TYPE.PAC4J_INDIRECT) {
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import { useSelector, useDispatch } from "react-redux";
|
|
3
3
|
|
|
4
|
-
import { getApplication } from "../redux/_modularui/ModularUISelectors";
|
|
5
4
|
import { login, logout, resetAuthErrors } from "../redux/actions";
|
|
6
5
|
|
|
7
6
|
import Cache from "../utils/browser/Cache";
|
|
8
7
|
import {
|
|
9
|
-
DEFAULT_AUTHENTICATION_TYPE,
|
|
10
8
|
getBasePath,
|
|
11
9
|
getBasePathServer,
|
|
12
10
|
INTERNAL_LOGIN_TYPE,
|
|
@@ -20,6 +18,7 @@ import type { AuthenticationType } from "../models/types";
|
|
|
20
18
|
|
|
21
19
|
type LoginHook = {
|
|
22
20
|
isAuthenticated: boolean,
|
|
21
|
+
primaryAuthenticationType: AuthenticationType,
|
|
23
22
|
authenticationTypes: Array<AuthenticationType>,
|
|
24
23
|
errorMessage: ?string,
|
|
25
24
|
resetErrors: () => ResetAuthErrorsAction,
|
|
@@ -28,6 +27,7 @@ type LoginHook = {
|
|
|
28
27
|
};
|
|
29
28
|
type LogoutHook = {
|
|
30
29
|
isAuthenticated: boolean,
|
|
30
|
+
primaryAuthenticationType: AuthenticationType,
|
|
31
31
|
authenticationTypes: Array<AuthenticationType>,
|
|
32
32
|
logout: () => void,
|
|
33
33
|
logoutUrl: string,
|
|
@@ -45,11 +45,13 @@ export const useLogin = (): LoginHook => {
|
|
|
45
45
|
|
|
46
46
|
const isAuthenticated = application?.isLoggedIn ?? false;
|
|
47
47
|
|
|
48
|
+
const primaryAuthenticationType = Cache.getItem("primaryAuthenticationType");
|
|
49
|
+
|
|
48
50
|
return {
|
|
49
51
|
isAuthenticated,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
],
|
|
52
|
+
primaryAuthenticationType:
|
|
53
|
+
primaryAuthenticationType ?? application?.authenticationTypes[0],
|
|
54
|
+
authenticationTypes: application?.authenticationTypes ?? [],
|
|
53
55
|
errorMessage: auth.error,
|
|
54
56
|
resetErrors: () => dispatch(resetAuthErrors()),
|
|
55
57
|
login: (username: string, password: string) =>
|
|
@@ -78,18 +80,21 @@ export const useLogin = (): LoginHook => {
|
|
|
78
80
|
*/
|
|
79
81
|
export const useLogout = (): LogoutHook => {
|
|
80
82
|
const dispatch = useDispatch();
|
|
81
|
-
|
|
83
|
+
|
|
84
|
+
const application = useApplication();
|
|
82
85
|
|
|
83
86
|
const BASE_PATH = getBasePath();
|
|
84
87
|
|
|
85
88
|
const authenticate = new Authenticate();
|
|
86
89
|
|
|
90
|
+
const primaryAuthenticationType = Cache.getItem("primaryAuthenticationType");
|
|
91
|
+
|
|
87
92
|
const isAuthenticated = application?.isLoggedIn ?? false;
|
|
88
93
|
return {
|
|
89
94
|
isAuthenticated,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
],
|
|
95
|
+
primaryAuthenticationType:
|
|
96
|
+
primaryAuthenticationType ?? application?.authenticationTypes[0],
|
|
97
|
+
authenticationTypes: application?.authenticationTypes ?? [],
|
|
93
98
|
logout: () => {
|
|
94
99
|
const type = authenticate.authenticationType;
|
|
95
100
|
if (type === INTERNAL_LOGIN_TYPE.PAC4J_INDIRECT) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuthentication.js","names":["useSelector","useDispatch","
|
|
1
|
+
{"version":3,"file":"useAuthentication.js","names":["useSelector","useDispatch","login","logout","resetAuthErrors","Cache","getBasePath","getBasePathServer","INTERNAL_LOGIN_TYPE","IllegalStateException","Authenticate","useApplication","useLogin","setItem","dispatch","application","auth","state","isAuthenticated","isLoggedIn","primaryAuthenticationType","getItem","authenticationTypes","errorMessage","error","resetErrors","username","password","redirectLogin","authenticationType","authentication","redirectUri","window","location","assign","useLogout","BASE_PATH","authenticate","type","PAC4J_INDIRECT","redirectToLogout","origin","url","getLogoutUrl","logoutUrl"],"sources":["../../src/hooks/useAuthentication.js"],"sourcesContent":["// @flow\nimport { useSelector, useDispatch } from \"react-redux\";\n\nimport { login, logout, resetAuthErrors } from \"../redux/actions\";\n\nimport Cache from \"../utils/browser/Cache\";\nimport {\n getBasePath,\n getBasePathServer,\n INTERNAL_LOGIN_TYPE,\n} from \"../constants\";\nimport { IllegalStateException } from \"../exceptions\";\nimport { Authenticate } from \"../modularui\";\nimport { useApplication } from \"./useModularUIModel\";\n\nimport type { ResetAuthErrorsAction } from \"../redux/types\";\nimport type { AuthenticationType } from \"../models/types\";\n\ntype LoginHook = {\n isAuthenticated: boolean,\n primaryAuthenticationType: AuthenticationType,\n authenticationTypes: Array<AuthenticationType>,\n errorMessage: ?string,\n resetErrors: () => ResetAuthErrorsAction,\n login: (username: string, password: string) => void,\n redirectLogin: (authenticationType: AuthenticationType) => void,\n};\ntype LogoutHook = {\n isAuthenticated: boolean,\n primaryAuthenticationType: AuthenticationType,\n authenticationTypes: Array<AuthenticationType>,\n logout: () => void,\n logoutUrl: string,\n};\n\n/**\n */\nexport const useLogin = (): LoginHook => {\n Cache.setItem(\"isRedirectLogin\", false);\n\n const dispatch = useDispatch();\n\n const application = useApplication();\n const auth = useSelector((state) => state.auth);\n\n const isAuthenticated = application?.isLoggedIn ?? false;\n\n const primaryAuthenticationType = Cache.getItem(\"primaryAuthenticationType\");\n\n return {\n isAuthenticated,\n primaryAuthenticationType:\n primaryAuthenticationType ?? application?.authenticationTypes[0],\n authenticationTypes: application?.authenticationTypes ?? [],\n errorMessage: auth.error,\n resetErrors: () => dispatch(resetAuthErrors()),\n login: (username: string, password: string) =>\n dispatch(login(username, password)),\n redirectLogin: (authenticationType: AuthenticationType) => {\n if (Cache.getItem(\"isRedirectLogin\")) {\n // prevent endless loop in redirects when authentication type can't be redirected\n throw new IllegalStateException(\n `Could not redirect to '${\n authenticationType.authentication\n }' using url: '${authenticationType.redirectUri ?? \"\"}'`,\n );\n }\n\n if (!isAuthenticated) {\n Cache.setItem(\"isRedirectLogin\", true);\n window.location.assign(\n `${getBasePathServer()}${authenticationType.redirectUri ?? \"\"}`,\n );\n }\n },\n };\n};\n\n/**\n */\nexport const useLogout = (): LogoutHook => {\n const dispatch = useDispatch();\n\n const application = useApplication();\n\n const BASE_PATH = getBasePath();\n\n const authenticate = new Authenticate();\n\n const primaryAuthenticationType = Cache.getItem(\"primaryAuthenticationType\");\n\n const isAuthenticated = application?.isLoggedIn ?? false;\n return {\n isAuthenticated,\n primaryAuthenticationType:\n primaryAuthenticationType ?? application?.authenticationTypes[0],\n authenticationTypes: application?.authenticationTypes ?? [],\n logout: () => {\n const type = authenticate.authenticationType;\n if (type === INTERNAL_LOGIN_TYPE.PAC4J_INDIRECT) {\n authenticate.redirectToLogout();\n } else if (Cache.getItem(\"isRedirectLogin\")) {\n const origin = window.location.origin;\n const url = `${authenticate.getLogoutUrl()}?url=${origin}${BASE_PATH}`;\n Cache.setItem(\"isRedirectLogin\", false);\n window.location.assign(url);\n } else {\n return dispatch(logout());\n }\n },\n logoutUrl: authenticate.getLogoutUrl(),\n };\n};\n"],"mappings":"AACA,SAASA,WAAW,EAAEC,WAAW,QAAQ,aAAa;AAEtD,SAASC,KAAK,EAAEC,MAAM,EAAEC,eAAe,QAAQ,kBAAkB;AAEjE,OAAOC,KAAK,MAAM,wBAAwB;AAC1C,SACEC,WAAW,EACXC,iBAAiB,EACjBC,mBAAmB,QACd,cAAc;AACrB,SAASC,qBAAqB,QAAQ,eAAe;AACrD,SAASC,YAAY,QAAQ,cAAc;AAC3C,SAASC,cAAc,QAAQ,qBAAqB;AAsBpD;AACA;AACA,OAAO,MAAMC,QAAQ,GAAGA,CAAA,KAAiB;EACvCP,KAAK,CAACQ,OAAO,CAAC,iBAAiB,EAAE,KAAK,CAAC;EAEvC,MAAMC,QAAQ,GAAGb,WAAW,CAAC,CAAC;EAE9B,MAAMc,WAAW,GAAGJ,cAAc,CAAC,CAAC;EACpC,MAAMK,IAAI,GAAGhB,WAAW,CAAEiB,KAAK,IAAKA,KAAK,CAACD,IAAI,CAAC;EAE/C,MAAME,eAAe,GAAGH,WAAW,EAAEI,UAAU,IAAI,KAAK;EAExD,MAAMC,yBAAyB,GAAGf,KAAK,CAACgB,OAAO,CAAC,2BAA2B,CAAC;EAE5E,OAAO;IACLH,eAAe;IACfE,yBAAyB,EACvBA,yBAAyB,IAAIL,WAAW,EAAEO,mBAAmB,CAAC,CAAC,CAAC;IAClEA,mBAAmB,EAAEP,WAAW,EAAEO,mBAAmB,IAAI,EAAE;IAC3DC,YAAY,EAAEP,IAAI,CAACQ,KAAK;IACxBC,WAAW,EAAEA,CAAA,KAAMX,QAAQ,CAACV,eAAe,CAAC,CAAC,CAAC;IAC9CF,KAAK,EAAEA,CAACwB,QAAgB,EAAEC,QAAgB,KACxCb,QAAQ,CAACZ,KAAK,CAACwB,QAAQ,EAAEC,QAAQ,CAAC,CAA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OAAO,CAAC,iBAAiB,CAAC,EAAE;QAC3C,MAAMoB,MAAM,GAAGT,MAAM,CAACC,QAAQ,CAACQ,MAAM;QACrC,MAAMC,GAAG,GAAG,GAAGL,YAAY,CAACM,YAAY,CAAC,CAAC,QAAQF,MAAM,GAAGL,SAAS,EAAE;QACtE/B,KAAK,CAACQ,OAAO,CAAC,iBAAiB,EAAE,KAAK,CAAC;QACvCmB,MAAM,CAACC,QAAQ,CAACC,MAAM,CAACQ,GAAG,CAAC;MAC7B,CAAC,MAAM;QACL,OAAO5B,QAAQ,CAACX,MAAM,CAAC,CAAC,CAAC;MAC3B;IACF,CAAC;IACDyC,SAAS,EAAEP,YAAY,CAACM,YAAY,CAAC;EACvC,CAAC;AACH,CAAC","ignoreList":[]}
|
|
@@ -6,14 +6,19 @@ import LinkModel from "../links/LinkModel";
|
|
|
6
6
|
import UserServicesModel from "../user/UserServicesModel";
|
|
7
7
|
import { NotAllowedUriException } from "../../exceptions";
|
|
8
8
|
import { DEFAULT_AUTHENTICATION_TYPE } from "../../constants";
|
|
9
|
+
import Cache from "../../utils/browser/Cache";
|
|
9
10
|
/**
|
|
10
11
|
* The Application model
|
|
11
12
|
*/
|
|
12
13
|
export default class ApplicationModel extends ResourceModel {
|
|
13
|
-
constructor(
|
|
14
|
-
super(
|
|
14
|
+
constructor(modularuiResponse) {
|
|
15
|
+
super(modularuiResponse);
|
|
16
|
+
|
|
17
|
+
// store authentication type in session cache, to make it available when application is no longer available (when not permitted for example)
|
|
15
18
|
_defineProperty(this, "_userServices", void 0);
|
|
19
|
+
Cache.setItem("primaryAuthenticationType", this.primaryAuthenticationType);
|
|
16
20
|
}
|
|
21
|
+
|
|
17
22
|
/**
|
|
18
23
|
* Retrieve type of model
|
|
19
24
|
*/
|
|
@@ -72,6 +77,14 @@ export default class ApplicationModel extends ResourceModel {
|
|
|
72
77
|
return [DEFAULT_AUTHENTICATION_TYPE];
|
|
73
78
|
}
|
|
74
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Returns the primary authentication type
|
|
82
|
+
* @returns {AuthenticationType}
|
|
83
|
+
*/
|
|
84
|
+
get primaryAuthenticationType() {
|
|
85
|
+
return this.authenticationTypes[0];
|
|
86
|
+
}
|
|
87
|
+
|
|
75
88
|
/**
|
|
76
89
|
* Getting the tab links
|
|
77
90
|
*/
|
|
@@ -7,6 +7,8 @@ import { NotAllowedUriException } from "../../exceptions";
|
|
|
7
7
|
|
|
8
8
|
import { DEFAULT_AUTHENTICATION_TYPE } from "../../constants";
|
|
9
9
|
|
|
10
|
+
import Cache from "../../utils/browser/Cache";
|
|
11
|
+
|
|
10
12
|
import type { ModularUIModel, AuthenticationType } from "../types";
|
|
11
13
|
import type { ModularUIResponse } from "../../modularui";
|
|
12
14
|
import type LinkCollection from "../links/LinkCollection";
|
|
@@ -18,6 +20,13 @@ import type Href from "../href/Href";
|
|
|
18
20
|
export default class ApplicationModel extends ResourceModel {
|
|
19
21
|
_userServices: ?UserServicesModel;
|
|
20
22
|
|
|
23
|
+
constructor(modularuiResponse: ModularUIResponse) {
|
|
24
|
+
super(modularuiResponse);
|
|
25
|
+
|
|
26
|
+
// store authentication type in session cache, to make it available when application is no longer available (when not permitted for example)
|
|
27
|
+
Cache.setItem("primaryAuthenticationType", this.primaryAuthenticationType);
|
|
28
|
+
}
|
|
29
|
+
|
|
21
30
|
/**
|
|
22
31
|
* Retrieve type of model
|
|
23
32
|
*/
|
|
@@ -91,6 +100,14 @@ export default class ApplicationModel extends ResourceModel {
|
|
|
91
100
|
return [DEFAULT_AUTHENTICATION_TYPE];
|
|
92
101
|
}
|
|
93
102
|
|
|
103
|
+
/**
|
|
104
|
+
* Returns the primary authentication type
|
|
105
|
+
* @returns {AuthenticationType}
|
|
106
|
+
*/
|
|
107
|
+
get primaryAuthenticationType(): AuthenticationType {
|
|
108
|
+
return this.authenticationTypes[0];
|
|
109
|
+
}
|
|
110
|
+
|
|
94
111
|
/**
|
|
95
112
|
* Getting the tab links
|
|
96
113
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApplicationModel.js","names":["ResourceModel","LinkModel","UserServicesModel","NotAllowedUriException","DEFAULT_AUTHENTICATION_TYPE","ApplicationModel","constructor","
|
|
1
|
+
{"version":3,"file":"ApplicationModel.js","names":["ResourceModel","LinkModel","UserServicesModel","NotAllowedUriException","DEFAULT_AUTHENTICATION_TYPE","Cache","ApplicationModel","constructor","modularuiResponse","_defineProperty","setItem","primaryAuthenticationType","type","modelName","isApplicableModel","data","contributions","resourcetype","getInitialChildModelLinks","userService","links","getLinkByKey","href","path","setChildModels","models","userServiceModel","_findInstanceProperty","call","model","userServices","label","getContribution","authenticationTypes","_context","Function","bind","_sortInstanceProperty","a","b","isPrimary","tabs","getLinksByGroup","modelcatalog","create","modelOptions","_userServices","isLoggedIn","userHref","userLink","userMustChangePassword","mustChangePassword"],"sources":["../../../src/models/application/ApplicationModel.js"],"sourcesContent":["// @flow\nimport ResourceModel from \"../base/ResourceModel\";\nimport LinkModel from \"../links/LinkModel\";\nimport UserServicesModel from \"../user/UserServicesModel\";\n\nimport { NotAllowedUriException } from \"../../exceptions\";\n\nimport { DEFAULT_AUTHENTICATION_TYPE } from \"../../constants\";\n\nimport Cache from \"../../utils/browser/Cache\";\n\nimport type { ModularUIModel, AuthenticationType } from \"../types\";\nimport type { ModularUIResponse } from \"../../modularui\";\nimport type LinkCollection from \"../links/LinkCollection\";\nimport type Href from \"../href/Href\";\n\n/**\n * The Application model\n */\nexport default class ApplicationModel extends ResourceModel {\n _userServices: ?UserServicesModel;\n\n constructor(modularuiResponse: ModularUIResponse) {\n super(modularuiResponse);\n\n // store authentication type in session cache, to make it available when application is no longer available (when not permitted for example)\n Cache.setItem(\"primaryAuthenticationType\", this.primaryAuthenticationType);\n }\n\n /**\n * Retrieve type of model\n */\n get type(): string {\n return \"Application\";\n }\n\n /**\n */\n static get modelName(): string {\n return \"ApplicationModel\";\n }\n\n /**\n */\n static isApplicableModel(data: ModularUIResponse): boolean {\n return (\n data.contributions.resourcetype &&\n data.contributions.resourcetype === \"Application\"\n );\n }\n\n /**\n */\n getInitialChildModelLinks(): Array<LinkModel> {\n const userService = this.links.getLinkByKey(\"UserServices\");\n if (userService && userService.href.path === \"/login\") {\n throw new NotAllowedUriException(\n \"The user service (Login panel) should not have the uri '/login', use a different URI because this uri matches the login service.\",\n );\n }\n\n return userService ? [userService] : [];\n }\n\n /**\n */\n setChildModels(models: Array<ModularUIModel>) {\n const userServiceModel = models.find(\n (model) => model.type === \"UserServices\",\n );\n\n if (userServiceModel) {\n this.userServices = userServiceModel;\n }\n }\n\n /**\n * Getting the label of the application\n */\n get label(): string {\n return this.getContribution(\"label\", \"\");\n }\n\n /**\n * Getting the authentication types of the application\n */\n get authenticationTypes(): Array<AuthenticationType> {\n const authenticationTypes = this.getContribution(\"security\", [\n DEFAULT_AUTHENTICATION_TYPE,\n ]);\n\n if (authenticationTypes) {\n //put primary first\n return authenticationTypes?.sort(\n (a: AuthenticationType, b: AuthenticationType) =>\n a.isPrimary === b.isPrimary ? 0 : a.isPrimary ? -1 : 1,\n );\n }\n\n return [DEFAULT_AUTHENTICATION_TYPE];\n }\n\n /**\n * Returns the primary authentication type\n * @returns {AuthenticationType}\n */\n get primaryAuthenticationType(): AuthenticationType {\n return this.authenticationTypes[0];\n }\n\n /**\n * Getting the tab links\n */\n get tabs(): LinkCollection {\n return this.links.getLinksByGroup(\"tab\");\n }\n\n /**\n * Get modelcatalog link\n */\n get modelcatalog(): LinkModel {\n return LinkModel.create(\n \"modelcatalog\",\n \"/modelcatalog\",\n \"Model catalog\",\n this.modelOptions,\n );\n }\n\n /**\n * Set the userservices for this application\n */\n set userServices(model: ?ModularUIModel) {\n this._userServices = model instanceof UserServicesModel ? model : null;\n }\n\n /**\n * returns the userservices configured for this application\n */\n get userServices(): ?UserServicesModel {\n return this._userServices ? this._userServices : null;\n }\n\n /**\n * Indicates if the user is logged in\n */\n get isLoggedIn(): boolean {\n return this.userServices?.isLoggedIn ?? false;\n }\n\n /**\n * Retrieve link to the user information,\n * only available when the user services are available\n */\n get userHref(): Href | null {\n if (this.userServices?.userLink) {\n return this.userServices.userLink.href;\n }\n\n return null;\n }\n\n /**\n */\n get userMustChangePassword(): boolean {\n return this.userServices?.mustChangePassword ?? false;\n }\n}\n"],"mappings":";;;AACA,OAAOA,aAAa,MAAM,uBAAuB;AACjD,OAAOC,SAAS,MAAM,oBAAoB;AAC1C,OAAOC,iBAAiB,MAAM,2BAA2B;AAEzD,SAASC,sBAAsB,QAAQ,kBAAkB;AAEzD,SAASC,2BAA2B,QAAQ,iBAAiB;AAE7D,OAAOC,KAAK,MAAM,2BAA2B;AAO7C;AACA;AACA;AACA,eAAe,MAAMC,gBAAgB,SAASN,aAAa,CAAC;EAG1DO,WAAWA,CAACC,iBAAoC,EAAE;IAChD,KAAK,CAACA,iBAAiB,CAAC;;IAExB;IAAAC,eAAA;IACAJ,KAAK,CAACK,OAAO,CAAC,2BAA2B,EAAE,IAAI,CAACC,yBAAyB,CAAC;EAC5E;;EAEA;AACF;AACA;EACE,IAAIC,IAAIA,CAAA,EAAW;IACjB,OAAO,aAAa;EACtB;;EAEA;AACF;EACE,WAAWC,SAASA,CAAA,EAAW;IAC7B,OAAO,kBAAkB;EAC3B;;EAEA;AACF;EACE,OAAOC,iBAAiBA,CAACC,IAAuB,EAAW;IACzD,OACEA,IAAI,CAACC,aAAa,CAACC,YAAY,IAC/BF,IAAI,CAACC,aAAa,CAACC,YAAY,KAAK,aAAa;EAErD;;EAEA;AACF;EACEC,yBAAyBA,CAAA,EAAqB;IAC5C,MAAMC,WAAW,GAAG,IAAI,CAACC,KAAK,CAACC,YAAY,CAAC,cAAc,CAAC;IAC3D,IAAIF,WAAW,IAAIA,WAAW,CAACG,IAAI,CAACC,IAAI,KAAK,QAAQ,EAAE;MACrD,MAAM,IAAIpB,sBAAsB,CAC9B,kIACF,CAAC;IACH;IAEA,OAAOgB,WAAW,GAAG,CAACA,WAAW,CAAC,GAA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M,CACrB,cAAc,EACd,eAAe,EACf,eAAe,EACf,IAAI,CAACC,YACP,CAAC;EACH;;EAEA;AACF;AACA;EACE,IAAIf,YAAYA,CAACD,KAAsB,EAAE;IACvC,IAAI,CAACiB,aAAa,GAAGjB,KAAK,YAAY3B,iBAAiB,GAAG2B,KAAK,GAAG,IAAI;EACxE;;EAEA;AACF;AACA;EACE,IAAIC,YAAYA,CAAA,EAAuB;IACrC,OAAO,IAAI,CAACgB,aAAa,GAAG,IAAI,CAACA,aAAa,GAAG,IAAI;EACvD;;EAEA;AACF;AACA;EACE,IAAIC,UAAUA,CAAA,EAAY;IACxB,OAAO,IAAI,CAACjB,YAAY,EAAEiB,UAAU,IAAI,KAAK;EAC/C;;EAEA;AACF;AACA;AACA;EACE,IAAIC,QAAQA,CAAA,EAAgB;IAC1B,IAAI,IAAI,CAAClB,YAAY,EAAEmB,QAAQ,EAAE;MAC/B,OAAO,IAAI,CAACnB,YAAY,CAACmB,QAAQ,CAAC3B,IAAI;IACxC;IAEA,OAAO,IAAI;EACb;;EAEA;AACF;EACE,IAAI4B,sBAAsBA,CAAA,EAAY;IACpC,OAAO,IAAI,CAACpB,YAAY,EAAEqB,kBAAkB,IAAI,KAAK;EACvD;AACF","ignoreList":[]}
|
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.useLogout = exports.useLogin = void 0;
|
|
8
8
|
var _reactRedux = require("react-redux");
|
|
9
|
-
var _ModularUISelectors = require("../redux/_modularui/ModularUISelectors");
|
|
10
9
|
var _actions = require("../redux/actions");
|
|
11
10
|
var _Cache = _interopRequireDefault(require("../utils/browser/Cache"));
|
|
12
11
|
var _constants = require("../constants");
|
|
@@ -21,9 +20,11 @@ const useLogin = () => {
|
|
|
21
20
|
const application = (0, _useModularUIModel.useApplication)();
|
|
22
21
|
const auth = (0, _reactRedux.useSelector)(state => state.auth);
|
|
23
22
|
const isAuthenticated = application?.isLoggedIn ?? false;
|
|
23
|
+
const primaryAuthenticationType = _Cache.default.getItem("primaryAuthenticationType");
|
|
24
24
|
return {
|
|
25
25
|
isAuthenticated,
|
|
26
|
-
|
|
26
|
+
primaryAuthenticationType: primaryAuthenticationType ?? application?.authenticationTypes[0],
|
|
27
|
+
authenticationTypes: application?.authenticationTypes ?? [],
|
|
27
28
|
errorMessage: auth.error,
|
|
28
29
|
resetErrors: () => dispatch((0, _actions.resetAuthErrors)()),
|
|
29
30
|
login: (username, password) => dispatch((0, _actions.login)(username, password)),
|
|
@@ -45,13 +46,15 @@ const useLogin = () => {
|
|
|
45
46
|
exports.useLogin = useLogin;
|
|
46
47
|
const useLogout = () => {
|
|
47
48
|
const dispatch = (0, _reactRedux.useDispatch)();
|
|
48
|
-
const application = (0,
|
|
49
|
+
const application = (0, _useModularUIModel.useApplication)();
|
|
49
50
|
const BASE_PATH = (0, _constants.getBasePath)();
|
|
50
51
|
const authenticate = new _modularui.Authenticate();
|
|
52
|
+
const primaryAuthenticationType = _Cache.default.getItem("primaryAuthenticationType");
|
|
51
53
|
const isAuthenticated = application?.isLoggedIn ?? false;
|
|
52
54
|
return {
|
|
53
55
|
isAuthenticated,
|
|
54
|
-
|
|
56
|
+
primaryAuthenticationType: primaryAuthenticationType ?? application?.authenticationTypes[0],
|
|
57
|
+
authenticationTypes: application?.authenticationTypes ?? [],
|
|
55
58
|
logout: () => {
|
|
56
59
|
const type = authenticate.authenticationType;
|
|
57
60
|
if (type === _constants.INTERNAL_LOGIN_TYPE.PAC4J_INDIRECT) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuthentication.js","names":["_reactRedux","require","
|
|
1
|
+
{"version":3,"file":"useAuthentication.js","names":["_reactRedux","require","_actions","_Cache","_interopRequireDefault","_constants","_exceptions","_modularui","_useModularUIModel","useLogin","Cache","setItem","dispatch","useDispatch","application","useApplication","auth","useSelector","state","isAuthenticated","isLoggedIn","primaryAuthenticationType","getItem","authenticationTypes","errorMessage","error","resetErrors","resetAuthErrors","login","username","password","redirectLogin","authenticationType","IllegalStateException","authentication","redirectUri","window","location","assign","getBasePathServer","exports","useLogout","BASE_PATH","getBasePath","authenticate","Authenticate","logout","type","INTERNAL_LOGIN_TYPE","PAC4J_INDIRECT","redirectToLogout","origin","url","getLogoutUrl","logoutUrl"],"sources":["../../src/hooks/useAuthentication.js"],"sourcesContent":["// @flow\nimport { useSelector, useDispatch } from \"react-redux\";\n\nimport { login, logout, resetAuthErrors } from \"../redux/actions\";\n\nimport Cache from \"../utils/browser/Cache\";\nimport {\n getBasePath,\n getBasePathServer,\n INTERNAL_LOGIN_TYPE,\n} from \"../constants\";\nimport { IllegalStateException } from \"../exceptions\";\nimport { Authenticate } from \"../modularui\";\nimport { useApplication } from \"./useModularUIModel\";\n\nimport type { ResetAuthErrorsAction } from \"../redux/types\";\nimport type { AuthenticationType } from \"../models/types\";\n\ntype LoginHook = {\n isAuthenticated: boolean,\n primaryAuthenticationType: AuthenticationType,\n authenticationTypes: Array<AuthenticationType>,\n errorMessage: ?string,\n resetErrors: () => ResetAuthErrorsAction,\n login: (username: string, password: string) => void,\n redirectLogin: (authenticationType: AuthenticationType) => void,\n};\ntype LogoutHook = {\n isAuthenticated: boolean,\n primaryAuthenticationType: AuthenticationType,\n authenticationTypes: Array<AuthenticationType>,\n logout: () => void,\n logoutUrl: string,\n};\n\n/**\n */\nexport const useLogin = (): LoginHook => {\n Cache.setItem(\"isRedirectLogin\", false);\n\n const dispatch = useDispatch();\n\n const application = useApplication();\n const auth = useSelector((state) => state.auth);\n\n const isAuthenticated = application?.isLoggedIn ?? false;\n\n const primaryAuthenticationType = Cache.getItem(\"primaryAuthenticationType\");\n\n return {\n isAuthenticated,\n primaryAuthenticationType:\n primaryAuthenticationType ?? application?.authenticationTypes[0],\n authenticationTypes: application?.authenticationTypes ?? [],\n errorMessage: auth.error,\n resetErrors: () => dispatch(resetAuthErrors()),\n login: (username: string, password: string) =>\n dispatch(login(username, password)),\n redirectLogin: (authenticationType: AuthenticationType) => {\n if (Cache.getItem(\"isRedirectLogin\")) {\n // prevent endless loop in redirects when authentication type can't be redirected\n throw new IllegalStateException(\n `Could not redirect to '${\n authenticationType.authentication\n }' using url: '${authenticationType.redirectUri ?? \"\"}'`,\n );\n }\n\n if (!isAuthenticated) {\n Cache.setItem(\"isRedirectLogin\", true);\n window.location.assign(\n `${getBasePathServer()}${authenticationType.redirectUri ?? \"\"}`,\n );\n }\n },\n };\n};\n\n/**\n */\nexport const useLogout = (): LogoutHook => {\n const dispatch = useDispatch();\n\n const application = useApplication();\n\n const BASE_PATH = getBasePath();\n\n const authenticate = new Authenticate();\n\n const primaryAuthenticationType = Cache.getItem(\"primaryAuthenticationType\");\n\n const isAuthenticated = application?.isLoggedIn ?? false;\n return {\n isAuthenticated,\n primaryAuthenticationType:\n primaryAuthenticationType ?? application?.authenticationTypes[0],\n authenticationTypes: application?.authenticationTypes ?? [],\n logout: () => {\n const type = authenticate.authenticationType;\n if (type === INTERNAL_LOGIN_TYPE.PAC4J_INDIRECT) {\n authenticate.redirectToLogout();\n } else if (Cache.getItem(\"isRedirectLogin\")) {\n const origin = window.location.origin;\n const url = `${authenticate.getLogoutUrl()}?url=${origin}${BASE_PATH}`;\n Cache.setItem(\"isRedirectLogin\", false);\n window.location.assign(url);\n } else {\n return dispatch(logout());\n }\n },\n logoutUrl: authenticate.getLogoutUrl(),\n };\n};\n"],"mappings":";;;;;;;AACA,IAAAA,WAAA,GAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AAKA,IAAAK,WAAA,GAAAL,OAAA;AACA,IAAAM,UAAA,GAAAN,OAAA;AACA,IAAAO,kBAAA,GAAAP,OAAA;AAsBA;AACA;AACO,MAAMQ,QAAQ,GAAGA,CAAA,KAAiB;EACvCC,cAAK,CAACC,OAAO,CAAC,iBAAiB,EAAE,KAAK,CAAC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OAAA,CAAAC,SAAA,GAAAA,SAAA","ignoreList":[]}
|
|
@@ -13,14 +13,19 @@ var _LinkModel = _interopRequireDefault(require("../links/LinkModel"));
|
|
|
13
13
|
var _UserServicesModel = _interopRequireDefault(require("../user/UserServicesModel"));
|
|
14
14
|
var _exceptions = require("../../exceptions");
|
|
15
15
|
var _constants = require("../../constants");
|
|
16
|
+
var _Cache = _interopRequireDefault(require("../../utils/browser/Cache"));
|
|
16
17
|
/**
|
|
17
18
|
* The Application model
|
|
18
19
|
*/
|
|
19
20
|
class ApplicationModel extends _ResourceModel.default {
|
|
20
|
-
constructor(
|
|
21
|
-
super(
|
|
21
|
+
constructor(modularuiResponse) {
|
|
22
|
+
super(modularuiResponse);
|
|
23
|
+
|
|
24
|
+
// store authentication type in session cache, to make it available when application is no longer available (when not permitted for example)
|
|
22
25
|
(0, _defineProperty2.default)(this, "_userServices", void 0);
|
|
26
|
+
_Cache.default.setItem("primaryAuthenticationType", this.primaryAuthenticationType);
|
|
23
27
|
}
|
|
28
|
+
|
|
24
29
|
/**
|
|
25
30
|
* Retrieve type of model
|
|
26
31
|
*/
|
|
@@ -79,6 +84,14 @@ class ApplicationModel extends _ResourceModel.default {
|
|
|
79
84
|
return [_constants.DEFAULT_AUTHENTICATION_TYPE];
|
|
80
85
|
}
|
|
81
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Returns the primary authentication type
|
|
89
|
+
* @returns {AuthenticationType}
|
|
90
|
+
*/
|
|
91
|
+
get primaryAuthenticationType() {
|
|
92
|
+
return this.authenticationTypes[0];
|
|
93
|
+
}
|
|
94
|
+
|
|
82
95
|
/**
|
|
83
96
|
* Getting the tab links
|
|
84
97
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApplicationModel.js","names":["_ResourceModel","_interopRequireDefault","require","_LinkModel","_UserServicesModel","_exceptions","_constants","ApplicationModel","ResourceModel","constructor","
|
|
1
|
+
{"version":3,"file":"ApplicationModel.js","names":["_ResourceModel","_interopRequireDefault","require","_LinkModel","_UserServicesModel","_exceptions","_constants","_Cache","ApplicationModel","ResourceModel","constructor","modularuiResponse","_defineProperty2","default","Cache","setItem","primaryAuthenticationType","type","modelName","isApplicableModel","data","contributions","resourcetype","getInitialChildModelLinks","userService","links","getLinkByKey","href","path","NotAllowedUriException","setChildModels","models","userServiceModel","_find","call","model","userServices","label","getContribution","authenticationTypes","DEFAULT_AUTHENTICATION_TYPE","_context","Function","bind","_sort","a","b","isPrimary","tabs","getLinksByGroup","modelcatalog","LinkModel","create","modelOptions","_userServices","UserServicesModel","isLoggedIn","userHref","userLink","userMustChangePassword","mustChangePassword","exports"],"sources":["../../../src/models/application/ApplicationModel.js"],"sourcesContent":["// @flow\nimport ResourceModel from \"../base/ResourceModel\";\nimport LinkModel from \"../links/LinkModel\";\nimport UserServicesModel from \"../user/UserServicesModel\";\n\nimport { NotAllowedUriException } from \"../../exceptions\";\n\nimport { DEFAULT_AUTHENTICATION_TYPE } from \"../../constants\";\n\nimport Cache from \"../../utils/browser/Cache\";\n\nimport type { ModularUIModel, AuthenticationType } from \"../types\";\nimport type { ModularUIResponse } from \"../../modularui\";\nimport type LinkCollection from \"../links/LinkCollection\";\nimport type Href from \"../href/Href\";\n\n/**\n * The Application model\n */\nexport default class ApplicationModel extends ResourceModel {\n _userServices: ?UserServicesModel;\n\n constructor(modularuiResponse: ModularUIResponse) {\n super(modularuiResponse);\n\n // store authentication type in session cache, to make it available when application is no longer available (when not permitted for example)\n Cache.setItem(\"primaryAuthenticationType\", this.primaryAuthenticationType);\n }\n\n /**\n * Retrieve type of model\n */\n get type(): string {\n return \"Application\";\n }\n\n /**\n */\n static get modelName(): string {\n return \"ApplicationModel\";\n }\n\n /**\n */\n static isApplicableModel(data: ModularUIResponse): boolean {\n return (\n data.contributions.resourcetype &&\n data.contributions.resourcetype === \"Application\"\n );\n }\n\n /**\n */\n getInitialChildModelLinks(): Array<LinkModel> {\n const userService = this.links.getLinkByKey(\"UserServices\");\n if (userService && userService.href.path === \"/login\") {\n throw new NotAllowedUriException(\n \"The user service (Login panel) should not have the uri '/login', use a different URI because this uri matches the login service.\",\n );\n }\n\n return userService ? [userService] : [];\n }\n\n /**\n */\n setChildModels(models: Array<ModularUIModel>) {\n const userServiceModel = models.find(\n (model) => model.type === \"UserServices\",\n );\n\n if (userServiceModel) {\n this.userServices = userServiceModel;\n }\n }\n\n /**\n * Getting the label of the application\n */\n get label(): string {\n return this.getContribution(\"label\", \"\");\n }\n\n /**\n * Getting the authentication types of the application\n */\n get authenticationTypes(): Array<AuthenticationType> {\n const authenticationTypes = this.getContribution(\"security\", [\n DEFAULT_AUTHENTICATION_TYPE,\n ]);\n\n if (authenticationTypes) {\n //put primary first\n return authenticationTypes?.sort(\n (a: AuthenticationType, b: AuthenticationType) =>\n a.isPrimary === b.isPrimary ? 0 : a.isPrimary ? -1 : 1,\n );\n }\n\n return [DEFAULT_AUTHENTICATION_TYPE];\n }\n\n /**\n * Returns the primary authentication type\n * @returns {AuthenticationType}\n */\n get primaryAuthenticationType(): AuthenticationType {\n return this.authenticationTypes[0];\n }\n\n /**\n * Getting the tab links\n */\n get tabs(): LinkCollection {\n return this.links.getLinksByGroup(\"tab\");\n }\n\n /**\n * Get modelcatalog link\n */\n get modelcatalog(): LinkModel {\n return LinkModel.create(\n \"modelcatalog\",\n \"/modelcatalog\",\n \"Model catalog\",\n this.modelOptions,\n );\n }\n\n /**\n * Set the userservices for this application\n */\n set userServices(model: ?ModularUIModel) {\n this._userServices = model instanceof UserServicesModel ? model : null;\n }\n\n /**\n * returns the userservices configured for this application\n */\n get userServices(): ?UserServicesModel {\n return this._userServices ? this._userServices : null;\n }\n\n /**\n * Indicates if the user is logged in\n */\n get isLoggedIn(): boolean {\n return this.userServices?.isLoggedIn ?? false;\n }\n\n /**\n * Retrieve link to the user information,\n * only available when the user services are available\n */\n get userHref(): Href | null {\n if (this.userServices?.userLink) {\n return this.userServices.userLink.href;\n }\n\n return null;\n }\n\n /**\n */\n get userMustChangePassword(): boolean {\n return this.userServices?.mustChangePassword ?? false;\n }\n}\n"],"mappings":";;;;;;;;;;AACA,IAAAA,cAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,kBAAA,GAAAH,sBAAA,CAAAC,OAAA;AAEA,IAAAG,WAAA,GAAAH,OAAA;AAEA,IAAAI,UAAA,GAAAJ,OAAA;AAEA,IAAAK,MAAA,GAAAN,sBAAA,CAAAC,OAAA;AAOA;AACA;AACA;AACe,MAAMM,gBAAgB,SAASC,sBAAa,CAAC;EAG1DC,WAAWA,CAACC,iBAAoC,EAAE;IAChD,KAAK,CAACA,iBAAiB,CAAC;;IAExB;IAAA,IAAAC,gBAAA,CAAAC,OAAA;IACAC,cAAK,CAACC,OAAO,CAAC,2BAA2B,EAAE,IAAI,CAACC,yBAAyB,CAAC;EAC5E;;EAEA;AACF;AACA;EACE,IAAIC,IAAIA,CAAA,EAAW;IACjB,OAAO,aAAa;EACtB;;EAEA;AACF;EACE,WAAWC,SAASA,CAAA,EAAW;IAC7B,OAAO,kBAAkB;EAC3B;;EAEA;AACF;EACE,OAAOC,iBAAiBA,CAACC,IAAuB,EAAW;IACzD,OACEA,IAAI,CAACC,aAAa,CAACC,YAAY,IAC/BF,IAAI,CAACC,aAAa,CAACC,YAAY,KAAK,aAAa;EAErD;;EAEA;AACF;EACEC,yBAAyBA,CAAA,EAAqB;IAC5C,MAAMC,WAAW,GAAG,IAAI,CAACC,KAAK,CAACC,YAAY,CAAC,cAAc,CAAC;IAC3D,IAAIF,WAAW,IAAIA,WAAW,CAACG,IAAI,CAACC,IAAI,KAAK,QAAQ,EAAE;MACrD,MAAM,IAAIC,kCAAsB,CAC9B,kIACF,CAAC;IACH;IAEA,OAAOL,WAAW,GAAG,CAACA,WAAW,CAAC,GAAG,EAAE;EACzC;;EAEA;AACF;EACEM,cAAcA,CAACC,MAA6B,EAAE;IAC5C,MAAMC,gBAAg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ACP,CAAC;EACH;;EAEA;AACF;AACA;EACE,IAAIjB,YAAYA,CAACD,KAAsB,EAAE;IACvC,IAAI,CAACmB,aAAa,GAAGnB,KAAK,YAAYoB,0BAAiB,GAAGpB,KAAK,GAAG,IAAI;EACxE;;EAEA;AACF;AACA;EACE,IAAIC,YAAYA,CAAA,EAAuB;IACrC,OAAO,IAAI,CAACkB,aAAa,GAAG,IAAI,CAACA,aAAa,GAAG,IAAI;EACvD;;EAEA;AACF;AACA;EACE,IAAIE,UAAUA,CAAA,EAAY;IACxB,OAAO,IAAI,CAACpB,YAAY,EAAEoB,UAAU,IAAI,KAAK;EAC/C;;EAEA;AACF;AACA;AACA;EACE,IAAIC,QAAQA,CAAA,EAAgB;IAC1B,IAAI,IAAI,CAACrB,YAAY,EAAEsB,QAAQ,EAAE;MAC/B,OAAO,IAAI,CAACtB,YAAY,CAACsB,QAAQ,CAAC/B,IAAI;IACxC;IAEA,OAAO,IAAI;EACb;;EAEA;AACF;EACE,IAAIgC,sBAAsBA,CAAA,EAAY;IACpC,OAAO,IAAI,CAACvB,YAAY,EAAEwB,kBAAkB,IAAI,KAAK;EACvD;AACF;AAACC,OAAA,CAAAhD,OAAA,GAAAL,gBAAA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beinformed/ui",
|
|
3
|
-
"version": "1.63.
|
|
3
|
+
"version": "1.63.13",
|
|
4
4
|
"description": "Toolbox for be informed javascript layouts",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"bugs": "https://support.beinformed.com",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"dependencies": {
|
|
72
72
|
"@babel/runtime-corejs3": "^7.28.4",
|
|
73
73
|
"@date-fns/tz": "^1.4.1",
|
|
74
|
-
"baseline-browser-mapping": "^2.9.
|
|
74
|
+
"baseline-browser-mapping": "^2.9.5",
|
|
75
75
|
"big.js": "^7.0.1",
|
|
76
76
|
"date-fns": "^4.1.0",
|
|
77
77
|
"deepmerge": "^4.3.1",
|
|
@@ -115,7 +115,12 @@ describe("authentication hooks", () => {
|
|
|
115
115
|
return res.status(200).body({ data: "ok" });
|
|
116
116
|
});
|
|
117
117
|
|
|
118
|
-
const store = mockStore({
|
|
118
|
+
const store = mockStore({
|
|
119
|
+
auth: {},
|
|
120
|
+
modularui: {},
|
|
121
|
+
router: { location: {} },
|
|
122
|
+
i18n: { locale: "en" },
|
|
123
|
+
});
|
|
119
124
|
|
|
120
125
|
/**
|
|
121
126
|
*/
|
|
@@ -135,6 +140,14 @@ describe("authentication hooks", () => {
|
|
|
135
140
|
|
|
136
141
|
expect(store.getActions()).toStrictEqual([
|
|
137
142
|
{ type: "START_PROGRESS" },
|
|
143
|
+
expect.objectContaining({
|
|
144
|
+
type: "MODULARUI/FETCH",
|
|
145
|
+
payload: expect.objectContaining({
|
|
146
|
+
key: "application(/)(en)",
|
|
147
|
+
}),
|
|
148
|
+
}),
|
|
149
|
+
{ type: "START_PROGRESS" },
|
|
150
|
+
{ type: "FINISH_PROGRESS" },
|
|
138
151
|
{ type: "MODULARUI/RESET" },
|
|
139
152
|
{ type: "START_PROGRESS" },
|
|
140
153
|
expect.objectContaining({
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import { useSelector, useDispatch } from "react-redux";
|
|
3
3
|
|
|
4
|
-
import { getApplication } from "../redux/_modularui/ModularUISelectors";
|
|
5
4
|
import { login, logout, resetAuthErrors } from "../redux/actions";
|
|
6
5
|
|
|
7
6
|
import Cache from "../utils/browser/Cache";
|
|
8
7
|
import {
|
|
9
|
-
DEFAULT_AUTHENTICATION_TYPE,
|
|
10
8
|
getBasePath,
|
|
11
9
|
getBasePathServer,
|
|
12
10
|
INTERNAL_LOGIN_TYPE,
|
|
@@ -20,6 +18,7 @@ import type { AuthenticationType } from "../models/types";
|
|
|
20
18
|
|
|
21
19
|
type LoginHook = {
|
|
22
20
|
isAuthenticated: boolean,
|
|
21
|
+
primaryAuthenticationType: AuthenticationType,
|
|
23
22
|
authenticationTypes: Array<AuthenticationType>,
|
|
24
23
|
errorMessage: ?string,
|
|
25
24
|
resetErrors: () => ResetAuthErrorsAction,
|
|
@@ -28,6 +27,7 @@ type LoginHook = {
|
|
|
28
27
|
};
|
|
29
28
|
type LogoutHook = {
|
|
30
29
|
isAuthenticated: boolean,
|
|
30
|
+
primaryAuthenticationType: AuthenticationType,
|
|
31
31
|
authenticationTypes: Array<AuthenticationType>,
|
|
32
32
|
logout: () => void,
|
|
33
33
|
logoutUrl: string,
|
|
@@ -45,11 +45,13 @@ export const useLogin = (): LoginHook => {
|
|
|
45
45
|
|
|
46
46
|
const isAuthenticated = application?.isLoggedIn ?? false;
|
|
47
47
|
|
|
48
|
+
const primaryAuthenticationType = Cache.getItem("primaryAuthenticationType");
|
|
49
|
+
|
|
48
50
|
return {
|
|
49
51
|
isAuthenticated,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
],
|
|
52
|
+
primaryAuthenticationType:
|
|
53
|
+
primaryAuthenticationType ?? application?.authenticationTypes[0],
|
|
54
|
+
authenticationTypes: application?.authenticationTypes ?? [],
|
|
53
55
|
errorMessage: auth.error,
|
|
54
56
|
resetErrors: () => dispatch(resetAuthErrors()),
|
|
55
57
|
login: (username: string, password: string) =>
|
|
@@ -78,18 +80,21 @@ export const useLogin = (): LoginHook => {
|
|
|
78
80
|
*/
|
|
79
81
|
export const useLogout = (): LogoutHook => {
|
|
80
82
|
const dispatch = useDispatch();
|
|
81
|
-
|
|
83
|
+
|
|
84
|
+
const application = useApplication();
|
|
82
85
|
|
|
83
86
|
const BASE_PATH = getBasePath();
|
|
84
87
|
|
|
85
88
|
const authenticate = new Authenticate();
|
|
86
89
|
|
|
90
|
+
const primaryAuthenticationType = Cache.getItem("primaryAuthenticationType");
|
|
91
|
+
|
|
87
92
|
const isAuthenticated = application?.isLoggedIn ?? false;
|
|
88
93
|
return {
|
|
89
94
|
isAuthenticated,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
],
|
|
95
|
+
primaryAuthenticationType:
|
|
96
|
+
primaryAuthenticationType ?? application?.authenticationTypes[0],
|
|
97
|
+
authenticationTypes: application?.authenticationTypes ?? [],
|
|
93
98
|
logout: () => {
|
|
94
99
|
const type = authenticate.authenticationType;
|
|
95
100
|
if (type === INTERNAL_LOGIN_TYPE.PAC4J_INDIRECT) {
|
|
@@ -7,6 +7,8 @@ import { NotAllowedUriException } from "../../exceptions";
|
|
|
7
7
|
|
|
8
8
|
import { DEFAULT_AUTHENTICATION_TYPE } from "../../constants";
|
|
9
9
|
|
|
10
|
+
import Cache from "../../utils/browser/Cache";
|
|
11
|
+
|
|
10
12
|
import type { ModularUIModel, AuthenticationType } from "../types";
|
|
11
13
|
import type { ModularUIResponse } from "../../modularui";
|
|
12
14
|
import type LinkCollection from "../links/LinkCollection";
|
|
@@ -18,6 +20,13 @@ import type Href from "../href/Href";
|
|
|
18
20
|
export default class ApplicationModel extends ResourceModel {
|
|
19
21
|
_userServices: ?UserServicesModel;
|
|
20
22
|
|
|
23
|
+
constructor(modularuiResponse: ModularUIResponse) {
|
|
24
|
+
super(modularuiResponse);
|
|
25
|
+
|
|
26
|
+
// store authentication type in session cache, to make it available when application is no longer available (when not permitted for example)
|
|
27
|
+
Cache.setItem("primaryAuthenticationType", this.primaryAuthenticationType);
|
|
28
|
+
}
|
|
29
|
+
|
|
21
30
|
/**
|
|
22
31
|
* Retrieve type of model
|
|
23
32
|
*/
|
|
@@ -91,6 +100,14 @@ export default class ApplicationModel extends ResourceModel {
|
|
|
91
100
|
return [DEFAULT_AUTHENTICATION_TYPE];
|
|
92
101
|
}
|
|
93
102
|
|
|
103
|
+
/**
|
|
104
|
+
* Returns the primary authentication type
|
|
105
|
+
* @returns {AuthenticationType}
|
|
106
|
+
*/
|
|
107
|
+
get primaryAuthenticationType(): AuthenticationType {
|
|
108
|
+
return this.authenticationTypes[0];
|
|
109
|
+
}
|
|
110
|
+
|
|
94
111
|
/**
|
|
95
112
|
* Getting the tab links
|
|
96
113
|
*/
|