aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/bshaffer/oauth2-server-php/src/OAuth2/Scope.php
diff options
context:
space:
mode:
authorKlaus Weidenbach <Klaus.Weidenbach@gmx.net>2017-03-20 00:34:20 +0100
committerKlaus Weidenbach <Klaus.Weidenbach@gmx.net>2017-03-20 00:43:09 +0100
commit8b4b1350369714a832588c74df3f261b538ec566 (patch)
tree5aca6c06d787bea810dfe0c4736834109fa67e09 /vendor/bshaffer/oauth2-server-php/src/OAuth2/Scope.php
parentd2c971eda99fadb7515fb1e1ea4bd645a52513bd (diff)
downloadvolse-hubzilla-8b4b1350369714a832588c74df3f261b538ec566.tar.gz
volse-hubzilla-8b4b1350369714a832588c74df3f261b538ec566.tar.bz2
volse-hubzilla-8b4b1350369714a832588c74df3f261b538ec566.zip
:arrow_up: Update bshaffer/oauth2-server-php library.
Manage oauth2-server-php library with composer. Folder ./library/oauth2/ can be removed and includes removed with autoloading.
Diffstat (limited to 'vendor/bshaffer/oauth2-server-php/src/OAuth2/Scope.php')
-rw-r--r--vendor/bshaffer/oauth2-server-php/src/OAuth2/Scope.php103
1 files changed, 103 insertions, 0 deletions
diff --git a/vendor/bshaffer/oauth2-server-php/src/OAuth2/Scope.php b/vendor/bshaffer/oauth2-server-php/src/OAuth2/Scope.php
new file mode 100644
index 000000000..c44350bfd
--- /dev/null
+++ b/vendor/bshaffer/oauth2-server-php/src/OAuth2/Scope.php
@@ -0,0 +1,103 @@
+<?php
+
+namespace OAuth2;
+
+use OAuth2\Storage\Memory;
+use OAuth2\Storage\ScopeInterface as ScopeStorageInterface;
+
+/**
+* @see OAuth2\ScopeInterface
+*/
+class Scope implements ScopeInterface
+{
+ protected $storage;
+
+ /**
+ * @param mixed @storage
+ * Either an array of supported scopes, or an instance of OAuth2\Storage\ScopeInterface
+ */
+ public function __construct($storage = null)
+ {
+ if (is_null($storage) || is_array($storage)) {
+ $storage = new Memory((array) $storage);
+ }
+
+ if (!$storage instanceof ScopeStorageInterface) {
+ throw new \InvalidArgumentException("Argument 1 to OAuth2\Scope must be null, an array, or instance of OAuth2\Storage\ScopeInterface");
+ }
+
+ $this->storage = $storage;
+ }
+
+ /**
+ * Check if everything in required scope is contained in available scope.
+ *
+ * @param $required_scope
+ * A space-separated string of scopes.
+ *
+ * @return
+ * TRUE if everything in required scope is contained in available scope,
+ * and FALSE if it isn't.
+ *
+ * @see http://tools.ietf.org/html/rfc6749#section-7
+ *
+ * @ingroup oauth2_section_7
+ */
+ public 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);
+ }
+
+ /**
+ * Check if the provided scope exists in storage.
+ *
+ * @param $scope
+ * A space-separated string of scopes.
+ *
+ * @return
+ * TRUE if it exists, FALSE otherwise.
+ */
+ public function scopeExists($scope)
+ {
+ // Check reserved scopes first.
+ $scope = explode(' ', trim($scope));
+ $reservedScope = $this->getReservedScopes();
+ $nonReservedScopes = array_diff($scope, $reservedScope);
+ if (count($nonReservedScopes) == 0) {
+ return true;
+ } else {
+ // Check the storage for non-reserved scopes.
+ $nonReservedScopes = implode(' ', $nonReservedScopes);
+
+ return $this->storage->scopeExists($nonReservedScopes);
+ }
+ }
+
+ public function getScopeFromRequest(RequestInterface $request)
+ {
+ // "scope" is valid if passed in either POST or QUERY
+ return $request->request('scope', $request->query('scope'));
+ }
+
+ public function getDefaultScope($client_id = null)
+ {
+ return $this->storage->getDefaultScope($client_id);
+ }
+
+ /**
+ * Get reserved scopes needed by the server.
+ *
+ * In case OpenID Connect is used, these scopes must include:
+ * 'openid', offline_access'.
+ *
+ * @return
+ * An array of reserved scopes.
+ */
+ public function getReservedScopes()
+ {
+ return array('openid', 'offline_access');
+ }
+}