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:
@@ -4,32 +4,33 @@ namespace common\models;
|
||||
use common\components\Annotations\Reader;
|
||||
use ReflectionClass;
|
||||
use Yii;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
class OauthScope {
|
||||
|
||||
/**
|
||||
* @owner user
|
||||
*/
|
||||
const OFFLINE_ACCESS = 'offline_access';
|
||||
/**
|
||||
* @owner user
|
||||
*/
|
||||
const MINECRAFT_SERVER_SESSION = 'minecraft_server_session';
|
||||
/**
|
||||
* @owner user
|
||||
*/
|
||||
const ACCOUNT_INFO = 'account_info';
|
||||
/**
|
||||
* @owner user
|
||||
*/
|
||||
const ACCOUNT_EMAIL = 'account_email';
|
||||
|
||||
/** @internal */
|
||||
/**
|
||||
* @internal
|
||||
* @owner machine
|
||||
*/
|
||||
const ACCOUNT_BLOCK = 'account_block';
|
||||
|
||||
public static function getScopes(): array {
|
||||
return ArrayHelper::getColumn(static::queryScopes(), 'value');
|
||||
}
|
||||
|
||||
public static function getPublicScopes(): array {
|
||||
return ArrayHelper::getColumn(array_filter(static::queryScopes(), function($value) {
|
||||
return !isset($value['internal']);
|
||||
}), 'value');
|
||||
}
|
||||
|
||||
public static function getInternalScopes(): array {
|
||||
return ArrayHelper::getColumn(array_filter(static::queryScopes(), function($value) {
|
||||
return isset($value['internal']);
|
||||
}), 'value');
|
||||
public static function find(): OauthScopeQuery {
|
||||
return new OauthScopeQuery(static::queryScopes());
|
||||
}
|
||||
|
||||
private static function queryScopes(): array {
|
||||
@@ -43,12 +44,12 @@ class OauthScope {
|
||||
foreach ($constants as $constName => $value) {
|
||||
$annotations = $reader->getConstantAnnotations(static::class, $constName);
|
||||
$isInternal = $annotations->get('internal', false);
|
||||
$owner = $annotations->get('owner', 'user');
|
||||
$keyValue = [
|
||||
'value' => $value,
|
||||
'internal' => $isInternal,
|
||||
'owner' => $owner,
|
||||
];
|
||||
if ($isInternal) {
|
||||
$keyValue['internal'] = true;
|
||||
}
|
||||
$scopes[$constName] = $keyValue;
|
||||
}
|
||||
|
||||
|
50
common/models/OauthScopeQuery.php
Normal file
50
common/models/OauthScopeQuery.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
namespace common\models;
|
||||
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
class OauthScopeQuery {
|
||||
|
||||
private $scopes;
|
||||
|
||||
private $internal;
|
||||
|
||||
private $owner;
|
||||
|
||||
public function onlyPublic(): self {
|
||||
$this->internal = false;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function onlyInternal(): self {
|
||||
$this->internal = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function usersScopes(): self {
|
||||
$this->owner = 'user';
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function machineScopes(): self {
|
||||
$this->owner = 'machine';
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function all(): array {
|
||||
return ArrayHelper::getColumn(array_filter($this->scopes, function($value) {
|
||||
$shouldCheckInternal = $this->internal !== null;
|
||||
$isInternalMatch = $value['internal'] === $this->internal;
|
||||
$shouldCheckOwner = $this->owner !== null;
|
||||
$isOwnerMatch = $value['owner'] === $this->owner;
|
||||
|
||||
return (!$shouldCheckInternal || $isInternalMatch)
|
||||
&& (!$shouldCheckOwner || $isOwnerMatch);
|
||||
}), 'value');
|
||||
}
|
||||
|
||||
public function __construct(array $scopes) {
|
||||
$this->scopes = $scopes;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user