@frontegg/react-hooks 6.155.0-alpha.1 → 6.155.0-alpha.3
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/auth/stepUp/consts.d.ts +4 -0
- package/auth/stepUp/consts.js +4 -0
- package/auth/stepUp/index.d.ts +2 -0
- package/auth/stepUp/index.js +2 -0
- package/auth/stepUp/interfaces.d.ts +14 -0
- package/auth/stepUp/interfaces.js +1 -0
- package/auth/stepUp/stepUp.d.ts +27 -0
- package/auth/stepUp/stepUp.js +66 -0
- package/index.js +1 -1
- package/node/auth/stepUp/consts.js +11 -0
- package/node/auth/stepUp/index.js +27 -0
- package/node/auth/stepUp/interfaces.js +5 -0
- package/node/auth/stepUp/stepUp.js +78 -0
- package/node/index.js +1 -1
- package/package.json +3 -3
- package/auth/stepUp.d.ts +0 -10
- package/auth/stepUp.js +0 -55
- package/node/auth/stepUp.js +0 -67
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { StepUpState } from '@frontegg/redux-store';
|
|
2
|
+
export declare type StepUpStateMapper<S> = (state: StepUpState) => S;
|
|
3
|
+
/**
|
|
4
|
+
* Step up options (for stepUp function)
|
|
5
|
+
*/
|
|
6
|
+
export interface StepUpOptions {
|
|
7
|
+
maxAge?: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* useIsSteppedUp hook options
|
|
11
|
+
*/
|
|
12
|
+
export interface UseIsSteppedUpOptions {
|
|
13
|
+
maxAge?: number;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { StepUpState, StepUpActions } from '@frontegg/redux-store';
|
|
2
|
+
import { RedirectOptions } from '@frontegg/rest-api';
|
|
3
|
+
import { StepUpStateMapper, UseIsSteppedUpOptions } from './interfaces';
|
|
4
|
+
export declare function useStepUpState(): StepUpState;
|
|
5
|
+
export declare function useStepUpState<S>(stateMapper: StepUpStateMapper<S>): S;
|
|
6
|
+
export declare const useStepUpActions: () => StepUpActions;
|
|
7
|
+
/**
|
|
8
|
+
* Redirects to the step up url with the max age param and set the redirect url in the local storage
|
|
9
|
+
* The redirect url will be used after the step up flow is done
|
|
10
|
+
* @param stepUpUrl - step up url to redirect to
|
|
11
|
+
* @param onRedirectTo - redirect to function
|
|
12
|
+
* @param maxAge - max age of step up
|
|
13
|
+
*/
|
|
14
|
+
export declare const redirectByStepUpUrl: (stepUpUrl: string, onRedirectTo: (path: string, opts?: RedirectOptions | undefined) => void, maxAge?: number | undefined) => void;
|
|
15
|
+
/**
|
|
16
|
+
* @returns max age from the query param as a number or null if not exists
|
|
17
|
+
*/
|
|
18
|
+
export declare const getMaxAgeFromQueryParam: () => number | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* @returns step up function that redirects to the step up url with the max age param and set the redirect url in the local storage
|
|
21
|
+
*/
|
|
22
|
+
export declare const useStepUp: () => any;
|
|
23
|
+
/**
|
|
24
|
+
* @param options.maxAge - max age of step up
|
|
25
|
+
* @returns true when the user is stepped up, false otherwise
|
|
26
|
+
*/
|
|
27
|
+
export declare const useIsSteppedUp: ({ maxAge }?: UseIsSteppedUpOptions) => boolean;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { FRONTEGG_AFTER_AUTH_REDIRECT_URL, stepUpReducers, stepUpActions, getSearchParam, isSteppedUp } from '@frontegg/redux-store';
|
|
2
|
+
import { reducerActionsGenerator, stateHookGenerator, useAuthRoutes, useAuthUser, useOnRedirectTo } from '../hooks';
|
|
3
|
+
import { useCallback } from 'react';
|
|
4
|
+
import { STEP_UP_MAX_AGE_PARAM_NAME } from './consts';
|
|
5
|
+
const defaultMapper = state => state;
|
|
6
|
+
export function useStepUpState(stateMapper = defaultMapper) {
|
|
7
|
+
return stateHookGenerator(stateMapper, 'stepUpState');
|
|
8
|
+
}
|
|
9
|
+
export const useStepUpActions = () => reducerActionsGenerator(stepUpActions, stepUpReducers);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Redirects to the step up url with the max age param and set the redirect url in the local storage
|
|
13
|
+
* The redirect url will be used after the step up flow is done
|
|
14
|
+
* @param stepUpUrl - step up url to redirect to
|
|
15
|
+
* @param onRedirectTo - redirect to function
|
|
16
|
+
* @param maxAge - max age of step up
|
|
17
|
+
*/
|
|
18
|
+
export const redirectByStepUpUrl = (stepUpUrl, onRedirectTo, maxAge) => {
|
|
19
|
+
const encodedRedirectUrl = window.location.pathname + window.location.search;
|
|
20
|
+
const maxAgePart = maxAge !== undefined ? `?${STEP_UP_MAX_AGE_PARAM_NAME}=${maxAge}` : '';
|
|
21
|
+
window.localStorage.setItem(FRONTEGG_AFTER_AUTH_REDIRECT_URL, encodedRedirectUrl);
|
|
22
|
+
onRedirectTo(`${stepUpUrl}${maxAgePart}`, {
|
|
23
|
+
refresh: false
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @returns max age from the query param as a number or null if not exists
|
|
29
|
+
*/
|
|
30
|
+
export const getMaxAgeFromQueryParam = () => {
|
|
31
|
+
const str = getSearchParam(STEP_UP_MAX_AGE_PARAM_NAME);
|
|
32
|
+
return str === undefined ? undefined : +str;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @returns step up function that redirects to the step up url with the max age param and set the redirect url in the local storage
|
|
37
|
+
*/
|
|
38
|
+
export const useStepUp = () => {
|
|
39
|
+
const {
|
|
40
|
+
stepUpUrl
|
|
41
|
+
} = useAuthRoutes();
|
|
42
|
+
const onRedirectTo = useOnRedirectTo();
|
|
43
|
+
return useCallback(options => {
|
|
44
|
+
redirectByStepUpUrl(stepUpUrl, onRedirectTo, options == null ? void 0 : options.maxAge);
|
|
45
|
+
}, [stepUpUrl, onRedirectTo]);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param options.maxAge - max age of step up
|
|
50
|
+
* @returns true when the user is stepped up, false otherwise
|
|
51
|
+
*/
|
|
52
|
+
export const useIsSteppedUp = ({
|
|
53
|
+
maxAge
|
|
54
|
+
} = {}) => {
|
|
55
|
+
const {
|
|
56
|
+
amr = [],
|
|
57
|
+
acr = '',
|
|
58
|
+
auth_time
|
|
59
|
+
} = useAuthUser();
|
|
60
|
+
return isSteppedUp({
|
|
61
|
+
amr,
|
|
62
|
+
acr,
|
|
63
|
+
auth_time,
|
|
64
|
+
maxAge
|
|
65
|
+
});
|
|
66
|
+
};
|
package/index.js
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.STEP_UP_MAX_AGE_PARAM_NAME = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* The name of the query param that contains the max age of the step up
|
|
9
|
+
*/
|
|
10
|
+
const STEP_UP_MAX_AGE_PARAM_NAME = 'maxAge';
|
|
11
|
+
exports.STEP_UP_MAX_AGE_PARAM_NAME = STEP_UP_MAX_AGE_PARAM_NAME;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _stepUp = require("./stepUp");
|
|
7
|
+
Object.keys(_stepUp).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _stepUp[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _stepUp[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _interfaces = require("./interfaces");
|
|
18
|
+
Object.keys(_interfaces).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _interfaces[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _interfaces[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useStepUpActions = exports.useStepUp = exports.useIsSteppedUp = exports.redirectByStepUpUrl = exports.getMaxAgeFromQueryParam = void 0;
|
|
7
|
+
exports.useStepUpState = useStepUpState;
|
|
8
|
+
var _reduxStore = require("@frontegg/redux-store");
|
|
9
|
+
var _hooks = require("../hooks");
|
|
10
|
+
var _react = require("react");
|
|
11
|
+
var _consts = require("./consts");
|
|
12
|
+
const defaultMapper = state => state;
|
|
13
|
+
function useStepUpState(stateMapper = defaultMapper) {
|
|
14
|
+
return (0, _hooks.stateHookGenerator)(stateMapper, 'stepUpState');
|
|
15
|
+
}
|
|
16
|
+
const useStepUpActions = () => (0, _hooks.reducerActionsGenerator)(_reduxStore.stepUpActions, _reduxStore.stepUpReducers);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Redirects to the step up url with the max age param and set the redirect url in the local storage
|
|
20
|
+
* The redirect url will be used after the step up flow is done
|
|
21
|
+
* @param stepUpUrl - step up url to redirect to
|
|
22
|
+
* @param onRedirectTo - redirect to function
|
|
23
|
+
* @param maxAge - max age of step up
|
|
24
|
+
*/
|
|
25
|
+
exports.useStepUpActions = useStepUpActions;
|
|
26
|
+
const redirectByStepUpUrl = (stepUpUrl, onRedirectTo, maxAge) => {
|
|
27
|
+
const encodedRedirectUrl = window.location.pathname + window.location.search;
|
|
28
|
+
const maxAgePart = maxAge !== undefined ? `?${_consts.STEP_UP_MAX_AGE_PARAM_NAME}=${maxAge}` : '';
|
|
29
|
+
window.localStorage.setItem(_reduxStore.FRONTEGG_AFTER_AUTH_REDIRECT_URL, encodedRedirectUrl);
|
|
30
|
+
onRedirectTo(`${stepUpUrl}${maxAgePart}`, {
|
|
31
|
+
refresh: false
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @returns max age from the query param as a number or null if not exists
|
|
37
|
+
*/
|
|
38
|
+
exports.redirectByStepUpUrl = redirectByStepUpUrl;
|
|
39
|
+
const getMaxAgeFromQueryParam = () => {
|
|
40
|
+
const str = (0, _reduxStore.getSearchParam)(_consts.STEP_UP_MAX_AGE_PARAM_NAME);
|
|
41
|
+
return str === undefined ? undefined : +str;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @returns step up function that redirects to the step up url with the max age param and set the redirect url in the local storage
|
|
46
|
+
*/
|
|
47
|
+
exports.getMaxAgeFromQueryParam = getMaxAgeFromQueryParam;
|
|
48
|
+
const useStepUp = () => {
|
|
49
|
+
const {
|
|
50
|
+
stepUpUrl
|
|
51
|
+
} = (0, _hooks.useAuthRoutes)();
|
|
52
|
+
const onRedirectTo = (0, _hooks.useOnRedirectTo)();
|
|
53
|
+
return (0, _react.useCallback)(options => {
|
|
54
|
+
redirectByStepUpUrl(stepUpUrl, onRedirectTo, options == null ? void 0 : options.maxAge);
|
|
55
|
+
}, [stepUpUrl, onRedirectTo]);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @param options.maxAge - max age of step up
|
|
60
|
+
* @returns true when the user is stepped up, false otherwise
|
|
61
|
+
*/
|
|
62
|
+
exports.useStepUp = useStepUp;
|
|
63
|
+
const useIsSteppedUp = ({
|
|
64
|
+
maxAge
|
|
65
|
+
} = {}) => {
|
|
66
|
+
const {
|
|
67
|
+
amr = [],
|
|
68
|
+
acr = '',
|
|
69
|
+
auth_time
|
|
70
|
+
} = (0, _hooks.useAuthUser)();
|
|
71
|
+
return (0, _reduxStore.isSteppedUp)({
|
|
72
|
+
amr,
|
|
73
|
+
acr,
|
|
74
|
+
auth_time,
|
|
75
|
+
maxAge
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
exports.useIsSteppedUp = useIsSteppedUp;
|
package/node/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontegg/react-hooks",
|
|
3
|
-
"version": "6.155.0-alpha.
|
|
3
|
+
"version": "6.155.0-alpha.3",
|
|
4
4
|
"main": "./node/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Frontegg LTD",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@babel/runtime": "^7.18.6",
|
|
9
|
-
"@frontegg/redux-store": "6.155.0-alpha.
|
|
10
|
-
"@frontegg/types": "6.155.0-alpha.
|
|
9
|
+
"@frontegg/redux-store": "6.155.0-alpha.3",
|
|
10
|
+
"@frontegg/types": "6.155.0-alpha.3",
|
|
11
11
|
"@types/react": "*",
|
|
12
12
|
"get-value": "^3.0.1",
|
|
13
13
|
"react-redux": "^7.x"
|
package/auth/stepUp.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { StepUpState, StepUpActions } from '@frontegg/redux-store';
|
|
2
|
-
import { RedirectOptions } from '@frontegg/rest-api';
|
|
3
|
-
export declare type StepUpStateMapper<S> = (state: StepUpState) => S;
|
|
4
|
-
export declare function useStepUpState(): StepUpState;
|
|
5
|
-
export declare function useStepUpState<S>(stateMapper: StepUpStateMapper<S>): S;
|
|
6
|
-
export declare const useStepUpActions: () => StepUpActions;
|
|
7
|
-
export declare const redirectByStepUpUrl: (stepUpUrl: string, onRedirectTo: (path: string, opts?: RedirectOptions | undefined) => void, maxAge?: number | undefined) => void;
|
|
8
|
-
export declare const getMaxAgeFromQueryParam: () => number | null;
|
|
9
|
-
export declare const useStepUp: () => any;
|
|
10
|
-
export declare const useIsSteppedUp: () => boolean;
|
package/auth/stepUp.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { STEP_UP_REDIRECT_URL_QUERY_PARAM, stepUpReducers, stepUpActions, getQueryParam } from '@frontegg/redux-store';
|
|
2
|
-
import { reducerActionsGenerator, stateHookGenerator, useAuth, useAuthRoutes, useOnRedirectTo } from './hooks';
|
|
3
|
-
import { useCallback } from 'react';
|
|
4
|
-
const defaultMapper = state => state;
|
|
5
|
-
const STEP_UP_MAX_AGE_PARAM_NAME = 'maxAge';
|
|
6
|
-
export function useStepUpState(stateMapper = defaultMapper) {
|
|
7
|
-
return stateHookGenerator(stateMapper, 'stepUpState');
|
|
8
|
-
}
|
|
9
|
-
export const useStepUpActions = () => reducerActionsGenerator(stepUpActions, stepUpReducers);
|
|
10
|
-
export const redirectByStepUpUrl = (stepUpUrl, onRedirectTo, maxAge) => {
|
|
11
|
-
const encodedRedirectUrl = encodeURIComponent(window.location.pathname + window.location.search);
|
|
12
|
-
onRedirectTo(`${stepUpUrl}?${STEP_UP_REDIRECT_URL_QUERY_PARAM}=${encodedRedirectUrl}&${STEP_UP_MAX_AGE_PARAM_NAME}=${maxAge}`, {
|
|
13
|
-
refresh: false
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
export const getMaxAgeFromQueryParam = () => {
|
|
17
|
-
const str = getQueryParam(STEP_UP_MAX_AGE_PARAM_NAME);
|
|
18
|
-
return str === null ? null : +str;
|
|
19
|
-
};
|
|
20
|
-
export const useStepUp = () => {
|
|
21
|
-
// also custom url?
|
|
22
|
-
const {
|
|
23
|
-
stepUpUrl
|
|
24
|
-
} = useAuthRoutes();
|
|
25
|
-
const onRedirectTo = useOnRedirectTo();
|
|
26
|
-
|
|
27
|
-
// SHOULD CHECK IF USER IS AUTHENTICATED? If not what to do?
|
|
28
|
-
// WHAT TO DO IF USER IS NOT AUTHENTICATED AND ENTERED DIRECTLY TO THE ROUTE OF STEP UP?
|
|
29
|
-
|
|
30
|
-
return useCallback(options => {
|
|
31
|
-
// SSR handling?
|
|
32
|
-
|
|
33
|
-
// A hack because of double calls to useEffect.
|
|
34
|
-
// It keeps us also when there is a usage of multiple HOCs on the same page -> multiple calls to stepUp
|
|
35
|
-
// TODO no window for SSR - what to do?
|
|
36
|
-
if (window.location.search.indexOf(STEP_UP_REDIRECT_URL_QUERY_PARAM) !== -1) return;
|
|
37
|
-
redirectByStepUpUrl(stepUpUrl, onRedirectTo, options == null ? void 0 : options.maxAge);
|
|
38
|
-
}, [stepUpUrl, onRedirectTo]);
|
|
39
|
-
};
|
|
40
|
-
const ACR_VALUE = 'http://schemas.openid.net/pape/policies/2007/06/multi-factor';
|
|
41
|
-
const AMR_MFA_VALUE = 'mfa';
|
|
42
|
-
const AMR_ADDITIONAL_VALUE = ['otp', 'sms', 'hwk'];
|
|
43
|
-
export const useIsSteppedUp = () => {
|
|
44
|
-
// only if don't have amr acr ?? max age???
|
|
45
|
-
const {
|
|
46
|
-
amr = [],
|
|
47
|
-
acr = ''
|
|
48
|
-
} = useAuth(({
|
|
49
|
-
user
|
|
50
|
-
}) => user || {});
|
|
51
|
-
const isACRValid = acr === ACR_VALUE;
|
|
52
|
-
const isAMRIncludesMFA = amr.indexOf(AMR_MFA_VALUE) !== -1;
|
|
53
|
-
const isAMRIncludesMethod = AMR_ADDITIONAL_VALUE.find(method => amr.indexOf(method)) !== undefined;
|
|
54
|
-
return isACRValid && isAMRIncludesMFA && isAMRIncludesMethod;
|
|
55
|
-
};
|
package/node/auth/stepUp.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useStepUpActions = exports.useStepUp = exports.useIsSteppedUp = exports.redirectByStepUpUrl = exports.getMaxAgeFromQueryParam = void 0;
|
|
7
|
-
exports.useStepUpState = useStepUpState;
|
|
8
|
-
var _reduxStore = require("@frontegg/redux-store");
|
|
9
|
-
var _hooks = require("./hooks");
|
|
10
|
-
var _react = require("react");
|
|
11
|
-
const defaultMapper = state => state;
|
|
12
|
-
const STEP_UP_MAX_AGE_PARAM_NAME = 'maxAge';
|
|
13
|
-
function useStepUpState(stateMapper = defaultMapper) {
|
|
14
|
-
return (0, _hooks.stateHookGenerator)(stateMapper, 'stepUpState');
|
|
15
|
-
}
|
|
16
|
-
const useStepUpActions = () => (0, _hooks.reducerActionsGenerator)(_reduxStore.stepUpActions, _reduxStore.stepUpReducers);
|
|
17
|
-
exports.useStepUpActions = useStepUpActions;
|
|
18
|
-
const redirectByStepUpUrl = (stepUpUrl, onRedirectTo, maxAge) => {
|
|
19
|
-
const encodedRedirectUrl = encodeURIComponent(window.location.pathname + window.location.search);
|
|
20
|
-
onRedirectTo(`${stepUpUrl}?${_reduxStore.STEP_UP_REDIRECT_URL_QUERY_PARAM}=${encodedRedirectUrl}&${STEP_UP_MAX_AGE_PARAM_NAME}=${maxAge}`, {
|
|
21
|
-
refresh: false
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
exports.redirectByStepUpUrl = redirectByStepUpUrl;
|
|
25
|
-
const getMaxAgeFromQueryParam = () => {
|
|
26
|
-
const str = (0, _reduxStore.getQueryParam)(STEP_UP_MAX_AGE_PARAM_NAME);
|
|
27
|
-
return str === null ? null : +str;
|
|
28
|
-
};
|
|
29
|
-
exports.getMaxAgeFromQueryParam = getMaxAgeFromQueryParam;
|
|
30
|
-
const useStepUp = () => {
|
|
31
|
-
// also custom url?
|
|
32
|
-
const {
|
|
33
|
-
stepUpUrl
|
|
34
|
-
} = (0, _hooks.useAuthRoutes)();
|
|
35
|
-
const onRedirectTo = (0, _hooks.useOnRedirectTo)();
|
|
36
|
-
|
|
37
|
-
// SHOULD CHECK IF USER IS AUTHENTICATED? If not what to do?
|
|
38
|
-
// WHAT TO DO IF USER IS NOT AUTHENTICATED AND ENTERED DIRECTLY TO THE ROUTE OF STEP UP?
|
|
39
|
-
|
|
40
|
-
return (0, _react.useCallback)(options => {
|
|
41
|
-
// SSR handling?
|
|
42
|
-
|
|
43
|
-
// A hack because of double calls to useEffect.
|
|
44
|
-
// It keeps us also when there is a usage of multiple HOCs on the same page -> multiple calls to stepUp
|
|
45
|
-
// TODO no window for SSR - what to do?
|
|
46
|
-
if (window.location.search.indexOf(_reduxStore.STEP_UP_REDIRECT_URL_QUERY_PARAM) !== -1) return;
|
|
47
|
-
redirectByStepUpUrl(stepUpUrl, onRedirectTo, options == null ? void 0 : options.maxAge);
|
|
48
|
-
}, [stepUpUrl, onRedirectTo]);
|
|
49
|
-
};
|
|
50
|
-
exports.useStepUp = useStepUp;
|
|
51
|
-
const ACR_VALUE = 'http://schemas.openid.net/pape/policies/2007/06/multi-factor';
|
|
52
|
-
const AMR_MFA_VALUE = 'mfa';
|
|
53
|
-
const AMR_ADDITIONAL_VALUE = ['otp', 'sms', 'hwk'];
|
|
54
|
-
const useIsSteppedUp = () => {
|
|
55
|
-
// only if don't have amr acr ?? max age???
|
|
56
|
-
const {
|
|
57
|
-
amr = [],
|
|
58
|
-
acr = ''
|
|
59
|
-
} = (0, _hooks.useAuth)(({
|
|
60
|
-
user
|
|
61
|
-
}) => user || {});
|
|
62
|
-
const isACRValid = acr === ACR_VALUE;
|
|
63
|
-
const isAMRIncludesMFA = amr.indexOf(AMR_MFA_VALUE) !== -1;
|
|
64
|
-
const isAMRIncludesMethod = AMR_ADDITIONAL_VALUE.find(method => amr.indexOf(method)) !== undefined;
|
|
65
|
-
return isACRValid && isAMRIncludesMFA && isAMRIncludesMethod;
|
|
66
|
-
};
|
|
67
|
-
exports.useIsSteppedUp = useIsSteppedUp;
|