From 9e5bd4cd6763fea2cfff6031f648e946dc41d661 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Mon, 16 Dec 2013 23:47:53 +0000 Subject: [PATCH] First commit of Session --- src/League/OAuth2/Server/Session.php | 134 +++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 src/League/OAuth2/Server/Session.php diff --git a/src/League/OAuth2/Server/Session.php b/src/League/OAuth2/Server/Session.php new file mode 100644 index 00000000..bf7b0063 --- /dev/null +++ b/src/League/OAuth2/Server/Session.php @@ -0,0 +1,134 @@ +storage = $storage; + $this->scopes = new ParameterBag(); + } + + public function associateScope($scope) + { + if (!$this->scopes->has($scope)) { + $this->scopes->set($scope, 1); + } + + return $this; + } + + public function hasScope($scope) + { + return $this->scopes->has($scope); + } + + public function associateAccessToken(AccessToken $accessToken) + { + $this->accessToken = $accessToken; + } + + public function associateRefreshToken(RefreshToken $refreshToken) + { + $this->refreshToken = $refreshToken; + } + + public function associateAuthCode(AuthCode $authCode) + { + $this->authCode = $authCode; + } + + /** + * Associate a client + * @param League\OAuth2\Server\Client $client The client + * @return self + */ + public function associateClient(Client $client) + { + $this->client = $client; + + return $this; + } + + /** + * Set client + * @param League\OAuth2\Server\Client + */ + public function setClient(Client $client) + { + $this->client = $client; + } + + /** + * Return client + * @return League\OAuth2\Server\Client + */ + public function getClient() + { + return $this->client; + } + + /** + * Set the session owner + * @param string $type The type of the owner (e.g. user, app) + * @param string $id The ID of the owner + * @return self + */ + public function setOwner($type, $id) + { + $this->ownerType = $type; + $this->ownerId = $id; + + return $this; + } + + public function getOwnerId() + { + return $this->ownerId; + } + + public function getOwnerType() + { + return $this->ownerType; + } + + public function getById($id) + { + $params = $this->storage->getSession($id); + + if ($params === null) { + throw new OAuth2Exception('Unrecognised session ID - ' . $id); + } + + $this->id = $params['session_id']; + $this->setOwner($params['owner_type'], $params['owner_id']); + } +}