Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
authenticateUserInternal(usermanager, location)();
}
return () => {
oidcLog.info('Protected component unmounted');
};
}, [location, isEnabled, authenticateUserInternal, getUserManagerInternal]);
return { oidcUser, authenticating, isEnabled };
};
// for usage
export const useReactOidc = () => {
const { isEnabled, login, logout, oidcUser } = useContext(AuthenticationContext);
return { isEnabled, login, logout, oidcUser };
};
const OidcSecure = withRouter(({ children, location }) => {
const { oidcUser, authenticating, isEnabled } = useOidcSecure(
authenticateUser,
getUserManager,
location
);
const requiredAuth = useMemo(() => isRequireAuthentication(oidcUser, false) && isEnabled, [
isEnabled,
oidcUser,
]);
const AuthenticatingComponent = authenticating || Authenticating;
return requiredAuth ? : <div>{children}</div>;
});
export default OidcSecure;
// For non-regression
export const onAccessTokenExpired = (dispatch, userManager) => async () => {
oidcLog.info(`AccessToken Expired `);
dispatch({ type: 'ON_UNLOAD_USER' });
await userManager.signinSilent();
};
useEffect(() => {
oidcLog.info('Protection : ', isEnabled);
if (isEnabled) {
oidcLog.info('Protected component mounted');
const usermanager = getUserManagerInternal();
authenticateUserInternal(usermanager, location)();
}
return () => {
oidcLog.info('Protected component unmounted');
};
}, [location, isEnabled, authenticateUserInternal, getUserManagerInternal]);
return { oidcUser, authenticating, isEnabled };
useEffect(() => {
oidcLog.info('Protection : ', isEnabled);
if (isEnabled) {
oidcLog.info('Protected component mounted');
const usermanager = getUserManagerInternal();
authenticateUserInternal(usermanager, location)();
}
return () => {
oidcLog.info('Protected component unmounted');
};
}, [location, isEnabled, authenticateUserInternal, getUserManagerInternal]);
return { oidcUser, authenticating, isEnabled };
return () => {
oidcLog.info('Protected component unmounted');
};
}, [location, isEnabled, authenticateUserInternal, getUserManagerInternal]);
export const login = (userManager, dispatch, location) => async () => {
dispatch({ type: 'ON_LOADING' });
oidcLog.info('Login requested');
await authenticateUser(userManager, location)();
};
export const logout = (userManager, dispatch) => async () => {
try {
oidcLog.info('Logout successfull');
await logoutUser(userManager);
} catch (error) {
onError(dispatch)(error);
}
};
export const login = (userManager, dispatch, location) => async () => {
]),
}}
>
{children}
);
};
const AuthenticationProvider = withRouter(withServices(AuthenticationProviderInt, { Callback }));
AuthenticationProvider.propTypes = propTypes;
AuthenticationProvider.defaultProps = defaultProps;
AuthenticationProvider.displayName = 'AuthenticationProvider';
export default AuthenticationProvider;
getUserManager: getUserManagerInternal,
oidcLog: oidcLogInternal,
callbackComponentOverride: CallbackComponentOverride,
}) => {
const onSuccess = onRedirectSuccess(history, oidcLogInternal);
const onError = onRedirectError(history, oidcLogInternal);
useEffect(() => {
getUserManagerInternal()
.signinRedirectCallback()
.then(onSuccess, onError);
}, [getUserManagerInternal, onError, onSuccess]);
return CallbackComponentOverride ? : ;
};
const CallbackContainer = withRouter(
withServices(CallbackContainerCore, {
getUserManager,
oidcLog,
})
);
export default React.memo(CallbackContainer);
export const withOidcSecure = WrappedComponent =>
withRouter(
withServices(withOidcSecurewithRouter(WrappedComponent), {
authenticateUser,
getUserManager,
})
);