Skip to content

Commit

Permalink
[FEATURE] Add signal to re-use access token retrieved on login (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
j-schumann authored Jan 4, 2021
1 parent b85475c commit f472772
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion Classes/Service/AuthenticationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@

namespace Causal\Oidc\Service;

use Causal\Oidc\Service\OAuthService;
use League\OAuth2\Client\Token\AccessToken;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\EndTimeRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\StartTimeRestriction;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\HttpUtility;
use Causal\Oidc\Service\OAuthService;
use TYPO3\CMS\Core\Utility\RootlineUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;

/**
Expand Down Expand Up @@ -100,6 +102,15 @@ public function getUser()
$user = $this->authenticateWithResourceOwnerPasswordCredentials($username, $password);
}

// dispatch a signal (containing the user with his access token if auth was successful)
// so other extensions can use them to make further requests to an API
// provided by the authentication server
$dispatcher = GeneralUtility::makeInstance(ObjectManager::class)->get(Dispatcher::class);
$dispatcher->dispatch(__CLASS__, 'getUser', ['user' => $user]);
if (is_array($user)) {
unset($user['accessToken']);
}

return $user;
}

Expand Down Expand Up @@ -132,6 +143,10 @@ protected function authenticateWithAuhorizationCode($code)
}

$user = $this->getUserFromAccessToken($service, $accessToken);
if (is_array($user)) {
$user['accessToken'] = $accessToken;
}

return $user;
}

Expand Down Expand Up @@ -170,6 +185,10 @@ protected function authenticateWithResourceOwnerPasswordCredentials($username, $
]);
}

if (is_array($user)) {
$user['accessToken'] = $accessToken;
}

return $user;
}

Expand Down

0 comments on commit f472772

Please sign in to comment.