2014-01-10 23:00:12 +05:30
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* OAuth 2.0 Abstract Server
|
|
|
|
*
|
|
|
|
* @package league/oauth2-server
|
|
|
|
* @author Alex Bilbie <hello@alexbilbie.com>
|
2014-03-10 01:04:23 +05:30
|
|
|
* @copyright Copyright (c) Alex Bilbie
|
2014-01-10 23:00:12 +05:30
|
|
|
* @license http://mit-license.org/
|
2014-03-10 01:35:38 +05:30
|
|
|
* @link https://github.com/thephpleague/oauth2-server
|
2014-01-10 23:00:12 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
namespace League\OAuth2\Server;
|
|
|
|
|
2014-11-08 23:56:12 +05:30
|
|
|
use League\Event\Emitter;
|
2014-11-07 07:50:06 +05:30
|
|
|
use League\OAuth2\Server\Storage\AccessTokenInterface;
|
|
|
|
use League\OAuth2\Server\Storage\AuthCodeInterface;
|
|
|
|
use League\OAuth2\Server\Storage\ClientInterface;
|
2014-11-08 23:56:12 +05:30
|
|
|
use League\OAuth2\Server\Storage\RefreshTokenInterface;
|
|
|
|
use League\OAuth2\Server\Storage\ScopeInterface;
|
|
|
|
use League\OAuth2\Server\Storage\SessionInterface;
|
|
|
|
use League\OAuth2\Server\TokenType\TokenTypeInterface;
|
2014-01-10 23:00:12 +05:30
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* OAuth 2.0 Resource Server
|
|
|
|
*/
|
|
|
|
|
|
|
|
abstract class AbstractServer
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The request object
|
|
|
|
*
|
2014-11-07 06:16:02 +05:30
|
|
|
* @var \Symfony\Component\HttpFoundation\Request
|
2014-01-10 23:00:12 +05:30
|
|
|
*/
|
|
|
|
protected $request;
|
|
|
|
|
|
|
|
/**
|
2014-11-07 07:50:06 +05:30
|
|
|
* Session storage
|
|
|
|
* @var \League\OAuth2\Server\Storage\SessionInterface
|
2014-01-10 23:00:12 +05:30
|
|
|
*/
|
2014-11-07 07:50:06 +05:30
|
|
|
protected $sessionStorage;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Access token storage
|
|
|
|
* @var \League\OAuth2\Server\Storage\AccessTokenInterface
|
|
|
|
*/
|
|
|
|
protected $accessTokenStorage;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Refresh token storage
|
|
|
|
* @var \League\OAuth2\Server\Storage\RefreshTokenInterface
|
|
|
|
*/
|
|
|
|
protected $refreshTokenStorage;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Auth code storage
|
|
|
|
* @var \League\OAuth2\Server\Storage\AuthCodeInterface
|
|
|
|
*/
|
|
|
|
protected $authCodeStorage;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scope storage
|
|
|
|
* @var \League\OAuth2\Server\Storage\ScopeInterface
|
|
|
|
*/
|
|
|
|
protected $scopeStorage;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Client storage
|
|
|
|
* @var \League\OAuth2\Server\Storage\ClientInterface
|
|
|
|
*/
|
|
|
|
protected $clientStorage;
|
2014-01-10 23:00:12 +05:30
|
|
|
|
2014-04-23 21:32:50 +05:30
|
|
|
/**
|
|
|
|
* Token type
|
2014-11-07 06:16:02 +05:30
|
|
|
* @var \League\OAuth2\Server\TokenType\TokenTypeInterface
|
2014-04-23 21:32:50 +05:30
|
|
|
*/
|
|
|
|
protected $tokenType;
|
|
|
|
|
2014-07-11 19:43:28 +05:30
|
|
|
/**
|
|
|
|
* Event emitter
|
2014-11-07 06:16:02 +05:30
|
|
|
* @var \League\Event\Emitter
|
2014-07-11 19:43:28 +05:30
|
|
|
*/
|
|
|
|
protected $eventEmitter;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract server constructor
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
2014-07-11 22:48:41 +05:30
|
|
|
$this->setEventEmitter();
|
2014-07-11 19:43:28 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set an event emitter
|
|
|
|
* @param object $emitter Event emitter object
|
|
|
|
*/
|
|
|
|
public function setEventEmitter($emitter = null)
|
|
|
|
{
|
|
|
|
if ($emitter === null) {
|
2014-11-08 23:56:12 +05:30
|
|
|
$this->eventEmitter = new Emitter();
|
2014-07-11 19:43:28 +05:30
|
|
|
} else {
|
|
|
|
$this->eventEmitter = $emitter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-07 06:16:02 +05:30
|
|
|
/**
|
|
|
|
* Add an event listener to the event emitter
|
|
|
|
* @param string $eventName Event name
|
|
|
|
* @param callable $listener Callable function or method
|
|
|
|
*/
|
2014-07-11 19:43:28 +05:30
|
|
|
public function addEventListener($eventName, callable $listener)
|
|
|
|
{
|
|
|
|
$this->eventEmitter->addListener($eventName, $listener);
|
|
|
|
}
|
|
|
|
|
2014-11-07 06:16:02 +05:30
|
|
|
/**
|
|
|
|
* Returns the event emitter
|
|
|
|
* @return \League\Event\Emitter
|
|
|
|
*/
|
2014-07-11 22:48:41 +05:30
|
|
|
public function getEventEmitter()
|
|
|
|
{
|
|
|
|
return $this->eventEmitter;
|
|
|
|
}
|
|
|
|
|
2014-01-10 23:00:12 +05:30
|
|
|
/**
|
|
|
|
* Sets the Request Object
|
|
|
|
* @param \Symfony\Component\HttpFoundation\Request The Request Object
|
|
|
|
* @return self
|
|
|
|
*/
|
2014-09-22 11:26:15 +05:30
|
|
|
public function setRequest($request)
|
2014-01-10 23:00:12 +05:30
|
|
|
{
|
|
|
|
$this->request = $request;
|
2014-05-03 15:23:43 +05:30
|
|
|
|
2014-01-10 23:00:12 +05:30
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the Request object. It will create one from the globals if one is not set.
|
|
|
|
* @return \Symfony\Component\HttpFoundation\Request
|
|
|
|
*/
|
|
|
|
public function getRequest()
|
|
|
|
{
|
|
|
|
if ($this->request === null) {
|
2014-05-02 19:44:25 +05:30
|
|
|
$this->request = Request::createFromGlobals();
|
2014-01-10 23:00:12 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
return $this->request;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-11-07 07:50:06 +05:30
|
|
|
* Set the client storage
|
|
|
|
* @param \League\OAuth2\Server\Storage\ClientInterface $storage
|
|
|
|
* @return self
|
2014-01-10 23:00:12 +05:30
|
|
|
*/
|
2014-11-07 07:50:06 +05:30
|
|
|
public function setClientStorage(ClientInterface $storage)
|
2014-01-10 23:00:12 +05:30
|
|
|
{
|
2014-11-07 07:50:06 +05:30
|
|
|
$storage->setServer($this);
|
|
|
|
$this->clientStorage = $storage;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the session storage
|
|
|
|
* @param \League\OAuth2\Server\Storage\SessionInterface $storage
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
public function setSessionStorage(SessionInterface $storage)
|
|
|
|
{
|
|
|
|
$storage->setServer($this);
|
|
|
|
$this->sessionStorage = $storage;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the access token storage
|
|
|
|
* @param \League\OAuth2\Server\Storage\AccessTokenInterface $storage
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
public function setAccessTokenStorage(AccessTokenInterface $storage)
|
|
|
|
{
|
|
|
|
$storage->setServer($this);
|
|
|
|
$this->accessTokenStorage = $storage;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the refresh token storage
|
|
|
|
* @param \League\OAuth2\Server\Storage\RefreshTokenInteface $storage
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
public function setRefreshTokenStorage(RefreshTokenInterface $storage)
|
|
|
|
{
|
|
|
|
$storage->setServer($this);
|
|
|
|
$this->refreshTokenStorage = $storage;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2014-05-03 15:23:43 +05:30
|
|
|
|
2014-11-07 07:50:06 +05:30
|
|
|
/**
|
|
|
|
* Set the auth code storage
|
|
|
|
* @param \League\OAuth2\Server\Storage\AuthCodeInterface $authCode
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
public function setAuthCodeStorage(AuthCodeInterface $storage)
|
|
|
|
{
|
|
|
|
$storage->setServer($this);
|
|
|
|
$this->authCodeStorage = $storage;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the scope storage
|
|
|
|
* @param \League\OAuth2\Server\Storage\ScopeInterface $storage
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
public function setScopeStorage(ScopeInterface $storage)
|
|
|
|
{
|
|
|
|
$storage->setServer($this);
|
|
|
|
$this->scopeStorage = $storage;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the client storage
|
|
|
|
* @return \League\OAuth2\Server\Storage\ClientInterface
|
|
|
|
*/
|
|
|
|
public function getClientStorage()
|
|
|
|
{
|
|
|
|
return $this->clientStorage;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the scope storage
|
|
|
|
* @return \League\OAuth2\Server\Storage\ScopeInterface
|
|
|
|
*/
|
|
|
|
public function getScopeStorage()
|
|
|
|
{
|
|
|
|
return $this->scopeStorage;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the session storage
|
|
|
|
* @return \League\OAuth2\Server\Storage\SessionInterface
|
|
|
|
*/
|
|
|
|
public function getSessionStorage()
|
|
|
|
{
|
|
|
|
return $this->sessionStorage;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the refresh token storage
|
|
|
|
* @return \League\OAuth2\Server\Storage\RefreshTokenInterface
|
|
|
|
*/
|
|
|
|
public function getRefreshTokenStorage()
|
|
|
|
{
|
|
|
|
return $this->refreshTokenStorage;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the access token storage
|
|
|
|
* @return \League\OAuth2\Server\Storage\AccessTokenInterface
|
|
|
|
*/
|
|
|
|
public function getAccessTokenStorage()
|
|
|
|
{
|
|
|
|
return $this->accessTokenStorage;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the auth code storage
|
|
|
|
* @return \League\OAuth2\Server\Storage\AuthCodeInterface
|
|
|
|
*/
|
|
|
|
public function getAuthCodeStorage()
|
|
|
|
{
|
|
|
|
return $this->authCodeStorage;
|
2014-01-10 23:00:12 +05:30
|
|
|
}
|
2014-04-23 21:32:50 +05:30
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the access token type
|
|
|
|
* @param TokenTypeInterface $tokenType The token type
|
|
|
|
* @return void
|
|
|
|
*/
|
2014-09-09 18:06:20 +05:30
|
|
|
public function setTokenType(TokenTypeInterface $tokenType)
|
2014-04-23 21:32:50 +05:30
|
|
|
{
|
2014-10-01 02:56:34 +05:30
|
|
|
$tokenType->setServer($this);
|
2014-04-23 21:32:50 +05:30
|
|
|
$this->tokenType = $tokenType;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the access token type
|
|
|
|
* @return TokenTypeInterface
|
|
|
|
*/
|
2014-07-11 22:57:03 +05:30
|
|
|
public function getTokenType()
|
2014-04-23 21:32:50 +05:30
|
|
|
{
|
|
|
|
return $this->tokenType;
|
|
|
|
}
|
2014-05-03 15:23:43 +05:30
|
|
|
}
|