mirror of
https://github.com/elyby/accounts.git
synced 2024-12-27 07:30:18 +05:30
79bbc12206
Добавлен client_credentials grant для oAuth Рефакторинг структуры OauthScopes чтобы можно было разделить владельца прав на пользовательские и общие (машинные) Исправлена стилистика кода, внедряются фишки PHP 7.1
51 lines
1.2 KiB
PHP
51 lines
1.2 KiB
PHP
<?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;
|
|
}
|
|
|
|
}
|