mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Rework identity provider for the legacy OAuth2 tokens [skip ci]
This commit is contained in:
@@ -8,19 +8,24 @@ use yii\web\UnauthorizedHttpException;
|
||||
class IdentityFactory {
|
||||
|
||||
/**
|
||||
* @throws UnauthorizedHttpException
|
||||
* @param string $token
|
||||
* @param string $type
|
||||
*
|
||||
* @return IdentityInterface
|
||||
* @throws UnauthorizedHttpException
|
||||
*/
|
||||
public static function findIdentityByAccessToken($token, $type = null): IdentityInterface {
|
||||
if (empty($token)) {
|
||||
throw new UnauthorizedHttpException('Incorrect token');
|
||||
if (!empty($token)) {
|
||||
if (mb_strlen($token) === 40) {
|
||||
return LegacyOAuth2Identity::findIdentityByAccessToken($token, $type);
|
||||
}
|
||||
|
||||
if (substr_count($token, '.') === 2) {
|
||||
return JwtIdentity::findIdentityByAccessToken($token, $type);
|
||||
}
|
||||
}
|
||||
|
||||
if (substr_count($token, '.') === 2) {
|
||||
return JwtIdentity::findIdentityByAccessToken($token, $type);
|
||||
}
|
||||
|
||||
return OAuth2Identity::findIdentityByAccessToken($token, $type);
|
||||
throw new UnauthorizedHttpException('Incorrect token');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user