for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Created by PhpStorm.
* User: GCC-MED
* Date: 15/01/2018
* Time: 09:54
*/
namespace OAuth2\ScopePolicy;
use OAuth2\Config;
use OAuth2\Exceptions\OAuthException;
use OAuth2\Roles\ClientInterface;
use OAuth2\Roles\Clients\RegisteredClient;
class ScopePolicyManager
{
* @var Config
private $config;
* ScopePolicyManager constructor.
* @param Config $config
* @throws \Exception
public function __construct(Config $config)
$this->config = $config;
}
* @param ClientInterface $client
* @return array|null
* @throws OAuthException
public function getDefaultScopes(ClientInterface $client): ?array
return $this->config->getScopePolicy()->getDefaultScopes($client);
* @param array $scopes
public function verifyScopes(ClientInterface $client, ?array $scopes): void
if ($client instanceof RegisteredClient && is_array($client->getMetadata()->getScope())) {
$client instanceof OAuth...Metadata()->getScope())
true
$supportedScopes = explode(' ', $client->getMetadata()->getScope());
if(empty($scopes) || !empty(array_diff($scopes, $supportedScopes))) {
throw new OAuthException('invalid_scope',
'The request scope is invalid. Supported scopes : '.$client->getMetadata()->getScope(),
'https://tools.ietf.org/html/rfc6749#section-4.1');