Cheetah
Scope.php
Go to the documentation of this file.
1 <?php
2 
3 namespace OAuth2;
4 
6 use OAuth2\Storage\ScopeInterface as ScopeStorageInterface;
7 
11 class Scope implements ScopeInterface
12 {
13  protected $storage;
14 
19  public function __construct($storage = null)
20  {
21  if (is_null($storage) || is_array($storage)) {
22  $storage = new Memory((array) $storage);
23  }
24 
25  if (!$storage instanceof ScopeStorageInterface) {
26  throw new \InvalidArgumentException("Argument 1 to OAuth2\Scope must be null, an array, or instance of OAuth2\Storage\ScopeInterface");
27  }
28 
29  $this->storage = $storage;
30  }
31 
46  public function checkScope($required_scope, $available_scope)
47  {
48  $required_scope = explode(' ', trim($required_scope));
49  $available_scope = explode(' ', trim($available_scope));
50 
51  return (count(array_diff($required_scope, $available_scope)) == 0);
52  }
53 
63  public function scopeExists($scope)
64  {
65  // Check reserved scopes first.
66  $scope = explode(' ', trim($scope));
67  $reservedScope = $this->getReservedScopes();
68  $nonReservedScopes = array_diff($scope, $reservedScope);
69  if (count($nonReservedScopes) == 0) {
70  return true;
71  } else {
72  // Check the storage for non-reserved scopes.
73  $nonReservedScopes = implode(' ', $nonReservedScopes);
74 
75  return $this->storage->scopeExists($nonReservedScopes);
76  }
77  }
78 
79  public function getScopeFromRequest(RequestInterface $request)
80  {
81  // "scope" is valid if passed in either POST or QUERY
82  return $request->request('scope', $request->query('scope'));
83  }
84 
85  public function getDefaultScope($client_id = null)
86  {
87  return $this->storage->getDefaultScope($client_id);
88  }
89 
99  public function getReservedScopes()
100  {
101  return array('openid', 'offline_access');
102  }
103 }
OAuth2\ScopeInterface
Definition: ScopeInterface.php:13
OAuth2\RequestInterface\request
request($name, $default=null)
use
GNU LESSER GENERAL PUBLIC LICENSE February Free Software Inc Franklin Fifth MA USA Everyone is permitted to copy and distribute verbatim copies of this license but changing it is not allowed[This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it By the GNU General Public Licenses are intended to guarantee your freedom to share and change free software to make sure the software is free for all its users This the Lesser General Public applies to some specially designated software packages typically libraries of the Free Software Foundation and other authors who decide to use it You can use it but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular based on the explanations below When we speak of free we are referring to freedom of use
Definition: license.txt:27
OAuth2\Scope
Definition: Scope.php:12
OAuth2\Storage\Memory
Definition: Memory.php:26
php
OAuth2\Scope\getDefaultScope
getDefaultScope($client_id=null)
Definition: Scope.php:85
OAuth2\Storage\ScopeInterface
Definition: ScopeInterface.php:13
OAuth2\Scope\__construct
__construct($storage=null)
Definition: Scope.php:19
OAuth2\Scope\scopeExists
scopeExists($scope)
Definition: Scope.php:63
OAuth2\RequestInterface
Definition: RequestInterface.php:6
OAuth2\Scope\getReservedScopes
getReservedScopes()
Definition: Scope.php:99
OAuth2\Scope\$storage
$storage
Definition: Scope.php:13
OAuth2\RequestInterface\query
query($name, $default=null)
OAuth2
Definition: Autoloader.php:3
OAuth2\Scope\checkScope
checkScope($required_scope, $available_scope)
Definition: Scope.php:46
OAuth2\Scope\getScopeFromRequest
getScopeFromRequest(RequestInterface $request)
Definition: Scope.php:79
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10