Replace emarref/jwt with lcobucci/jwt

Refactor all JWT-related components
Replace RS256 with ES256 as a preferred JWT algorithm
This commit is contained in:
ErickSkrauch
2019-08-01 12:17:12 +03:00
parent 4c2a9cc172
commit 45c2ed601d
47 changed files with 805 additions and 621 deletions

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace api\models\authentication;
use api\aop\annotations\CollectModelMetrics;
use api\components\Tokens\TokensFactory;
use api\models\base\ApiForm;
use api\validators\EmailActivationKeyValidator;
use common\helpers\Error as E;
@ -38,12 +39,10 @@ class RecoverPasswordForm extends ApiForm {
/**
* @CollectModelMetrics(prefix="authentication.recoverPassword")
* @return \api\components\User\AuthenticationResult|bool
* @throws \Throwable
*/
public function recoverPassword() {
public function recoverPassword(): ?AuthenticationResult {
if (!$this->validate()) {
return false;
return null;
}
$transaction = Yii::$app->db->beginTransaction();
@ -52,16 +51,16 @@ class RecoverPasswordForm extends ApiForm {
$confirmModel = $this->key;
$account = $confirmModel->account;
$account->password = $this->newPassword;
/** @noinspection PhpUnhandledExceptionInspection */
Assert::notSame($confirmModel->delete(), false, 'Unable remove activation key.');
Assert::true($account->save(), 'Unable activate user account.');
$token = Yii::$app->user->createJwtAuthenticationToken($account);
$jwt = Yii::$app->user->serializeToken($token);
$token = TokensFactory::createForAccount($account);
$transaction->commit();
return new \api\components\User\AuthenticationResult($account, $jwt, null);
return new AuthenticationResult($token);
}
}