mirror of
https://github.com/elyby/accounts.git
synced 2024-11-10 07:22:00 +05:30
27 lines
637 B
PHP
27 lines
637 B
PHP
|
<?php
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace api\components\User;
|
||
|
|
||
|
use yii\web\UnauthorizedHttpException;
|
||
|
|
||
|
class IdentityFactory {
|
||
|
|
||
|
/**
|
||
|
* @throws UnauthorizedHttpException
|
||
|
* @return IdentityInterface
|
||
|
*/
|
||
|
public static function findIdentityByAccessToken($token, $type = null): IdentityInterface {
|
||
|
if (empty($token)) {
|
||
|
throw new UnauthorizedHttpException('Incorrect token');
|
||
|
}
|
||
|
|
||
|
if (substr_count($token, '.') === 2) {
|
||
|
return JwtIdentity::findIdentityByAccessToken($token, $type);
|
||
|
}
|
||
|
|
||
|
return Oauth2Identity::findIdentityByAccessToken($token, $type);
|
||
|
}
|
||
|
|
||
|
}
|