Scope.php in OAuth2 Server 7
File
lib/Drupal/oauth2_server/Scope.php
View source
<?php
namespace Drupal\oauth2_server;
use OAuth2\ScopeInterface;
use Oauth2\RequestInterface;
class Scope implements ScopeInterface {
private $server;
public function __construct($server) {
$this->server = $server;
}
function checkScope($required_scope, $available_scope) {
$required_scope = explode(' ', trim($required_scope));
$available_scope = explode(' ', trim($available_scope));
return count(array_diff($required_scope, $available_scope)) == 0;
}
function scopeExists($scope, $client_id = null) {
$scope = explode(' ', trim($scope));
$query = new \EntityFieldQuery();
$query
->entityCondition('entity_type', 'oauth2_server_scope');
$query
->propertyCondition('server', $this->server->name);
$query
->propertyCondition('name', $scope);
$query
->addTag('oauth2_server_scope_access');
$query
->addMetaData('oauth2_server', $this->server);
$results = $query
->execute();
if ($results) {
$scope_ids = array_keys($results['oauth2_server_scope']);
$loaded_scopes = entity_load('oauth2_server_scope', $scope_ids);
$found_scope = array();
foreach ($loaded_scopes as $loaded_scope) {
$found_scope[] = $loaded_scope->name;
}
return count(array_diff($scope, $found_scope)) == 0;
}
return FALSE;
}
public function getScopeFromRequest(RequestInterface $request) {
return $request
->request('scope', $request
->query('scope'));
}
public function getDefaultScope($client_id = NULL) {
foreach (module_implements('oauth2_server_default_scope') as $module) {
$function = $module . '_' . 'oauth2_server_default_scope';
$args = array(
$this->server,
);
$result = call_user_func_array($function, $args);
if (is_array($result)) {
return implode(' ', $result);
}
}
$default_scope = $this->server->settings['default_scope'];
if (!empty($default_scope) && oauth2_server_scope_load($this->server->name, $default_scope)) {
return $default_scope;
}
return FALSE;
}
}
Classes
Name |
Description |
Scope |
Provides a scope-checking utility to the library. |