@elliemae/pui-app-sdk 5.10.1 → 5.10.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/dist/cjs/api/auth/index.js +2 -2
- package/dist/cjs/communication/http-client/response-interceptor.js +24 -10
- package/dist/cjs/data/auth/actions.js +2 -2
- package/dist/cjs/sideeffect/auth/index.js +2 -0
- package/dist/cjs/utils/auth/index.js +24 -14
- package/dist/cjs/utils/auth/loginParams.js +29 -0
- package/dist/cjs/utils/auth/types.js +16 -0
- package/dist/cjs/utils/extendSession.js +47 -0
- package/dist/cjs/utils/log-records.js +4 -0
- package/dist/cjs/view/modals/session-expiry/index.js +3 -2
- package/dist/esm/api/auth/index.js +2 -2
- package/dist/esm/communication/http-client/response-interceptor.js +24 -10
- package/dist/esm/data/auth/actions.js +2 -2
- package/dist/esm/sideeffect/auth/index.js +2 -0
- package/dist/esm/utils/auth/index.js +24 -14
- package/dist/esm/utils/auth/loginParams.js +9 -0
- package/dist/esm/utils/auth/types.js +0 -0
- package/dist/esm/utils/extendSession.js +27 -0
- package/dist/esm/utils/log-records.js +4 -0
- package/dist/esm/view/modals/session-expiry/index.js +4 -6
- package/dist/types/lib/api/auth/index.d.ts +2 -2
- package/dist/types/lib/communication/http-client/response-interceptor.d.ts +2 -0
- package/dist/types/lib/data/auth/actions.d.ts +2 -2
- package/dist/types/lib/utils/auth/index.d.ts +4 -9
- package/dist/types/lib/utils/auth/loginParams.d.ts +10 -0
- package/dist/types/lib/utils/auth/types.d.ts +8 -0
- package/dist/types/lib/utils/extendSession.d.ts +5 -0
- package/dist/types/lib/utils/log-records.d.ts +4 -0
- package/package.json +6 -6
|
@@ -25,7 +25,7 @@ __export(auth_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(auth_exports);
|
|
26
26
|
var import_http_client = require("../../communication/http-client/index.js");
|
|
27
27
|
const getToken = async ({
|
|
28
|
-
|
|
28
|
+
code,
|
|
29
29
|
clientId,
|
|
30
30
|
scope,
|
|
31
31
|
redirectUri
|
|
@@ -35,7 +35,7 @@ const getToken = async ({
|
|
|
35
35
|
params.append("client_id", clientId);
|
|
36
36
|
params.append("redirect_uri", redirectUri);
|
|
37
37
|
params.append("scope", scope);
|
|
38
|
-
params.append("code",
|
|
38
|
+
params.append("code", code);
|
|
39
39
|
const { data } = await (0, import_http_client.getHTTPClient)().post(
|
|
40
40
|
"/oauth2/v1/token",
|
|
41
41
|
params
|
|
@@ -30,27 +30,41 @@ var response_interceptor_exports = {};
|
|
|
30
30
|
__export(response_interceptor_exports, {
|
|
31
31
|
handleFailure: () => handleFailure,
|
|
32
32
|
handleSuccess: () => handleSuccess,
|
|
33
|
-
onAuthorizationFailure: () => onAuthorizationFailure
|
|
33
|
+
onAuthorizationFailure: () => onAuthorizationFailure,
|
|
34
|
+
setEndSessionHandler: () => setEndSessionHandler
|
|
34
35
|
});
|
|
35
36
|
module.exports = __toCommonJS(response_interceptor_exports);
|
|
36
37
|
var import_axios = __toESM(require("axios"));
|
|
38
|
+
var import_loginParams = require("../../utils/auth/loginParams.js");
|
|
37
39
|
const HTTP_UNAUTHORIZED = 401;
|
|
38
40
|
let unAuthorizedFailureHandler = null;
|
|
41
|
+
let endSessionHandler = null;
|
|
39
42
|
const onAuthorizationFailure = (callback) => {
|
|
40
43
|
unAuthorizedFailureHandler = callback;
|
|
41
44
|
};
|
|
45
|
+
const setEndSessionHandler = (handler) => {
|
|
46
|
+
endSessionHandler = handler;
|
|
47
|
+
};
|
|
42
48
|
const handleSuccess = (response) => response;
|
|
43
49
|
const handleFailure = (error) => {
|
|
44
50
|
const { status } = (error || {}).response || {};
|
|
45
|
-
if (status === HTTP_UNAUTHORIZED
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
if (status === HTTP_UNAUTHORIZED) {
|
|
52
|
+
if (unAuthorizedFailureHandler && typeof unAuthorizedFailureHandler === "function") {
|
|
53
|
+
return unAuthorizedFailureHandler(error).then((authorizationHeader) => {
|
|
54
|
+
const { config } = error;
|
|
55
|
+
if (!config?.headers) throw error;
|
|
56
|
+
config.headers["Authorization"] = authorizationHeader;
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
import_axios.default.request(config).then(resolve).catch(reject);
|
|
59
|
+
});
|
|
60
|
+
}).catch((exception) => Promise.reject(exception));
|
|
61
|
+
}
|
|
62
|
+
if (endSessionHandler) {
|
|
63
|
+
endSessionHandler({ ...(0, import_loginParams.getLoginParams)(), skipRevoke: true }).catch(
|
|
64
|
+
() => {
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
}
|
|
54
68
|
}
|
|
55
69
|
return Promise.reject(error);
|
|
56
70
|
};
|
|
@@ -29,14 +29,14 @@ const LOGIN_SUCCESS = "auth/LOGIN_SUCCESS";
|
|
|
29
29
|
const LOGOUT = "auth/LOGOUT";
|
|
30
30
|
const auth = {
|
|
31
31
|
login: ({
|
|
32
|
-
|
|
32
|
+
code,
|
|
33
33
|
redirectUri,
|
|
34
34
|
clientId,
|
|
35
35
|
responseType,
|
|
36
36
|
scope
|
|
37
37
|
}) => ({
|
|
38
38
|
type: LOGIN,
|
|
39
|
-
payload: {
|
|
39
|
+
payload: { code, redirectUri, clientId, responseType, scope }
|
|
40
40
|
}),
|
|
41
41
|
logout: ({
|
|
42
42
|
clientId,
|
|
@@ -28,11 +28,13 @@ var import_actions = require("../../data/auth/actions.js");
|
|
|
28
28
|
var import_auth = require("../../utils/auth/index.js");
|
|
29
29
|
var import_micro_frontend = require("../../utils/micro-frontend/index.js");
|
|
30
30
|
var import_log_records = require("../../utils/log-records.js");
|
|
31
|
+
var import_response_interceptor = require("../../communication/http-client/response-interceptor.js");
|
|
31
32
|
function* login({
|
|
32
33
|
payload
|
|
33
34
|
}) {
|
|
34
35
|
try {
|
|
35
36
|
yield (0, import_effects.call)(import_auth.authorize, payload);
|
|
37
|
+
yield (0, import_effects.call)(import_response_interceptor.setEndSessionHandler, import_auth.endSession);
|
|
36
38
|
yield (0, import_effects.put)({ type: import_actions.LOGIN_SUCCESS });
|
|
37
39
|
} catch (err) {
|
|
38
40
|
(0, import_micro_frontend.getLogger)().error({
|
|
@@ -35,14 +35,15 @@ var import_helper = require("./helper.js");
|
|
|
35
35
|
var import_config = require("../app-config/config.js");
|
|
36
36
|
var import_micro_frontend = require("../micro-frontend/index.js");
|
|
37
37
|
var import_log_records = require("../log-records.js");
|
|
38
|
+
var import_loginParams = require("./loginParams.js");
|
|
38
39
|
const IDP_ENDPOINT_CONFIG_KEY = "serviceEndpoints.idp";
|
|
39
40
|
const isUserAuthorized = () => !!(0, import_helper.getAuthorizationHeader)();
|
|
40
41
|
const getIDPInfoFromUrl = () => {
|
|
41
42
|
const currentUrl = new URL(window.location.href);
|
|
42
|
-
const
|
|
43
|
+
const code = currentUrl.searchParams.get("code") || "";
|
|
43
44
|
const idpErrorCode = currentUrl.searchParams.get("error_code") || "";
|
|
44
45
|
currentUrl.search = "";
|
|
45
|
-
return {
|
|
46
|
+
return { code, idpErrorCode, redirectUri: currentUrl.href };
|
|
46
47
|
};
|
|
47
48
|
const navigateToLoginPage = ({
|
|
48
49
|
clientId,
|
|
@@ -71,16 +72,18 @@ const endSession = async ({
|
|
|
71
72
|
redirectUri,
|
|
72
73
|
responseType,
|
|
73
74
|
scope,
|
|
74
|
-
code = "1004"
|
|
75
|
+
code = "1004",
|
|
76
|
+
skipRevoke = false
|
|
75
77
|
}) => {
|
|
76
78
|
try {
|
|
77
79
|
const authorization = (0, import_helper.getAuthorizationHeader)();
|
|
78
80
|
sessionStorage.clear();
|
|
79
81
|
const token = authorization ? authorization.split(" ")[1] : "";
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
if (!skipRevoke)
|
|
83
|
+
await (0, import_auth.revokeToken)({
|
|
84
|
+
clientId,
|
|
85
|
+
token
|
|
86
|
+
});
|
|
84
87
|
(0, import_user_session_event.logoutEvent)();
|
|
85
88
|
(0, import_appdynamics.setAppDynamicsUserData)({ instanceId: "", userId: "" });
|
|
86
89
|
const idpHost = (0, import_config.getAppConfigValue)(IDP_ENDPOINT_CONFIG_KEY, "");
|
|
@@ -103,7 +106,7 @@ const endSession = async ({
|
|
|
103
106
|
}
|
|
104
107
|
};
|
|
105
108
|
const authorize = async ({
|
|
106
|
-
|
|
109
|
+
code,
|
|
107
110
|
redirectUri,
|
|
108
111
|
clientId,
|
|
109
112
|
scope,
|
|
@@ -111,11 +114,12 @@ const authorize = async ({
|
|
|
111
114
|
}) => {
|
|
112
115
|
try {
|
|
113
116
|
const { tokenType, accessToken } = await (0, import_auth.getToken)({
|
|
114
|
-
|
|
117
|
+
code,
|
|
115
118
|
clientId,
|
|
116
119
|
scope,
|
|
117
120
|
redirectUri
|
|
118
121
|
});
|
|
122
|
+
(0, import_loginParams.setLoginParams)({ clientId, scope, responseType, redirectUri, code });
|
|
119
123
|
const authorizationToken = `${tokenType} ${accessToken}`;
|
|
120
124
|
(0, import_helper.setAuthorizationHeader)(authorizationToken);
|
|
121
125
|
const introspectResponse = await (0, import_auth.introspectToken)({
|
|
@@ -144,8 +148,14 @@ const authorize = async ({
|
|
|
144
148
|
const pathName = new URL(redirectUri).pathname;
|
|
145
149
|
import_history.browserHistory.replace(pathName);
|
|
146
150
|
} catch (err) {
|
|
147
|
-
const
|
|
148
|
-
await endSession({
|
|
151
|
+
const errCode = err?.response?.data?.code;
|
|
152
|
+
await endSession({
|
|
153
|
+
clientId,
|
|
154
|
+
redirectUri,
|
|
155
|
+
code: errCode,
|
|
156
|
+
scope,
|
|
157
|
+
responseType
|
|
158
|
+
});
|
|
149
159
|
(0, import_micro_frontend.getLogger)().error({
|
|
150
160
|
...import_log_records.logRecords.LOGIN_FAILED,
|
|
151
161
|
exception: err
|
|
@@ -157,16 +167,16 @@ const login = async ({
|
|
|
157
167
|
scope,
|
|
158
168
|
responseType
|
|
159
169
|
}) => {
|
|
160
|
-
const {
|
|
170
|
+
const { code, idpErrorCode, redirectUri } = getIDPInfoFromUrl();
|
|
161
171
|
const loginInfo = {
|
|
162
172
|
clientId,
|
|
163
173
|
scope,
|
|
164
174
|
responseType,
|
|
165
175
|
redirectUri,
|
|
166
|
-
|
|
176
|
+
code,
|
|
167
177
|
idpErrorCode
|
|
168
178
|
};
|
|
169
|
-
if (
|
|
179
|
+
if (code) {
|
|
170
180
|
await authorize(loginInfo);
|
|
171
181
|
return { authorized: true };
|
|
172
182
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var loginParams_exports = {};
|
|
20
|
+
__export(loginParams_exports, {
|
|
21
|
+
getLoginParams: () => getLoginParams,
|
|
22
|
+
setLoginParams: () => setLoginParams
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(loginParams_exports);
|
|
25
|
+
let loginParams;
|
|
26
|
+
const setLoginParams = (params) => {
|
|
27
|
+
loginParams = params;
|
|
28
|
+
};
|
|
29
|
+
const getLoginParams = () => loginParams;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var extendSession_exports = {};
|
|
20
|
+
__export(extendSession_exports, {
|
|
21
|
+
extendUIandPSSSession: () => extendUIandPSSSession
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(extendSession_exports);
|
|
24
|
+
var import_loginParams = require("./auth/loginParams.js");
|
|
25
|
+
var import_helper = require("./auth/helper.js");
|
|
26
|
+
var import_auth = require("../api/auth/index.js");
|
|
27
|
+
var import_micro_frontend = require("./micro-frontend/index.js");
|
|
28
|
+
var import_log_records = require("./log-records.js");
|
|
29
|
+
var import_auth2 = require("./auth/index.js");
|
|
30
|
+
var import_session = require("./session.js");
|
|
31
|
+
const extendUIandPSSSession = async () => {
|
|
32
|
+
const loginParams = (0, import_loginParams.getLoginParams)();
|
|
33
|
+
try {
|
|
34
|
+
const authToken = (0, import_helper.getAuthorizationHeader)();
|
|
35
|
+
if (!authToken)
|
|
36
|
+
throw new Error("Authorization token not found to extend session");
|
|
37
|
+
const accessToken = authToken.split(" ")[1];
|
|
38
|
+
await (0, import_auth.introspectToken)({ clientId: loginParams.clientId, accessToken });
|
|
39
|
+
(0, import_session.resetUserIdleTime)(true);
|
|
40
|
+
} catch (e) {
|
|
41
|
+
(0, import_micro_frontend.getLogger)().error({
|
|
42
|
+
...import_log_records.logRecords.SESSION_RENEWAL_FAILED,
|
|
43
|
+
exception: e
|
|
44
|
+
});
|
|
45
|
+
await (0, import_auth2.endSession)({ ...loginParams, skipRevoke: true });
|
|
46
|
+
}
|
|
47
|
+
};
|
|
@@ -30,6 +30,7 @@ var import_ds_dialog = require("@elliemae/ds-dialog");
|
|
|
30
30
|
var import_react2 = require("../../../data/react.js");
|
|
31
31
|
var import_actions = require("../../../data/logout/actions.js");
|
|
32
32
|
var import_session = require("../../../utils/session.js");
|
|
33
|
+
var import_extendSession = require("../../../utils/extendSession.js");
|
|
33
34
|
var import_customHooks = require("./customHooks.js");
|
|
34
35
|
const SessionExpiry = (0, import_react.memo)(
|
|
35
36
|
({ open, warningNotifiedAt = 0 }) => {
|
|
@@ -42,9 +43,9 @@ const SessionExpiry = (0, import_react.memo)(
|
|
|
42
43
|
(0, import_react.useEffect)(() => {
|
|
43
44
|
setIsOpen(open);
|
|
44
45
|
}, [open]);
|
|
45
|
-
const resetSession = () => {
|
|
46
|
+
const resetSession = async () => {
|
|
46
47
|
setIsOpen(false);
|
|
47
|
-
(0,
|
|
48
|
+
await (0, import_extendSession.extendUIandPSSSession)();
|
|
48
49
|
(0, import_session.addEventListeners)();
|
|
49
50
|
dispatch(import_actions.logout.cancel());
|
|
50
51
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getHTTPClient } from "../../communication/http-client/index.js";
|
|
2
2
|
const getToken = async ({
|
|
3
|
-
|
|
3
|
+
code,
|
|
4
4
|
clientId,
|
|
5
5
|
scope,
|
|
6
6
|
redirectUri
|
|
@@ -10,7 +10,7 @@ const getToken = async ({
|
|
|
10
10
|
params.append("client_id", clientId);
|
|
11
11
|
params.append("redirect_uri", redirectUri);
|
|
12
12
|
params.append("scope", scope);
|
|
13
|
-
params.append("code",
|
|
13
|
+
params.append("code", code);
|
|
14
14
|
const { data } = await getHTTPClient().post(
|
|
15
15
|
"/oauth2/v1/token",
|
|
16
16
|
params
|
|
@@ -1,26 +1,40 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
|
+
import { getLoginParams } from "../../utils/auth/loginParams.js";
|
|
2
3
|
const HTTP_UNAUTHORIZED = 401;
|
|
3
4
|
let unAuthorizedFailureHandler = null;
|
|
5
|
+
let endSessionHandler = null;
|
|
4
6
|
const onAuthorizationFailure = (callback) => {
|
|
5
7
|
unAuthorizedFailureHandler = callback;
|
|
6
8
|
};
|
|
9
|
+
const setEndSessionHandler = (handler) => {
|
|
10
|
+
endSessionHandler = handler;
|
|
11
|
+
};
|
|
7
12
|
const handleSuccess = (response) => response;
|
|
8
13
|
const handleFailure = (error) => {
|
|
9
14
|
const { status } = (error || {}).response || {};
|
|
10
|
-
if (status === HTTP_UNAUTHORIZED
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
if (status === HTTP_UNAUTHORIZED) {
|
|
16
|
+
if (unAuthorizedFailureHandler && typeof unAuthorizedFailureHandler === "function") {
|
|
17
|
+
return unAuthorizedFailureHandler(error).then((authorizationHeader) => {
|
|
18
|
+
const { config } = error;
|
|
19
|
+
if (!config?.headers) throw error;
|
|
20
|
+
config.headers["Authorization"] = authorizationHeader;
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
axios.request(config).then(resolve).catch(reject);
|
|
23
|
+
});
|
|
24
|
+
}).catch((exception) => Promise.reject(exception));
|
|
25
|
+
}
|
|
26
|
+
if (endSessionHandler) {
|
|
27
|
+
endSessionHandler({ ...getLoginParams(), skipRevoke: true }).catch(
|
|
28
|
+
() => {
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
}
|
|
19
32
|
}
|
|
20
33
|
return Promise.reject(error);
|
|
21
34
|
};
|
|
22
35
|
export {
|
|
23
36
|
handleFailure,
|
|
24
37
|
handleSuccess,
|
|
25
|
-
onAuthorizationFailure
|
|
38
|
+
onAuthorizationFailure,
|
|
39
|
+
setEndSessionHandler
|
|
26
40
|
};
|
|
@@ -3,14 +3,14 @@ const LOGIN_SUCCESS = "auth/LOGIN_SUCCESS";
|
|
|
3
3
|
const LOGOUT = "auth/LOGOUT";
|
|
4
4
|
const auth = {
|
|
5
5
|
login: ({
|
|
6
|
-
|
|
6
|
+
code,
|
|
7
7
|
redirectUri,
|
|
8
8
|
clientId,
|
|
9
9
|
responseType,
|
|
10
10
|
scope
|
|
11
11
|
}) => ({
|
|
12
12
|
type: LOGIN,
|
|
13
|
-
payload: {
|
|
13
|
+
payload: { code, redirectUri, clientId, responseType, scope }
|
|
14
14
|
}),
|
|
15
15
|
logout: ({
|
|
16
16
|
clientId,
|
|
@@ -11,11 +11,13 @@ import {
|
|
|
11
11
|
import { authorize, endSession } from "../../utils/auth/index.js";
|
|
12
12
|
import { getLogger } from "../../utils/micro-frontend/index.js";
|
|
13
13
|
import { logRecords } from "../../utils/log-records.js";
|
|
14
|
+
import { setEndSessionHandler } from "../../communication/http-client/response-interceptor.js";
|
|
14
15
|
function* login({
|
|
15
16
|
payload
|
|
16
17
|
}) {
|
|
17
18
|
try {
|
|
18
19
|
yield call(authorize, payload);
|
|
20
|
+
yield call(setEndSessionHandler, endSession);
|
|
19
21
|
yield put({ type: LOGIN_SUCCESS });
|
|
20
22
|
} catch (err) {
|
|
21
23
|
getLogger().error({
|
|
@@ -11,14 +11,15 @@ import { getAuthorizationHeader, setAuthorizationHeader } from "./helper.js";
|
|
|
11
11
|
import { getAppConfigValue } from "../app-config/config.js";
|
|
12
12
|
import { getLogger } from "../micro-frontend/index.js";
|
|
13
13
|
import { logRecords } from "../log-records.js";
|
|
14
|
+
import { setLoginParams } from "./loginParams.js";
|
|
14
15
|
const IDP_ENDPOINT_CONFIG_KEY = "serviceEndpoints.idp";
|
|
15
16
|
const isUserAuthorized = () => !!getAuthorizationHeader();
|
|
16
17
|
const getIDPInfoFromUrl = () => {
|
|
17
18
|
const currentUrl = new URL(window.location.href);
|
|
18
|
-
const
|
|
19
|
+
const code = currentUrl.searchParams.get("code") || "";
|
|
19
20
|
const idpErrorCode = currentUrl.searchParams.get("error_code") || "";
|
|
20
21
|
currentUrl.search = "";
|
|
21
|
-
return {
|
|
22
|
+
return { code, idpErrorCode, redirectUri: currentUrl.href };
|
|
22
23
|
};
|
|
23
24
|
const navigateToLoginPage = ({
|
|
24
25
|
clientId,
|
|
@@ -47,16 +48,18 @@ const endSession = async ({
|
|
|
47
48
|
redirectUri,
|
|
48
49
|
responseType,
|
|
49
50
|
scope,
|
|
50
|
-
code = "1004"
|
|
51
|
+
code = "1004",
|
|
52
|
+
skipRevoke = false
|
|
51
53
|
}) => {
|
|
52
54
|
try {
|
|
53
55
|
const authorization = getAuthorizationHeader();
|
|
54
56
|
sessionStorage.clear();
|
|
55
57
|
const token = authorization ? authorization.split(" ")[1] : "";
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
if (!skipRevoke)
|
|
59
|
+
await revokeToken({
|
|
60
|
+
clientId,
|
|
61
|
+
token
|
|
62
|
+
});
|
|
60
63
|
logoutEvent();
|
|
61
64
|
setAppDynamicsUserData({ instanceId: "", userId: "" });
|
|
62
65
|
const idpHost = getAppConfigValue(IDP_ENDPOINT_CONFIG_KEY, "");
|
|
@@ -79,7 +82,7 @@ const endSession = async ({
|
|
|
79
82
|
}
|
|
80
83
|
};
|
|
81
84
|
const authorize = async ({
|
|
82
|
-
|
|
85
|
+
code,
|
|
83
86
|
redirectUri,
|
|
84
87
|
clientId,
|
|
85
88
|
scope,
|
|
@@ -87,11 +90,12 @@ const authorize = async ({
|
|
|
87
90
|
}) => {
|
|
88
91
|
try {
|
|
89
92
|
const { tokenType, accessToken } = await getToken({
|
|
90
|
-
|
|
93
|
+
code,
|
|
91
94
|
clientId,
|
|
92
95
|
scope,
|
|
93
96
|
redirectUri
|
|
94
97
|
});
|
|
98
|
+
setLoginParams({ clientId, scope, responseType, redirectUri, code });
|
|
95
99
|
const authorizationToken = `${tokenType} ${accessToken}`;
|
|
96
100
|
setAuthorizationHeader(authorizationToken);
|
|
97
101
|
const introspectResponse = await introspectToken({
|
|
@@ -120,8 +124,14 @@ const authorize = async ({
|
|
|
120
124
|
const pathName = new URL(redirectUri).pathname;
|
|
121
125
|
history.replace(pathName);
|
|
122
126
|
} catch (err) {
|
|
123
|
-
const
|
|
124
|
-
await endSession({
|
|
127
|
+
const errCode = err?.response?.data?.code;
|
|
128
|
+
await endSession({
|
|
129
|
+
clientId,
|
|
130
|
+
redirectUri,
|
|
131
|
+
code: errCode,
|
|
132
|
+
scope,
|
|
133
|
+
responseType
|
|
134
|
+
});
|
|
125
135
|
getLogger().error({
|
|
126
136
|
...logRecords.LOGIN_FAILED,
|
|
127
137
|
exception: err
|
|
@@ -133,16 +143,16 @@ const login = async ({
|
|
|
133
143
|
scope,
|
|
134
144
|
responseType
|
|
135
145
|
}) => {
|
|
136
|
-
const {
|
|
146
|
+
const { code, idpErrorCode, redirectUri } = getIDPInfoFromUrl();
|
|
137
147
|
const loginInfo = {
|
|
138
148
|
clientId,
|
|
139
149
|
scope,
|
|
140
150
|
responseType,
|
|
141
151
|
redirectUri,
|
|
142
|
-
|
|
152
|
+
code,
|
|
143
153
|
idpErrorCode
|
|
144
154
|
};
|
|
145
|
-
if (
|
|
155
|
+
if (code) {
|
|
146
156
|
await authorize(loginInfo);
|
|
147
157
|
return { authorized: true };
|
|
148
158
|
}
|
|
File without changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { getLoginParams } from "./auth/loginParams.js";
|
|
2
|
+
import { getAuthorizationHeader } from "./auth/helper.js";
|
|
3
|
+
import { introspectToken } from "../api/auth/index.js";
|
|
4
|
+
import { getLogger } from "./micro-frontend/index.js";
|
|
5
|
+
import { logRecords } from "./log-records.js";
|
|
6
|
+
import { endSession } from "./auth/index.js";
|
|
7
|
+
import { resetUserIdleTime } from "./session.js";
|
|
8
|
+
const extendUIandPSSSession = async () => {
|
|
9
|
+
const loginParams = getLoginParams();
|
|
10
|
+
try {
|
|
11
|
+
const authToken = getAuthorizationHeader();
|
|
12
|
+
if (!authToken)
|
|
13
|
+
throw new Error("Authorization token not found to extend session");
|
|
14
|
+
const accessToken = authToken.split(" ")[1];
|
|
15
|
+
await introspectToken({ clientId: loginParams.clientId, accessToken });
|
|
16
|
+
resetUserIdleTime(true);
|
|
17
|
+
} catch (e) {
|
|
18
|
+
getLogger().error({
|
|
19
|
+
...logRecords.SESSION_RENEWAL_FAILED,
|
|
20
|
+
exception: e
|
|
21
|
+
});
|
|
22
|
+
await endSession({ ...loginParams, skipRevoke: true });
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
export {
|
|
26
|
+
extendUIandPSSSession
|
|
27
|
+
};
|
|
@@ -14,10 +14,8 @@ import {
|
|
|
14
14
|
} from "@elliemae/ds-dialog";
|
|
15
15
|
import { useAppDispatch } from "../../../data/react.js";
|
|
16
16
|
import { logout } from "../../../data/logout/actions.js";
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
addEventListeners
|
|
20
|
-
} from "../../../utils/session.js";
|
|
17
|
+
import { addEventListeners } from "../../../utils/session.js";
|
|
18
|
+
import { extendUIandPSSSession } from "../../../utils/extendSession.js";
|
|
21
19
|
import { useTrackSessionExpiry } from "./customHooks.js";
|
|
22
20
|
const SessionExpiry = memo(
|
|
23
21
|
({ open, warningNotifiedAt = 0 }) => {
|
|
@@ -30,9 +28,9 @@ const SessionExpiry = memo(
|
|
|
30
28
|
useEffect(() => {
|
|
31
29
|
setIsOpen(open);
|
|
32
30
|
}, [open]);
|
|
33
|
-
const resetSession = () => {
|
|
31
|
+
const resetSession = async () => {
|
|
34
32
|
setIsOpen(false);
|
|
35
|
-
|
|
33
|
+
await extendUIandPSSSession();
|
|
36
34
|
addEventListeners();
|
|
37
35
|
dispatch(logout.cancel());
|
|
38
36
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AxiosResponse, AxiosError } from 'axios';
|
|
2
2
|
interface GetTokenRequestParams {
|
|
3
|
-
|
|
3
|
+
code: string;
|
|
4
4
|
clientId: string;
|
|
5
5
|
scope: string;
|
|
6
6
|
redirectUri: string;
|
|
@@ -15,7 +15,7 @@ interface GetTokenError {
|
|
|
15
15
|
export interface GetTokenErrorResponse extends AxiosError {
|
|
16
16
|
response: AxiosResponse<GetTokenError>;
|
|
17
17
|
}
|
|
18
|
-
export declare const getToken: ({
|
|
18
|
+
export declare const getToken: ({ code, clientId, scope, redirectUri, }: GetTokenRequestParams) => Promise<{
|
|
19
19
|
tokenType: string;
|
|
20
20
|
accessToken: string;
|
|
21
21
|
}>;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { AxiosError, AxiosResponse } from 'axios';
|
|
2
|
+
import type { EndSessionFn } from '../../utils/auth/types.js';
|
|
2
3
|
type FailureCallback = {
|
|
3
4
|
(error: AxiosError): Promise<string>;
|
|
4
5
|
};
|
|
5
6
|
export declare const onAuthorizationFailure: (callback: FailureCallback) => void;
|
|
7
|
+
export declare const setEndSessionHandler: (handler: EndSessionFn) => void;
|
|
6
8
|
export declare const handleSuccess: (response: AxiosResponse) => AxiosResponse;
|
|
7
9
|
export declare const handleFailure: (error: AxiosError) => Promise<unknown>;
|
|
8
10
|
export {};
|
|
@@ -3,7 +3,7 @@ export declare const LOGIN = "auth/LOGIN";
|
|
|
3
3
|
export declare const LOGIN_SUCCESS = "auth/LOGIN_SUCCESS";
|
|
4
4
|
export declare const LOGOUT = "auth/LOGOUT";
|
|
5
5
|
export interface LoginParms {
|
|
6
|
-
|
|
6
|
+
code: string;
|
|
7
7
|
redirectUri: string;
|
|
8
8
|
clientId: string;
|
|
9
9
|
responseType: string;
|
|
@@ -17,6 +17,6 @@ export interface LogoutParams {
|
|
|
17
17
|
code: string;
|
|
18
18
|
}
|
|
19
19
|
export declare const auth: {
|
|
20
|
-
login: ({
|
|
20
|
+
login: ({ code, redirectUri, clientId, responseType, scope, }: LoginParms) => PayloadAction<LoginParms>;
|
|
21
21
|
logout: ({ clientId, redirectUri, responseType, scope, code, }: LogoutParams) => PayloadAction<LogoutParams>;
|
|
22
22
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { EndSessionFn } from './types.js';
|
|
1
2
|
export declare const isUserAuthorized: () => boolean;
|
|
2
3
|
export declare const getIDPInfoFromUrl: () => {
|
|
3
|
-
|
|
4
|
+
code: string;
|
|
4
5
|
idpErrorCode: string;
|
|
5
6
|
redirectUri: string;
|
|
6
7
|
};
|
|
@@ -11,15 +12,9 @@ export declare const navigateToLoginPage: ({ clientId, redirectUri, idpErrorCode
|
|
|
11
12
|
scope: string;
|
|
12
13
|
responseType: string;
|
|
13
14
|
}) => void;
|
|
14
|
-
export declare const endSession:
|
|
15
|
-
|
|
16
|
-
redirectUri: string;
|
|
17
|
-
responseType: string;
|
|
18
|
-
scope: string;
|
|
15
|
+
export declare const endSession: EndSessionFn;
|
|
16
|
+
export declare const authorize: ({ code, redirectUri, clientId, scope, responseType, }: {
|
|
19
17
|
code: string;
|
|
20
|
-
}) => Promise<void>;
|
|
21
|
-
export declare const authorize: ({ idpCode, redirectUri, clientId, scope, responseType, }: {
|
|
22
|
-
idpCode: string;
|
|
23
18
|
redirectUri: string;
|
|
24
19
|
clientId: string;
|
|
25
20
|
scope: string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type LoginParams = {
|
|
2
|
+
clientId: string;
|
|
3
|
+
scope: string;
|
|
4
|
+
responseType: string;
|
|
5
|
+
redirectUri: string;
|
|
6
|
+
code: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const setLoginParams: (params: LoginParams) => void;
|
|
9
|
+
export declare const getLoginParams: () => LoginParams;
|
|
10
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/pui-app-sdk",
|
|
3
|
-
"version": "5.10.
|
|
3
|
+
"version": "5.10.2",
|
|
4
4
|
"description": "ICE MT UI Platform Application SDK ",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"*.css",
|
|
@@ -128,9 +128,9 @@
|
|
|
128
128
|
"@elliemae/ds-toast": "^3.35.0",
|
|
129
129
|
"@elliemae/ds-utilities": "^3.35.0",
|
|
130
130
|
"@elliemae/em-ssf-guest": "^1.11.3",
|
|
131
|
-
"@elliemae/pui-diagnostics": "^3.5.
|
|
131
|
+
"@elliemae/pui-diagnostics": "^3.5.2",
|
|
132
132
|
"@elliemae/pui-micro-frontend-base": "^1.14.0",
|
|
133
|
-
"@elliemae/pui-scripting-object": "^1.
|
|
133
|
+
"@elliemae/pui-scripting-object": "^1.37.0",
|
|
134
134
|
"@elliemae/pui-theme": "^2.9.3",
|
|
135
135
|
"@elliemae/pui-user-monitoring": "^1.23.0"
|
|
136
136
|
},
|
|
@@ -153,12 +153,12 @@
|
|
|
153
153
|
"@elliemae/ds-toast": "~3.35.0",
|
|
154
154
|
"@elliemae/ds-utilities": "~3.35.0",
|
|
155
155
|
"@elliemae/em-ssf-guest": "~1.11.3",
|
|
156
|
-
"@elliemae/pui-cli": "~8.34.
|
|
157
|
-
"@elliemae/pui-diagnostics": "~3.5.
|
|
156
|
+
"@elliemae/pui-cli": "~8.34.2",
|
|
157
|
+
"@elliemae/pui-diagnostics": "~3.5.2",
|
|
158
158
|
"@elliemae/pui-doc-gen": "~1.9.0",
|
|
159
159
|
"@elliemae/pui-e2e-test-sdk": "~8.1.4",
|
|
160
160
|
"@elliemae/pui-micro-frontend-base": "~1.14.0",
|
|
161
|
-
"@elliemae/pui-scripting-object": "~1.
|
|
161
|
+
"@elliemae/pui-scripting-object": "~1.37.0",
|
|
162
162
|
"@elliemae/pui-theme": "~2.9.3",
|
|
163
163
|
"@elliemae/pui-user-monitoring": "~1.23.0",
|
|
164
164
|
"@types/react-aria-live": "~2.0.6"
|