mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
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.
48 lines
1.7 KiB
TypeScript
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); |