mirror of
				https://github.com/elyby/accounts.git
				synced 2025-05-31 14:11:46 +05:30 
			
		
		
		
	Все действия, связанные с аккаунтами, теперь вызываются через url `/api/v1/accounts/<id>/<action>`. Добавлена вменяемая система разграничения прав на основе RBAC. Теперь oAuth2 токены генерируются как случайная строка в 40 символов длинной, а не UUID. Исправлен баг с неправильным временем жизни токена в ответе успешного запроса аутентификации. Теперь все unit тесты можно успешно прогнать без наличия интернета.
		
			
				
	
	
		
			61 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			61 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| namespace api\components\User;
 | |
| 
 | |
| use common\models\Account;
 | |
| use common\models\AccountSession;
 | |
| use Emarref\Jwt\Claim\Expiration;
 | |
| 
 | |
| class AuthenticationResult {
 | |
| 
 | |
|     /**
 | |
|      * @var Account
 | |
|      */
 | |
|     private $account;
 | |
| 
 | |
|     /**
 | |
|      * @var string
 | |
|      */
 | |
|     private $jwt;
 | |
| 
 | |
|     /**
 | |
|      * @var AccountSession|null
 | |
|      */
 | |
|     private $session;
 | |
| 
 | |
|     public function __construct(Account $account, string $jwt, ?AccountSession $session) {
 | |
|         $this->account = $account;
 | |
|         $this->jwt = $jwt;
 | |
|         $this->session = $session;
 | |
|     }
 | |
| 
 | |
|     public function getAccount(): Account {
 | |
|         return $this->account;
 | |
|     }
 | |
| 
 | |
|     public function getJwt(): string {
 | |
|         return $this->jwt;
 | |
|     }
 | |
| 
 | |
|     public function getSession(): ?AccountSession {
 | |
|         return $this->session;
 | |
|     }
 | |
| 
 | |
|     public function getAsResponse() {
 | |
|         $token = (new Jwt())->deserialize($this->getJwt());
 | |
| 
 | |
|         /** @noinspection NullPointerExceptionInspection */
 | |
|         $response = [
 | |
|             'access_token' => $this->getJwt(),
 | |
|             'expires_in' => $token->getPayload()->findClaimByName(Expiration::NAME)->getValue() - time(),
 | |
|         ];
 | |
| 
 | |
|         $session = $this->getSession();
 | |
|         if ($session !== null) {
 | |
|             $response['refresh_token'] = $session->refresh_token;
 | |
|         }
 | |
| 
 | |
|         return $response;
 | |
|     }
 | |
| 
 | |
| }
 |