2019-08-01 14:47:12 +05:30
|
|
|
<?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);
|
|
|
|
}
|
|
|
|
|
2019-08-02 21:02:08 +05:30
|
|
|
return OAuth2Identity::findIdentityByAccessToken($token, $type);
|
2019-08-01 14:47:12 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|