mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-17 02:29:46 +05:30
Fixing Resource bugs and moving the Request dep to a setter.
This commit is contained in:
parent
373ddf9f34
commit
2fecadd2a6
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace OAuth2;
|
namespace OAuth2;
|
||||||
|
|
||||||
class MissingAccessTokenException
|
class MissingAccessTokenException extends \Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
namespace OAuth2;
|
namespace OAuth2;
|
||||||
|
|
||||||
use OutOfBoundsException;
|
use OutOfBoundsException;
|
||||||
use Storage\SessionInterface;
|
use OAuth2\Storage\SessionInterface;
|
||||||
use Storage\SessionScopeInterface;
|
use OAuth2\Storage\SessionScopeInterface;
|
||||||
|
|
||||||
class Resource
|
class Resource
|
||||||
{
|
{
|
||||||
@ -29,19 +29,37 @@ class Resource
|
|||||||
*
|
*
|
||||||
* @param SessionInterface The Session Storage Object
|
* @param SessionInterface The Session Storage Object
|
||||||
* @param SessionScopeInterface The Session Scope Storage Object
|
* @param SessionScopeInterface The Session Scope Storage Object
|
||||||
* @param RequestInterface The Request Object
|
|
||||||
*/
|
*/
|
||||||
public function __construct(SessionInterface $session, SessionScopeInterface $session_scope, RequestInterface $request = null)
|
public function __construct(SessionInterface $session, SessionScopeInterface $session_scope)
|
||||||
{
|
{
|
||||||
$this->storages['session'] = $session;
|
$this->storages['session'] = $session;
|
||||||
$this->storages['session_scope'] = $session_scope;
|
$this->storages['session_scope'] = $session_scope;
|
||||||
|
|
||||||
if (is_null($request)) {
|
|
||||||
$request = Request::buildFromGlobals();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the Request Object
|
||||||
|
*
|
||||||
|
* @param RequestInterface The Request Object
|
||||||
|
*/
|
||||||
|
public function setRequest(RequestInterface $request)
|
||||||
|
{
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the Request object. It will create one from the globals if one is not set.
|
||||||
|
*
|
||||||
|
* @return RequestInterface
|
||||||
|
*/
|
||||||
|
public function getRequest()
|
||||||
|
{
|
||||||
|
if ($this->request === null) {
|
||||||
|
$this->request = Request::buildFromGlobals();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->request;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the Access Token is valid or not.
|
* Checks if the Access Token is valid or not.
|
||||||
*
|
*
|
||||||
@ -91,13 +109,19 @@ class Resource
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads in the Access Token from the headers.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @throws MissingAccessTokenException
|
||||||
|
*/
|
||||||
protected function determineAccessToken()
|
protected function determineAccessToken()
|
||||||
{
|
{
|
||||||
if ($header = $this->request->header('Authorization')) {
|
if ($header = $this->getRequest()->header('Authorization')) {
|
||||||
$access_token = trim(str_replace('Bearer', '', $header));
|
$access_token = trim(str_replace('Bearer', '', $header));
|
||||||
} else {
|
} else {
|
||||||
$method = $this->request->server('REQUEST_METHOD');
|
$method = $this->getRequest()->server('REQUEST_METHOD');
|
||||||
$access_token = $this->request->{$method}($this->tokenKey);
|
$access_token = $this->getRequest()->{$method}($this->tokenKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($access_token)) {
|
if (empty($access_token)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user