authelia/client/src/containers/views/AuthenticationView/AuthenticationView.ts
Clement Michaud 828f565290 Bootstrap Go implementation of Authelia.
This is going to be the v4.

Expected improvements:
- More reliable due to static typing.
- Bump of performance.
- Improvement of logging.
- Authelia can be shipped as a single binary.
- Will likely work on ARM architecture.
2019-10-28 23:28:59 +01:00

48 lines
1.7 KiB
TypeScript

import { connect } from 'react-redux';
import QueryString from 'query-string';
import AuthenticationView, {StateProps, Stage, OwnProps} from '../../../views/AuthenticationView/AuthenticationView';
import { RootState } from '../../../reducers';
import { Dispatch } from 'redux';
import AuthenticationLevel from '../../../types/AuthenticationLevel';
import FetchStateBehavior from '../../../behaviors/FetchStateBehavior';
function authenticationLevelToStage(level: AuthenticationLevel): Stage {
switch (level) {
case AuthenticationLevel.NOT_AUTHENTICATED:
return Stage.FIRST_FACTOR;
case AuthenticationLevel.ONE_FACTOR:
return Stage.SECOND_FACTOR;
case AuthenticationLevel.TWO_FACTOR:
return Stage.ALREADY_AUTHENTICATED;
}
}
const mapStateToProps = (state: RootState, ownProps: OwnProps): StateProps => {
const stage = (state.authentication.remoteState)
? authenticationLevelToStage(state.authentication.remoteState.authentication_level)
: Stage.FIRST_FACTOR;
let url: string | null = null;
if (ownProps.location) {
const params = QueryString.parse(ownProps.location.search);
if ('rd' in params) {
url = params['rd'] as string;
} else if (state.authentication.remoteState && state.authentication.remoteState.default_redirection_url) {
url = state.authentication.remoteState.default_redirection_url;
}
}
return {
redirectionUrl: url,
remoteState: state.authentication.remoteState,
stage: stage,
};
}
const mapDispatchToProps = (dispatch: Dispatch) => {
return {
onInit: async () => await FetchStateBehavior(dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(AuthenticationView);