示例#1
0
 /**
  * {@inheritdoc}
  */
 public function get($scope, $grantType = null, $clientId = null)
 {
     $scope = new ScopeEntity($this->server);
     $scope->hydrate(['id' => 'basic', 'description' => 'Basic details about your account']);
     return $scope;
     // $result = Capsule::table('oauth_scopes')
     //                         ->where('id', $scope)
     //                         ->get();
     // if (count($result) === 0) {
     //     return;
     // }
     // return (new ScopeEntity($this->server))->hydrate([
     //     'id'            =>  $result[0]['id'],
     //     'description'   =>  $result[0]['description'],
     // ]);
 }
 /**
  * Return information about a scope
  *
  * Example SQL query:
  *
  * <code>
  * SELECT * FROM oauth_scopes WHERE scope = :scope
  * </code>
  *
  * @param  string     $scope     The scope
  * @param  string     $grantType The grant type used in the request (default = "null")
  * @param  string     $clientId  The client id used for the request (default = "null")
  * @return \League\OAuth2\Server\Entity\ScopeEntity|null If the scope doesn't exist return false
  */
 public function get($scope, $grantType = null, $clientId = null)
 {
     $query = $this->getConnection()->table('oauth_scopes')->select('oauth_scopes.id as id', 'oauth_scopes.description as description')->where('oauth_scopes.id', $scope);
     if ($this->limitClientsToScopes === true and !is_null($clientId)) {
         $query = $query->join('oauth_client_scopes', 'oauth_scopes.id', '=', 'oauth_client_scopes.scope_id')->where('oauth_client_scopes.client_id', $clientId);
     }
     if ($this->limitScopesToGrants === true and !is_null($grantType)) {
         $query = $query->join('oauth_grant_scopes', 'oauth_scopes.id', '=', 'oauth_grant_scopes.scope_id')->join('oauth_grants', 'oauth_grants.id', '=', 'oauth_grant_scopes.grant_id')->where('oauth_grants.id', $grantType);
     }
     $result = $query->first();
     if (is_null($result)) {
         return null;
     }
     $scope = new ScopeEntity($this->getServer());
     $scope->hydrate(['id' => $result->id, 'description' => $result->description]);
     return $scope;
 }
 /**
  * Return information about a scope
  *
  * Example SQL query:
  *
  * <code>
  * SELECT * FROM oauth_scopes WHERE scope = :scope
  * </code>
  *
  * @param  string     $scope     The scope
  * @param  string     $grantType The grant type used in the request (default = "null")
  * @param  string     $clientId  The client id used for the request (default = "null")
  * @return \League\OAuth2\Server\Entity\ScopeEntity|null If the scope doesn't exist return false
  */
 public function get($scope, $grantType = null, $clientId = null)
 {
     $query = $this->getConnection()->table('oauth_scopes')->where('id', $scope);
     if ($this->limitClientsToScopes === true and !is_null($clientId)) {
         $allowedScopeIds = $this->getConnection()->table('oauth_client_scopes')->where('client_id', $clientId)->pluck('scope_id');
         $query = $query->whereIn('client_id', $allowedScopeIds);
     }
     if ($this->limitScopesToGrants === true and !is_null($grantType)) {
         $allowedGrantIds = $this->getConnection()->table('oauth_grants')->where('id', $grantType)->pluck('id');
         $allowedScopeIds = $this->getConnection()->table('oauth_grant_scopes')->whereIn('grant_id', $allowedGrantIds)->pluck('scope_id');
         $query = $query->whereIn('id', $allowedScopeIds);
     }
     $result = $query->first();
     if (is_null($result)) {
         return null;
     }
     $scope = new ScopeEntity($this->getServer());
     $scope->hydrate(['id' => $result['id'], 'description' => $result['description']]);
     return $scope;
 }
 public function testAssociateScopes()
 {
     $redis = $this->prophesize("Corley\\OAuth2\\Server\\Storage\\Redis\\RedisMock");
     $redis->lpush("auth_code:scopes:auth_code_id", "scope_id:desc")->shouldBeCalledTimes(1);
     $server = $this->prophesize("League\\OAuth2\\Server\\AbstractServer");
     $authCodeStorage = new AuthCodeStorage($redis->reveal());
     $authCodeStorage->setServer($server->reveal());
     $token = new AuthCodeEntity($server->reveal());
     $token->setId("auth_code_id");
     $token->setRedirectUri("http://localhost:8080/");
     $token->setExpireTime(11111);
     $scope = new ScopeEntity($server->reveal());
     $scope->hydrate(["id" => "scope_id", "description" => "desc"]);
     $authCodeStorage->associateScope($token, $scope);
 }
 public function testAssociateScope()
 {
     $redis = $this->prophesize("Corley\\OAuth2\\Server\\Storage\\Redis\\RedisMock");
     $redis->lpush("session:scopes:session_id", "scope_id:desc")->shouldBeCalledTimes(1);
     $server = $this->prophesize("League\\OAuth2\\Server\\AbstractServer");
     $server->getEventEmitter()->willReturn(new Emitter());
     $sessionStorage = new SessionStorage($redis->reveal());
     $sessionStorage->setServer($server->reveal());
     $session = new SessionEntity($server->reveal());
     $session->setId("session_id");
     $scope = new ScopeEntity($server->reveal());
     $scope->hydrate(["id" => "scope_id", "description" => "desc"]);
     $sessionStorage->associateScope($session, $scope);
 }
 /**
  * Return information about a scope.
  *
  * Example SQL query:
  *
  * <code>
  * SELECT * FROM oauth_scopes WHERE scope = :scope
  * </code>
  *
  * @param string $scope     The scope
  * @param string $grantType The grant type used in the request (default = "null")
  * @param string $clientId  The client id used for the request (default = "null")
  *
  * @return \League\OAuth2\Server\Entity\ScopeEntity|null If the scope doesn't exist return false
  */
 public function get($scopeId, $grantType = null, $clientId = null)
 {
     // Get scope
     $scope = $this->getConnection()->table('oauth_scopes')->where(['id' => $scopeId])->first();
     if (is_null($scope)) {
         return;
     }
     if ($this->limitClientsToScopes === true && !is_null($clientId)) {
         // Get client
         $client = $this->getConnection()->table('oauth_clients')->where(['id' => $clientId])->first();
         if (is_null($client)) {
             return;
         }
         // Get client scope
         $clientScope = $this->getConnection()->table('oauth_client_scopes')->where(['client_id' => (string) $client['_id'], 'scope_id' => (string) $scope['_id']])->first();
         if (is_null($clientScope)) {
             return;
         }
     }
     if ($this->limitScopesToGrants === true && !is_null($grantType)) {
         // Get grant
         $grant = $this->getConnection()->table('oauth_grants')->where(['id' => $grantType])->first();
         if (is_null($grant)) {
             return;
         }
         // Get grant scope
         $grantScope = $this->getConnection()->table('oauth_grant_scopes')->where(['grant_id' => (string) $grant['_id'], 'scope_id' => (string) $scope['_id']])->first();
         if (is_null($grantScope)) {
             return;
         }
     }
     $scopeEntity = new ScopeEntity($this->getServer());
     $scopeEntity->hydrate(['id' => $scope['id'], 'description' => $scope['description']]);
     return $scopeEntity;
 }