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-04-23 21:32:50 +05:30
|
|
|
use League\OAuth2\Server\Exception;
|
|
|
|
use League\OAuth2\Server\TokenType\TokenTypeInterface;
|
2014-01-10 23:00:12 +05:30
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
2014-07-11 19:43:28 +05:30
|
|
|
use League\Event\Emitter;
|
2014-01-10 23:00:12 +05:30
|
|
|
|
|
|
|
/**
|
|
|
|
* OAuth 2.0 Resource Server
|
|
|
|
*/
|
|
|
|
|
|
|
|
abstract class AbstractServer
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The request object
|
|
|
|
*
|
|
|
|
* @var Util\RequestInterface
|
|
|
|
*/
|
|
|
|
protected $request;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Storage classes
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $storages = [];
|
|
|
|
|
2014-04-23 21:32:50 +05:30
|
|
|
/**
|
|
|
|
* Token type
|
|
|
|
* @var TokenTypeInterface
|
|
|
|
*/
|
|
|
|
protected $tokenType;
|
|
|
|
|
2014-07-11 19:43:28 +05:30
|
|
|
/**
|
|
|
|
* Event emitter
|
|
|
|
*/
|
|
|
|
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) {
|
|
|
|
$this->eventEmitter = new Emitter;
|
|
|
|
} else {
|
|
|
|
$this->eventEmitter = $emitter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addEventListener($eventName, callable $listener)
|
|
|
|
{
|
|
|
|
$this->eventEmitter->addListener($eventName, $listener);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
public function setRequest(Request $request)
|
|
|
|
{
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a storage class
|
2014-05-03 15:23:43 +05:30
|
|
|
* @param string $obj The class required
|
2014-01-10 23:00:12 +05:30
|
|
|
* @return Storage\ClientInterface|Storage\ScopeInterface|Storage\SessionInterface
|
|
|
|
*/
|
|
|
|
public function getStorage($obj)
|
|
|
|
{
|
|
|
|
if (!isset($this->storages[$obj])) {
|
2014-04-25 15:54:42 +05:30
|
|
|
throw new Exception\ServerErrorException(
|
2014-01-16 22:20:16 +05:30
|
|
|
'The `'.$obj.'` storage interface has not been registered with the server'
|
2014-01-10 23:00:12 +05:30
|
|
|
);
|
|
|
|
}
|
2014-05-03 15:23:43 +05:30
|
|
|
|
2014-01-10 23:00:12 +05:30
|
|
|
return $this->storages[$obj];
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
$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
|
|
|
}
|