mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-23 13:39:48 +05:30
Started adding some Server methods, adding some Util classes and adding a way to get the token from the Resource
This commit is contained in:
parent
2727ba0078
commit
892ae3a0d3
@ -80,6 +80,16 @@ class Resource
|
||||
return $this->ownerId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Access Token.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAccessToken()
|
||||
{
|
||||
return $this->accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the Access Token is valid or not.
|
||||
*
|
||||
|
@ -16,6 +16,8 @@ class Server
|
||||
|
||||
protected $grantTypes = array();
|
||||
|
||||
protected $request = null;
|
||||
|
||||
public function __construct($storage)
|
||||
{
|
||||
|
||||
@ -29,14 +31,95 @@ class Server
|
||||
$this->grantTypes[$identifier] = $grant_type;
|
||||
}
|
||||
|
||||
public function getScopeDelimeter()
|
||||
{
|
||||
return $this->scopeDelimeter;
|
||||
}
|
||||
|
||||
public function setScopeDelimeter($scope_delimeter)
|
||||
{
|
||||
$this->scopeDelimeter = $scope_delimeter;
|
||||
}
|
||||
|
||||
public function getExpiresIn()
|
||||
{
|
||||
return $this->expiresIn;
|
||||
}
|
||||
|
||||
public function setExpiresIn($expires_in)
|
||||
{
|
||||
$this->expiresIn = $expires_in;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Request Object
|
||||
*
|
||||
* @param RequestInterface The Request Object
|
||||
*/
|
||||
public function setRequest(RequestInterface $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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check client authorise parameters
|
||||
*
|
||||
* @access public
|
||||
* @param array $authParams Optional array of parsed $_GET keys
|
||||
* @return array Authorise request parameters
|
||||
*/
|
||||
public function checkClientAuthoriseParams($authParams = null)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a new authorise request
|
||||
*
|
||||
* @param string $type The session owner's type
|
||||
* @param string $typeId The session owner's ID
|
||||
* @param array $authoriseParams The authorise request $_GET parameters
|
||||
* @return string An authorisation code
|
||||
*/
|
||||
public function newAuthoriseRequest($type, $typeId, $authoriseParams)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue an access token
|
||||
*
|
||||
* @access public
|
||||
* @param array $authParams Optional array of parsed $_POST keys
|
||||
* @return array Authorise request parameters
|
||||
*/
|
||||
public function issueAccessToken($authParams = null)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function getCurrentGrantType()
|
||||
{
|
||||
$grantType = $this->getRequest()->post('grant_type');
|
||||
|
||||
if (is_null($grantType)) {
|
||||
throw new Exception
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
12
src/OAuth2/Util/RedirectUri.php
Normal file
12
src/OAuth2/Util/RedirectUri.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace OAuth2\Util;
|
||||
|
||||
class RedirectUri
|
||||
{
|
||||
public static function make($uri, $params = array(), $queryDelimeter = '?')
|
||||
{
|
||||
$uri .= (strstr($uri, $queryDelimeter) === false) ? $queryDelimeter ? '&';
|
||||
return $uri.http_build_query($params)
|
||||
}
|
||||
}
|
21
src/OAuth2/Util/SecureKey.php
Normal file
21
src/OAuth2/Util/SecureKey.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace OAuth2\Util;
|
||||
|
||||
class SecureKey
|
||||
{
|
||||
public static function make($len = 42)
|
||||
{
|
||||
// We generate twice as many bytes here because we want to ensure we have
|
||||
// enough after we base64 encode it to get the length we need because we
|
||||
// take out the "/", "+", and "=" characters.
|
||||
$bytes = openssl_random_pseudo_bytes($len * 2, $strong);
|
||||
|
||||
// We want to stop execution if the key fails because, well, that is bad.
|
||||
if ($bytes === false || $strong === false) {
|
||||
throw new Exception('Error Generating Key');
|
||||
}
|
||||
|
||||
return substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $len);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user