Skip to content

Commit

Permalink
Merge pull request #1 from examus/update-oauth2-library
Browse files Browse the repository at this point in the history
Update oauth2 library
  • Loading branch information
MaksimBurnin authored Jul 21, 2021
2 parents 415ea44 + d8a2a08 commit b84d077
Show file tree
Hide file tree
Showing 70 changed files with 3,540 additions and 717 deletions.
12 changes: 9 additions & 3 deletions OAuth2/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,22 @@
*/
class Autoloader
{
/**
* @var string
*/
private $dir;

/**
* @param string $dir
*/
public function __construct($dir = null)
{
if (is_null($dir)) {
$dir = dirname(__FILE__).'/..';
}
$this->dir = $dir;
}

/**
* Registers OAuth2\Autoloader as an SPL autoloader.
*/
Expand All @@ -31,9 +38,8 @@ public static function register($dir = null)
/**
* Handles autoloading of classes.
*
* @param string $class A class name.
*
* @return boolean Returns true if the class has been loaded
* @param string $class - A class name.
* @return boolean - Returns true if the class has been loaded
*/
public function autoload($class)
{
Expand Down
13 changes: 13 additions & 0 deletions OAuth2/ClientAssertionType/ClientAssertionTypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@
*/
interface ClientAssertionTypeInterface
{
/**
* Validate the OAuth request
*
* @param RequestInterface $request
* @param ResponseInterface $response
* @return mixed
*/
public function validateRequest(RequestInterface $request, ResponseInterface $response);

/**
* Get the client id
*
* @return mixed
*/
public function getClientId();
}
48 changes: 32 additions & 16 deletions OAuth2/ClientAssertionType/HttpBasic.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use OAuth2\Storage\ClientCredentialsInterface;
use OAuth2\RequestInterface;
use OAuth2\ResponseInterface;
use LogicException;

/**
* Validate a client via Http Basic authentication
Expand All @@ -19,14 +20,16 @@ class HttpBasic implements ClientAssertionTypeInterface
protected $config;

/**
* @param OAuth2\Storage\ClientCredentialsInterface $clientStorage REQUIRED Storage class for retrieving client credentials information
* @param array $config OPTIONAL Configuration options for the server
* <code>
* $config = array(
* 'allow_credentials_in_request_body' => true, // whether to look for credentials in the POST body in addition to the Authorize HTTP Header
* 'allow_public_clients' => true // if true, "public clients" (clients without a secret) may be authenticated
* );
* </code>
* Config array $config should look as follows:
* @code
* $config = array(
* 'allow_credentials_in_request_body' => true, // whether to look for credentials in the POST body in addition to the Authorize HTTP Header
* 'allow_public_clients' => true // if true, "public clients" (clients without a secret) may be authenticated
* );
* @endcode
*
* @param ClientCredentialsInterface $storage Storage
* @param array $config Configuration options for the server
*/
public function __construct(ClientCredentialsInterface $storage, array $config = array())
{
Expand All @@ -37,14 +40,22 @@ public function __construct(ClientCredentialsInterface $storage, array $config =
), $config);
}

/**
* Validate the OAuth request
*
* @param RequestInterface $request
* @param ResponseInterface $response
* @return bool|mixed
* @throws LogicException
*/
public function validateRequest(RequestInterface $request, ResponseInterface $response)
{
if (!$clientData = $this->getClientCredentials($request, $response)) {
return false;
}

if (!isset($clientData['client_id'])) {
throw new \LogicException('the clientData array must have "client_id" set');
throw new LogicException('the clientData array must have "client_id" set');
}

if (!isset($clientData['client_secret']) || $clientData['client_secret'] == '') {
Expand All @@ -70,6 +81,11 @@ public function validateRequest(RequestInterface $request, ResponseInterface $re
return true;
}

/**
* Get the client id
*
* @return mixed
*/
public function getClientId()
{
return $this->clientData['client_id'];
Expand All @@ -82,13 +98,14 @@ public function getClientId()
* According to the spec (draft 20), the client_id can be provided in
* the Basic Authorization header (recommended) or via GET/POST.
*
* @return
* A list containing the client identifier and password, for example
* @param RequestInterface $request
* @param ResponseInterface $response
* @return array|null A list containing the client identifier and password, for example:
* @code
* return array(
* "client_id" => CLIENT_ID, // REQUIRED the client id
* "client_secret" => CLIENT_SECRET, // OPTIONAL the client secret (may be omitted for public clients)
* );
* return array(
* "client_id" => CLIENT_ID, // REQUIRED the client id
* "client_secret" => CLIENT_SECRET, // OPTIONAL the client secret (may be omitted for public clients)
* );
* @endcode
*
* @see http://tools.ietf.org/html/rfc6749#section-2.3.1
Expand All @@ -108,7 +125,6 @@ public function getClientCredentials(RequestInterface $request, ResponseInterfac
* client_secret can be null if the client's password is an empty string
* @see http://tools.ietf.org/html/rfc6749#section-2.3.1
*/

return array('client_id' => $request->request('client_id'), 'client_secret' => $request->request('client_secret'));
}
}
Expand Down
Loading

0 comments on commit b84d077

Please sign in to comment.