mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Объединены сущности для авторизации посредством JWT токенов и токенов, выданных через oAuth2.
Все действия, связанные с аккаунтами, теперь вызываются через url `/api/v1/accounts/<id>/<action>`. Добавлена вменяемая система разграничения прав на основе RBAC. Теперь oAuth2 токены генерируются как случайная строка в 40 символов длинной, а не UUID. Исправлен баг с неправильным временем жизни токена в ответе успешного запроса аутентификации. Теперь все unit тесты можно успешно прогнать без наличия интернета.
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
namespace api\models\authentication;
|
||||
|
||||
use api\models\AccountIdentity;
|
||||
use api\models\base\ApiForm;
|
||||
use api\models\profile\ChangeUsernameForm;
|
||||
use api\modules\accounts\models\ChangeUsernameForm;
|
||||
use api\validators\EmailActivationKeyValidator;
|
||||
use common\models\Account;
|
||||
use common\models\EmailActivation;
|
||||
@@ -14,14 +13,14 @@ class ConfirmEmailForm extends ApiForm {
|
||||
|
||||
public $key;
|
||||
|
||||
public function rules() {
|
||||
public function rules(): array {
|
||||
return [
|
||||
['key', EmailActivationKeyValidator::class, 'type' => EmailActivation::TYPE_REGISTRATION_EMAIL_CONFIRMATION],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \api\components\User\LoginResult|bool
|
||||
* @return \api\components\User\AuthenticationResult|bool
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function confirm() {
|
||||
@@ -48,7 +47,7 @@ class ConfirmEmailForm extends ApiForm {
|
||||
|
||||
$transaction->commit();
|
||||
|
||||
return Yii::$app->user->login(new AccountIdentity($account->attributes), true);
|
||||
return Yii::$app->user->createJwtAuthenticationToken($account, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -101,7 +101,7 @@ class ForgotPasswordForm extends ApiForm {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getLogin() {
|
||||
public function getLogin(): string {
|
||||
return $this->login;
|
||||
}
|
||||
|
||||
|
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace api\models\authentication;
|
||||
|
||||
use api\models\AccountIdentity;
|
||||
use api\models\base\ApiForm;
|
||||
use api\validators\TotpValidator;
|
||||
use common\helpers\Error as E;
|
||||
@@ -9,9 +8,6 @@ use api\traits\AccountFinder;
|
||||
use common\models\Account;
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* @method AccountIdentity|null getAccount()
|
||||
*/
|
||||
class LoginForm extends ApiForm {
|
||||
use AccountFinder;
|
||||
|
||||
@@ -86,12 +82,12 @@ class LoginForm extends ApiForm {
|
||||
}
|
||||
}
|
||||
|
||||
public function getLogin() {
|
||||
public function getLogin(): string {
|
||||
return $this->login;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \api\components\User\LoginResult|bool
|
||||
* @return \api\components\User\AuthenticationResult|bool
|
||||
*/
|
||||
public function login() {
|
||||
if (!$this->validate()) {
|
||||
@@ -104,11 +100,7 @@ class LoginForm extends ApiForm {
|
||||
$account->save();
|
||||
}
|
||||
|
||||
return Yii::$app->user->login($account, $this->rememberMe);
|
||||
}
|
||||
|
||||
protected function getAccountClassName() {
|
||||
return AccountIdentity::class;
|
||||
return Yii::$app->user->createJwtAuthenticationToken($account, $this->rememberMe);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace api\models\authentication;
|
||||
|
||||
use api\models\AccountIdentity;
|
||||
use api\models\base\ApiForm;
|
||||
use api\validators\EmailActivationKeyValidator;
|
||||
use common\helpers\Error as E;
|
||||
@@ -37,7 +36,7 @@ class RecoverPasswordForm extends ApiForm {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \api\components\User\LoginResult|bool
|
||||
* @return \api\components\User\AuthenticationResult|bool
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function recoverPassword() {
|
||||
@@ -61,7 +60,7 @@ class RecoverPasswordForm extends ApiForm {
|
||||
|
||||
$transaction->commit();
|
||||
|
||||
return Yii::$app->user->login(new AccountIdentity($account->attributes), false);
|
||||
return Yii::$app->user->createJwtAuthenticationToken($account, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ class RefreshTokenForm extends ApiForm {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \api\components\User\RenewResult|bool
|
||||
* @return \api\components\User\AuthenticationResult|bool
|
||||
*/
|
||||
public function renew() {
|
||||
if (!$this->validate()) {
|
||||
@@ -42,7 +42,7 @@ class RefreshTokenForm extends ApiForm {
|
||||
/** @var \api\components\User\Component $component */
|
||||
$component = Yii::$app->user;
|
||||
|
||||
return $component->renew($this->getSession());
|
||||
return $component->renewJwtAuthenticationToken($this->getSession());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user