Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Add signal to re-use access token retrieved on login #49

Merged
merged 1 commit into from
Jan 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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