mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Replace emarref/jwt with lcobucci/jwt
Refactor all JWT-related components Replace RS256 with ES256 as a preferred JWT algorithm
This commit is contained in:
26
api/components/User/IdentityFactory.php
Normal file
26
api/components/User/IdentityFactory.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user