mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Добавлен контроллер для блокировки аккаунта
Добавлен client_credentials grant для oAuth Рефакторинг структуры OauthScopes чтобы можно было разделить владельца прав на пользовательские и общие (машинные) Исправлена стилистика кода, внедряются фишки PHP 7.1
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
<?php
|
||||
namespace api\components\OAuth2\Storage;
|
||||
|
||||
use api\components\OAuth2\Entities\ClientEntity;
|
||||
use api\components\OAuth2\Entities\ScopeEntity;
|
||||
use common\models\OauthScope;
|
||||
use League\OAuth2\Server\Storage\AbstractStorage;
|
||||
use League\OAuth2\Server\Storage\ScopeInterface;
|
||||
use yii\base\ErrorException;
|
||||
|
||||
class ScopeStorage extends AbstractStorage implements ScopeInterface {
|
||||
|
||||
@@ -12,7 +14,27 @@ class ScopeStorage extends AbstractStorage implements ScopeInterface {
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get($scope, $grantType = null, $clientId = null) {
|
||||
$scopes = $grantType === 'authorization_code' ? OauthScope::getPublicScopes() : OauthScope::getScopes();
|
||||
$query = OauthScope::find();
|
||||
if ($grantType === 'authorization_code') {
|
||||
$query->onlyPublic()->usersScopes();
|
||||
} elseif ($grantType === 'client_credentials') {
|
||||
$query->machineScopes();
|
||||
$isTrusted = false;
|
||||
if ($clientId !== null) {
|
||||
$client = $this->server->getClientStorage()->get($clientId);
|
||||
if (!$client instanceof ClientEntity) {
|
||||
throw new ErrorException('client storage must return instance of ' . ClientEntity::class);
|
||||
}
|
||||
|
||||
$isTrusted = $client->isTrusted();
|
||||
}
|
||||
|
||||
if (!$isTrusted) {
|
||||
$query->onlyPublic();
|
||||
}
|
||||
}
|
||||
|
||||
$scopes = $query->all();
|
||||
if (!in_array($scope, $scopes, true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user