Skip to content

Commit

Permalink
[TASK] Prevent automated logiin of every page load
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Wessels committed Sep 11, 2019
1 parent db460fd commit 8649e77
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 48 deletions.
68 changes: 24 additions & 44 deletions Classes/Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,25 @@ public function initializeAction()
*/
public function formAction()
{
// Get Auth0 user from session storage
// ToDo: User Auth0->getUser() instead.
$sessionStore = new SessionStore();
$userInfo = $sessionStore->get('user');
$feUserAuthentication = $GLOBALS['TSFE']->fe_user;
$redirectService = GeneralUtility::makeInstance(RedirectService::class, $this->settings);

// Redirect when user just logged in (and update him)
if (GeneralUtility::_GP('logintype') === 'login' && $feUserAuthentication->user !== null && $userInfo !== null) {
if (!empty(GeneralUtility::_GP('referrer'))) {
$this->logger->notice('Handle referrer redirect prior to updating user.');
$redirectService->forceRedirectByReferrer(['logintype' => 'login']);
}
if ($feUserAuthentication->user !== null) {
// Get Auth0 user from session storage
// ToDo: User Auth0->getUser() instead.
$sessionStore = new SessionStore();
$userInfo = $sessionStore->get('user');

// Redirect when user just logged in (and update him)
if (GeneralUtility::_GP('logintype') === 'login' && $userInfo !== null) {
if (!empty(GeneralUtility::_GP('referrer'))) {
$this->logger->notice('Handle referrer redirect prior to updating user.');
$redirectService->forceRedirectByReferrer(['logintype' => 'login']);
}

GeneralUtility::makeInstance(UserUtility::class)->updateUser($this->getAuth0(), (int)$this->settings['application']);
$redirectService->handleRedirect(['groupLogin', 'userLogin', 'login', 'getpost', 'referrer']);
GeneralUtility::makeInstance(UserUtility::class)->updateUser($this->getAuth0(), (int)$this->settings['application']);
$redirectService->handleRedirect(['groupLogin', 'userLogin', 'login', 'getpost', 'referrer']);
}
}

// Force redirect due to Auth0 sign up or log in errors
Expand All @@ -92,7 +95,7 @@ public function formAction()
}

$this->view->assignMultiple([
'userInfo' => $userInfo,
'userInfo' => $userInfo ?? null,
'auth0Error' => $this->error,
'auth0ErrorDescription' => $this->errorDescription,
]);
Expand All @@ -110,24 +113,13 @@ public function loginAction()
// ToDo: User Auth0->getUser() instead.
$store = new SessionStore();
$userInfo = $store->get('user');
$feUserAuthentication = $GLOBALS['TSFE']->fe_user;

if ($userInfo === null) {
// Try to login user
$this->logger->notice('Try to login user.');

$_params = ['sessionStore' => $store];

foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['auth0']['login_pre_processing'] ?? [] as $_funcRef) {
if ($_funcRef) {
GeneralUtility::callUserFunction($_funcRef, $_params, $this);
}
}

if ($userInfo === null || $feUserAuthentication->user === null) {
$this->logger->notice('Try to login user to Auth0.');
$this->getAuth0()->login();
}

// Show login form
$this->redirect('form');
}

Expand All @@ -136,36 +128,24 @@ public function loginAction()
* @throws InvalidApplicationException
* @throws StopActionException
* @throws UnsupportedRequestTypeException
* TODO: Write Hook $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_post_processing'] instead (or pre_processing)
*/
public function logoutAction()
{
$_params = [];
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['auth0']['logoff_pre_processing'] ?? [] as $_funcRef) {
if ($_funcRef) {
GeneralUtility::callUserFunction($_funcRef, $_params, $this);
}
}

$this->getAuth0()->logout();

foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['auth0']['logoff_post_processing'] ?? [] as $_funcRef) {
if ($_funcRef) {
GeneralUtility::callUserFunction($_funcRef, $_params, $this);
}
}

$application = GeneralUtility::makeInstance(ApplicationRepository::class)->findByUid((int)$this->settings['application']);
$logoutSettings = $this->settings['frontend']['logout'] ?? [];
$redirectUri = GeneralUtility::makeInstance(RoutingUtility::class)
->setCallback((int)$logoutSettings['targetPageUid'], (int)$logoutSettings['targetPageType'])
->addArgument('logintype', 'logout')
->getUri();

if ((bool)$this->settings['softLogout'] === true) {
$singleLogOut = isset($this->settings['softLogout']) ? !(bool)$this->settings['softLogout'] : (bool)$application['single_log_out'];

if ($singleLogOut === false) {
$this->redirectToUri($redirectUri);
}

$application = GeneralUtility::makeInstance(ApplicationRepository::class)->findByUid((int)$this->settings['application']);
$this->getAuth0()->logout();
$this->logger->notice('Proceed with single log out.');
$logoutUri = $this->getAuth0()->getLogoutUri($redirectUri, $application['id']);

$this->redirectToUri($logoutUri);
Expand Down
6 changes: 2 additions & 4 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,9 @@
'writerConfiguration' => [
\TYPO3\CMS\Core\Log\LogLevel::DEBUG => [
\TYPO3\CMS\Core\Log\Writer\NullWriter::class => []
]
]
],
],
];

$GLOBALS['TYPO3_CONF_VARS']['SVCONF']['auth']['setup']['FE_fetchUserIfNoSession'] = true;

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing']['auth0'] = \Bitmotion\Auth0\Hooks\SingleSignOutHook::class . '->isResponsible';
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_post_processing']['auth0'] = \Bitmotion\Auth0\Hooks\SingleSignOutHook::class . '->performLogout';

0 comments on commit 8649e77

Please sign in to comment.