/** * {@inheritdoc} */ public function associateScope(AccessTokenEntity $token, ScopeEntity $scope) { $query = $this->db->createQueryBuilder()->insert('oauth_access_token_scopes')->values(['access_token' => ':token', 'scope' => ':scope']); $query->createNamedParameter($token->getId(), \PDO::PARAM_STR, ':token'); $query->createNamedParameter($scope->getId(), \PDO::PARAM_STR, ':scope'); $query->execute(); }
/** * {@inheritdoc} */ public function associateScope(AccessTokenEntity $token, ScopeEntity $scope) { $key = RedisUtil::prefix($token->getId(), 'oauth_access_token_scopes'); if (!isset($this->cache[$key])) { $this->cache[$key] = []; } $value = ['id' => $scope->getId()]; array_push($this->cache[$key], $value); RedisCapsule::sadd($key, RedisUtil::prepare($value)); }
/** * {@inheritdoc} */ public function associateScope(AccessTokenEntity $token, ScopeEntity $scopeEntity) { /** @var AccessToken $accessToken */ $accessToken = $this->dm->getRepository(AccessToken::class)->find($token->getId()); /** @var Scope $scope */ $scope = $this->dm->getRepository(Scope::class)->find($scopeEntity->getId()); $accessToken->associateScope($scope); $this->dm->persist($accessToken); $this->dm->flush($accessToken); }
/** * {@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 testAssociateScope() { $redis = $this->prophesize("Corley\\OAuth2\\Server\\Storage\\Redis\\RedisMock"); $redis->lpush("access_token:scopes:access_token_id", "scope_id:desc")->shouldBeCalledTimes(1)->willReturn(null); $server = $this->prophesize("League\\OAuth2\\Server\\AbstractServer"); $server->getEventEmitter()->willReturn(new Emitter()); $accessTokenStorage = new AccessTokenStorage($redis->reveal()); $accessTokenStorage->setServer($server->reveal()); $accessToken = new AccessTokenEntity($server->reveal()); $accessToken->setId("access_token_id"); $scope = new ScopeEntity($server->reveal()); $scope->hydrate(["id" => "scope_id", "description" => "desc"]); $accessTokenStorage->associateScope($accessToken, $scope); }
/** * Associate a scope with an acess token * * @param \League\OAuth2\Server\Entity\AccessTokenEntity $token The access token * @param \League\OAuth2\Server\Entity\ScopeEntity $scope The scope * * @return bool * @throws OAuthException */ public function associateScope(AccessTokenEntity $token, ScopeEntity $scope) { $accessTokenScope = new AccessTokenScope(); $accessTokenScope->setAttribute("access_token", $token->getId()); $accessTokenScope->setAttribute("scope", $scope->getId()); $saved = $accessTokenScope->save(); if ($saved) { return $saved; } else { throw new OAuthException(json_encode($accessTokenScope->errors)); } }
/** * {@inheritdoc} */ public function associateScope(AccessTokenEntity $token, ScopeEntity $scope) { $this->loadModel('OAuthServer.AccessTokenScopes'); $tokenScope = $this->AccessTokenScopes->newEntity(['oauth_token' => $token->getId(), 'scope_id' => $scope->getId()]); $this->AccessTokenScopes->save($tokenScope); }
/** * {@inheritdoc} */ public function associateScope(AuthCodeEntity $token, ScopeEntity $scope) { $this->getConnection()->table('oauth_auth_code_scopes')->insert(['auth_code' => $token->getId(), 'scope' => $scope->getId()]); }
public function associateScope(SessionEntity $session, ScopeEntity $scope) { $this->redis->lpush("session:scopes:{$session->getId()}", "{$scope->getId()}:{$scope->getDescription()}"); }
public function associateScope(AccessTokenEntity $token, ScopeEntity $scope) { $this->redis->lpush("access_token:scopes:{$token}", "{$scope->getId()}:{$scope->getDescription()}"); }
public function associateScope(SessionEntity $session, ScopeEntity $scope) { $sql = 'INSERT INTO oauth_access_token_scopes' . ' (access_token_id, scope_id)' . ' VALUES' . ' (?, ?);'; $this->db->execute($sql, [$session->getId(), $scope->getId()]); }
/** * Associate a scope with a session in Redis storage. * * @param \League\OAuth2\Server\Entity\SessionEntity $session * @param \League\OAuth2\Server\Entity\ScopeEntity $scope * @return void */ public function associateScope(SessionEntity $session, ScopeEntity $scope) { $this->pushSet($session->getId(), 'oauth_session_scopes', ['id' => $scope->getId()]); }
/** * {@inheritdoc} */ public function associateScope(SessionEntity $session, ScopeEntity $scope) { $this->getConnection()->table('oauth_session_scopes')->insert(['session_id' => $session->getId(), 'scope' => $scope->getId()]); }
/** * Associate a scope * * @param \League\OAuth2\Server\Entity\ScopeEntity $scope * * @return self */ public function associateScope(ScopeEntity $scope) { if (!isset($this->scopes[$scope->getId()])) { $this->scopes[$scope->getId()] = $scope; } return $this; }
/** * {@inheritdoc} */ public function associateScope(AuthCodeEntity $token, ScopeEntity $scope) { Capsule::table('oauth_auth_code_scopes')->insert(['auth_code' => $token->getId(), 'scope' => $scope->getId()]); }
/** * {@inheritdoc} * * @param \League\OAuth2\Server\Entity\SessionEntity $session Session entity * @param \League\OAuth2\Server\Entity\ScopeEntity $scope Scope entity * @return void */ public function associateScope(SessionEntity $session, ScopeEntity $scope) { $this->loadModel('OAuthServer.SessionScopes'); $sessionScope = $this->SessionScopes->newEntity(['session_id' => $session->getId(), 'scope_id' => $scope->getId()]); $this->SessionScopes->save($sessionScope); }
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); }
/** * {@inheritdoc} */ public function associateScope(AccessTokenEntity $token, ScopeEntity $scope) { M('oauth_access_token_scopes')->add(array('access_token' => $token->getId(), 'scope' => $scope->getId())); }
/** * Associate a scope with a session * * @param \League\OAuth2\Server\Entity\SessionEntity $session The session * @param \League\OAuth2\Server\Entity\ScopeEntity $scope The scope * * @return null|string * @throws OAuthException */ public function associateScope(SessionEntity $session, ScopeEntity $scope) { $sessionScopesStorage = new SessionScopesStorage(); $sessionScopesStorage->setAttribute("session_id", $session->getId()); $sessionScopesStorage->setAttribute("scope", $scope->getId()); if ($sessionScopesStorage->save()) { return $sessionScopesStorage->getPrimaryKey(); } else { throw new OAuthException(json_encode($sessionScopesStorage->errors)); } }
/** * {@inheritdoc} */ public function associateScope(SessionEntity $session, ScopeEntity $scope) { Capsule::table('oauth_session_scopes')->insert(['session_id' => $session->getId(), 'scope' => $scope->getId()]); }
/** * Associate a scope with an acess token * * @param AuthCodeEntity $token * @param ScopeEntity $scope * @return void */ public function associateScope(AuthCodeEntity $token, ScopeEntity $scope) { $this->db->table('oauth_auth_code_scopes')->insert(['auth_code_id' => $token->getId(), 'scope_id' => $scope->getId(), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]); }
/** * Associate a scope with an authorization code in Redis storage. * * @param \League\OAuth2\Server\Entity\AuthCodeEntity $code * @param \League\OAuth2\Server\Entity\ScopeEntity $scope * @return void */ public function associateScope(AuthCodeEntity $code, ScopeEntity $scope) { $this->pushSet($code->getId(), 'oauth_auth_code_scopes', ['id' => $scope->getId()]); }
/** * {@inheritdoc} */ public function associateScope(AccessTokenEntity $token, ScopeEntity $scope) { Capsule::table('oauth_access_token_scopes')->insert(['access_token' => $token->getId(), 'scope' => $scope->getId()]); }
/** * Associate a scope with a session * * @param SessionEntity $session * @param ScopeEntity $scope * @return void */ public function associateScope(SessionEntity $session, ScopeEntity $scope) { $this->db->table('oauth_session_scopes')->insert(['session_id' => $session->getId(), 'scope_id' => $scope->getId(), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]); }
/** * {@inheritdoc} */ public function associateScope(AuthCodeEntity $token, ScopeEntity $scope) { $this->loadModel('OAuthServer.AuthCodeScopes'); $codeScope = $this->AuthCodeScopes->newEntity(['auth_code' => $token->getId(), 'scope_id' => $scope->getId()]); $this->AuthCodeScopes->save($codeScope); }
/** * Associate a scope with an access token in Redis storage. * * @param \League\OAuth2\Server\Entity\AbstractTokenEntity $token * @param \League\OAuth2\Server\Entity\ScopeEntity $scope * @return void */ public function associateScope(AbstractTokenEntity $token, ScopeEntity $scope) { $this->pushSet($token->getToken(), 'oauth_access_token_scopes', ['id' => $scope->getId()]); }
/** * {@inheritdoc} */ public function associateScope(AccessTokenEntity $token, ScopeEntity $scope) { $this->getConnection()->table('oauth_access_token_scopes')->insert(['access_token_id' => $token->getId(), 'scope_id' => $scope->getId(), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]); }
/** * Associate a scope with an acess token * * @param \League\OAuth2\Server\Entity\AccessTokenEntity $token The access token * @param \League\OAuth2\Server\Entity\ScopeEntity $scope The scope * * @return void */ public function associateScope(AccessTokenEntity $token, ScopeEntity $scope) { $this->getEntityManager()->getConnection()->insert('oauth_access_token_scope', ['access_token' => $token->getId(), 'scope' => $scope->getId()]); }