2016-05-31 03:33:30 +05:30
|
|
|
<?php
|
|
|
|
namespace api\components\User;
|
|
|
|
|
2016-11-04 14:53:04 +05:30
|
|
|
use DateInterval;
|
|
|
|
use DateTime;
|
2016-05-31 03:33:30 +05:30
|
|
|
use Yii;
|
|
|
|
use yii\web\IdentityInterface;
|
|
|
|
|
|
|
|
class RenewResult {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var IdentityInterface
|
|
|
|
*/
|
|
|
|
private $identity;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $jwt;
|
|
|
|
|
|
|
|
public function __construct(IdentityInterface $identity, string $jwt) {
|
|
|
|
$this->identity = $identity;
|
|
|
|
$this->jwt = $jwt;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getIdentity() : IdentityInterface {
|
|
|
|
return $this->identity;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getJwt() : string {
|
|
|
|
return $this->jwt;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAsResponse() {
|
|
|
|
/** @var Component $component */
|
|
|
|
$component = Yii::$app->user;
|
|
|
|
|
2016-11-04 14:53:04 +05:30
|
|
|
$now = new DateTime();
|
|
|
|
$expiresIn = (clone $now)->add(new DateInterval($component->expirationTimeout));
|
|
|
|
|
2016-05-31 03:33:30 +05:30
|
|
|
return [
|
|
|
|
'access_token' => $this->getJwt(),
|
2016-11-04 14:53:04 +05:30
|
|
|
'expires_in' => $expiresIn->getTimestamp() - $now->getTimestamp(),
|
2016-05-31 03:33:30 +05:30
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|