Implementation of the backend for the OAuth2 clients management

This commit is contained in:
ErickSkrauch
2018-02-28 01:27:35 +03:00
parent ddec87e3a9
commit 673429e577
55 changed files with 1810 additions and 65 deletions

View File

@ -18,14 +18,12 @@ class ClientStorage extends AbstractStorage implements ClientInterface {
* @inheritdoc
*/
public function get($clientId, $clientSecret = null, $redirectUri = null, $grantType = null) {
$query = OauthClient::find()->andWhere(['id' => $clientId]);
if ($clientSecret !== null) {
$query->andWhere(['secret' => $clientSecret]);
$model = $this->findClient($clientId);
if ($model === null) {
return null;
}
/** @var OauthClient|null $model */
$model = $query->one();
if ($model === null) {
if ($clientSecret !== null && $clientSecret !== $model->secret) {
return null;
}
@ -60,8 +58,7 @@ class ClientStorage extends AbstractStorage implements ClientInterface {
throw new \ErrorException('This module assumes that $session typeof ' . SessionEntity::class);
}
/** @var OauthClient|null $model */
$model = OauthClient::findOne($session->getClientId());
$model = $this->findClient($session->getClientId());
if ($model === null) {
return null;
}
@ -80,4 +77,8 @@ class ClientStorage extends AbstractStorage implements ClientInterface {
return $entity;
}
private function findClient(string $clientId): ?OauthClient {
return OauthClient::findOne($clientId);
}
}