mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-16 10:18:55 +05:30
Added league/event and implemented SessionOwnerEvent
This commit is contained in:
parent
33c68a2103
commit
954f29f879
@ -5,7 +5,8 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.4.0",
|
"php": ">=5.4.0",
|
||||||
"symfony/http-foundation": "~2.1"
|
"symfony/http-foundation": "~2.1",
|
||||||
|
"league/event": "0.1"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "~4.0",
|
"phpunit/phpunit": "~4.0",
|
||||||
|
@ -14,6 +14,7 @@ namespace League\OAuth2\Server;
|
|||||||
use League\OAuth2\Server\Exception;
|
use League\OAuth2\Server\Exception;
|
||||||
use League\OAuth2\Server\TokenType\TokenTypeInterface;
|
use League\OAuth2\Server\TokenType\TokenTypeInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use League\Event\Emitter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OAuth 2.0 Resource Server
|
* OAuth 2.0 Resource Server
|
||||||
@ -40,6 +41,37 @@ abstract class AbstractServer
|
|||||||
*/
|
*/
|
||||||
protected $tokenType;
|
protected $tokenType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event emitter
|
||||||
|
*/
|
||||||
|
protected $eventEmitter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract server constructor
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->eventEmitter = $this->setEventEmitter();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the Request Object
|
* Sets the Request Object
|
||||||
* @param \Symfony\Component\HttpFoundation\Request The Request Object
|
* @param \Symfony\Component\HttpFoundation\Request The Request Object
|
||||||
|
@ -80,6 +80,8 @@ class AuthorizationServer extends AbstractServer
|
|||||||
// Set Bearer as the default token type
|
// Set Bearer as the default token type
|
||||||
$this->setTokenType(new Bearer);
|
$this->setTokenType(new Bearer);
|
||||||
|
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,6 +228,8 @@ class SessionEntity
|
|||||||
$this->ownerType = $type;
|
$this->ownerType = $type;
|
||||||
$this->ownerId = $id;
|
$this->ownerId = $id;
|
||||||
|
|
||||||
|
$this->server->eventEmitter->emit(new Event\SessionOwnerEvent($this));
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
51
src/Event/SessionOwnerEvent.php
Normal file
51
src/Event/SessionOwnerEvent.php
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* OAuth 2.0 session owner event
|
||||||
|
*
|
||||||
|
* @package league/oauth2-server
|
||||||
|
* @author Alex Bilbie <hello@alexbilbie.com>
|
||||||
|
* @copyright Copyright (c) Alex Bilbie
|
||||||
|
* @license http://mit-license.org/
|
||||||
|
* @link https://github.com/thephpleague/oauth2-server
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace League\OAuth2\Server\Event;
|
||||||
|
|
||||||
|
use League\Event\EventAbstract;
|
||||||
|
use League\OAuth2\Server\Entity\SessionEntity;
|
||||||
|
|
||||||
|
class SessionOwnerEvent extends EventAbstract
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Session entity
|
||||||
|
* @var \League\OAuth2\Server\Entity\SessionEntity
|
||||||
|
*/
|
||||||
|
private $session;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init the event with a session
|
||||||
|
* @param \League\OAuth2\Server\Entity\SessionEntity $session
|
||||||
|
*/
|
||||||
|
public function __construct(SessionEntity $session)
|
||||||
|
{
|
||||||
|
$this->session = $session;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the event
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return 'session.owner';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return session
|
||||||
|
* @return \League\OAuth2\Server\Entity\SessionEntity
|
||||||
|
*/
|
||||||
|
public function getSession()
|
||||||
|
{
|
||||||
|
return $this->session;
|
||||||
|
}
|
||||||
|
}
|
@ -66,6 +66,8 @@ class ResourceServer extends AbstractServer
|
|||||||
// Set Bearer as the default token type
|
// Set Bearer as the default token type
|
||||||
$this->setTokenType(new Bearer);
|
$this->setTokenType(new Bearer);
|
||||||
|
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user