Формируем время в DateTime для генерации JWT токенов

This commit is contained in:
ErickSkrauch
2016-11-04 12:23:04 +03:00
parent 203d9c9fb4
commit c324ebe1c6
3 changed files with 23 additions and 8 deletions

View File

@@ -1,6 +1,8 @@
<?php
namespace api\components\User;
use DateInterval;
use DateTime;
use Yii;
use yii\web\IdentityInterface;
@@ -33,9 +35,12 @@ class RenewResult {
/** @var Component $component */
$component = Yii::$app->user;
$now = new DateTime();
$expiresIn = (clone $now)->add(new DateInterval($component->expirationTimeout));
return [
'access_token' => $this->getJwt(),
'expires_in' => $component->expirationTimeout,
'expires_in' => $expiresIn->getTimestamp() - $now->getTimestamp(),
];
}