-
Notifications
You must be signed in to change notification settings - Fork 149
/
AuthenticationCallback.js
65 lines (55 loc) · 1.75 KB
/
AuthenticationCallback.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import * as React from 'react';
import { CallbackComponent } from 'redux-oidc';
import { withRouter, getUserManager, oidcLog } from '@axa-fr/react-oidc-core';
import { compose, withProps, pure } from 'recompose';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
const propTypes = {
history: PropTypes.object.isRequired,
userManager: PropTypes.object.isRequired,
callbackComponentOverride: PropTypes.elementType,
};
const defaultProps = {
callbackComponentOverride: null,
};
export const success = oidcLogInjected => history => user => {
if (user && user.state) {
history.push(user.state.url);
} else {
oidcLogInjected.error('urlBeforeSignin is null or undefined');
}
};
const AuthenticationCallback = ({
history,
userManager,
callbackComponentOverride: CallbackComponentOverride,
}) => {
const successCallback = user => success(oidcLog)(history)(user);
const errorCallback = error => {
const { message } = error;
oidcLog.error(`There was an error handling the token callback: ${message}`);
history.push(`/authentication/not-authenticated?message=${message}`);
};
return (
<CallbackComponent
userManager={userManager}
errorCallback={errorCallback}
successCallback={successCallback}
>
{CallbackComponentOverride ? (
<CallbackComponentOverride />
) : (
<p>Authentification en cours vous allez être redirigé.</p>
)}
</CallbackComponent>
);
};
AuthenticationCallback.propTypes = propTypes;
AuthenticationCallback.defaultProps = defaultProps;
const wrapUserManager = () => ({ userManager: getUserManager() });
const enhance = compose(
withRouter,
withProps(wrapUserManager),
connect()
);
export default pure(enhance(AuthenticationCallback));