2016-08-04 03:37:21 +05:30
|
|
|
<?php
|
|
|
|
namespace api\components\ApiUser;
|
|
|
|
|
2016-11-30 14:49:10 +05:30
|
|
|
use Yii;
|
2016-08-04 03:37:21 +05:30
|
|
|
use yii\rbac\CheckAccessInterface;
|
|
|
|
|
|
|
|
class AuthChecker implements CheckAccessInterface {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public function checkAccess($token, $permissionName, $params = []) : bool {
|
2016-11-30 14:49:10 +05:30
|
|
|
$accessToken = Yii::$app->oauth->getAuthServer()->getAccessTokenStorage()->get($token);
|
2016-08-04 03:37:21 +05:30
|
|
|
if ($accessToken === null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-30 14:49:10 +05:30
|
|
|
return $accessToken->hasScope($permissionName);
|
2016-08-04 03:37:21 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|