Applied fixes from StyleCI

This commit is contained in:
Alex Bilbie 2016-02-19 18:09:39 -05:00 committed by StyleCI Bot
parent 60c45ab8fe
commit a2460886f6
57 changed files with 346 additions and 330 deletions

View File

@ -3,19 +3,17 @@
use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Exception\OAuthServerException;
use League\OAuth2\Server\Grant\AuthCodeGrant; use League\OAuth2\Server\Grant\AuthCodeGrant;
use League\OAuth2\Server\Server; use League\OAuth2\Server\Server;
use OAuth2ServerExamples\Repositories\AccessTokenRepository; use OAuth2ServerExamples\Repositories\AccessTokenRepository;
use OAuth2ServerExamples\Repositories\AuthCodeRepository; use OAuth2ServerExamples\Repositories\AuthCodeRepository;
use OAuth2ServerExamples\Repositories\ClientRepository; use OAuth2ServerExamples\Repositories\ClientRepository;
use OAuth2ServerExamples\Repositories\RefreshTokenRepository; use OAuth2ServerExamples\Repositories\RefreshTokenRepository;
use OAuth2ServerExamples\Repositories\ScopeRepository; use OAuth2ServerExamples\Repositories\ScopeRepository;
use OAuth2ServerExamples\Repositories\UserRepository; use OAuth2ServerExamples\Repositories\UserRepository;
use Slim\App; use Slim\App;
use Slim\Http\Request; use Slim\Http\Request;
use Slim\Http\Response; use Slim\Http\Response;
include(__DIR__ . '/../vendor/autoload.php'); include __DIR__.'/../vendor/autoload.php';
// App // App
$app = new App([ $app = new App([
@ -29,8 +27,8 @@ $app = new App([
$refreshTokenRepository = new RefreshTokenRepository(); $refreshTokenRepository = new RefreshTokenRepository();
$authCodeRepository = new AuthCodeRepository(); $authCodeRepository = new AuthCodeRepository();
$privateKeyPath = 'file://' . __DIR__ . '/../private.key'; $privateKeyPath = 'file://'.__DIR__.'/../private.key';
$publicKeyPath = 'file://' . __DIR__ . '/../public.key'; $publicKeyPath = 'file://'.__DIR__.'/../public.key';
// Setup the authorization server // Setup the authorization server
$server = new Server( $server = new Server(

View File

@ -3,16 +3,14 @@
use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Exception\OAuthServerException;
use League\OAuth2\Server\Grant\ClientCredentialsGrant; use League\OAuth2\Server\Grant\ClientCredentialsGrant;
use League\OAuth2\Server\Server; use League\OAuth2\Server\Server;
use OAuth2ServerExamples\Repositories\AccessTokenRepository; use OAuth2ServerExamples\Repositories\AccessTokenRepository;
use OAuth2ServerExamples\Repositories\ClientRepository; use OAuth2ServerExamples\Repositories\ClientRepository;
use OAuth2ServerExamples\Repositories\ScopeRepository; use OAuth2ServerExamples\Repositories\ScopeRepository;
use Slim\App; use Slim\App;
use Slim\Http\Request; use Slim\Http\Request;
use Slim\Http\Response; use Slim\Http\Response;
include(__DIR__ . '/../vendor/autoload.php'); include __DIR__.'/../vendor/autoload.php';
// App // App
$app = new App([ $app = new App([
@ -23,8 +21,8 @@ $app = new App([
$scopeRepository = new ScopeRepository(); $scopeRepository = new ScopeRepository();
$accessTokenRepository = new AccessTokenRepository(); $accessTokenRepository = new AccessTokenRepository();
$privateKeyPath = 'file://' . __DIR__ . '/../private.key'; $privateKeyPath = 'file://'.__DIR__.'/../private.key';
$publicKeyPath = 'file://' . __DIR__ . '/../public.key'; $publicKeyPath = 'file://'.__DIR__.'/../public.key';
// Setup the authorization server // Setup the authorization server
$server = new Server( $server = new Server(
@ -39,7 +37,7 @@ $app = new App([
$server->enableGrantType(new ClientCredentialsGrant(), new \DateInterval('PT1H')); $server->enableGrantType(new ClientCredentialsGrant(), new \DateInterval('PT1H'));
return $server; return $server;
} },
]); ]);
$app->post('/access_token', function (Request $request, Response $response) { $app->post('/access_token', function (Request $request, Response $response) {

View File

@ -4,16 +4,14 @@ use League\OAuth2\Server\Grant\PasswordGrant;
use League\OAuth2\Server\Grant\RefreshTokenGrant; use League\OAuth2\Server\Grant\RefreshTokenGrant;
use League\OAuth2\Server\Middleware\AuthenticationServerMiddleware; use League\OAuth2\Server\Middleware\AuthenticationServerMiddleware;
use League\OAuth2\Server\Server; use League\OAuth2\Server\Server;
use OAuth2ServerExamples\Repositories\AccessTokenRepository; use OAuth2ServerExamples\Repositories\AccessTokenRepository;
use OAuth2ServerExamples\Repositories\ClientRepository; use OAuth2ServerExamples\Repositories\ClientRepository;
use OAuth2ServerExamples\Repositories\RefreshTokenRepository; use OAuth2ServerExamples\Repositories\RefreshTokenRepository;
use OAuth2ServerExamples\Repositories\ScopeRepository; use OAuth2ServerExamples\Repositories\ScopeRepository;
use OAuth2ServerExamples\Repositories\UserRepository; use OAuth2ServerExamples\Repositories\UserRepository;
use Slim\App; use Slim\App;
include(__DIR__ . '/../vendor/autoload.php'); include __DIR__.'/../vendor/autoload.php';
// App // App
$app = new App([ $app = new App([
@ -29,8 +27,8 @@ $app = new App([
$userRepository = new UserRepository(); $userRepository = new UserRepository();
$refreshTokenRepository = new RefreshTokenRepository(); $refreshTokenRepository = new RefreshTokenRepository();
$privateKeyPath = 'file://' . __DIR__ . '/../private.key'; $privateKeyPath = 'file://'.__DIR__.'/../private.key';
$publicKeyPath = 'file://' . __DIR__ . '/../public.key'; $publicKeyPath = 'file://'.__DIR__.'/../public.key';
// Setup the authorization server // Setup the authorization server
$server = new Server( $server = new Server(
@ -52,7 +50,7 @@ $app = new App([
); );
return $server; return $server;
} },
]); ]);
$app->post('/access_token', function () { $app->post('/access_token', function () {

View File

@ -3,18 +3,16 @@
use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Exception\OAuthServerException;
use League\OAuth2\Server\Grant\PasswordGrant; use League\OAuth2\Server\Grant\PasswordGrant;
use League\OAuth2\Server\Server; use League\OAuth2\Server\Server;
use OAuth2ServerExamples\Repositories\AccessTokenRepository; use OAuth2ServerExamples\Repositories\AccessTokenRepository;
use OAuth2ServerExamples\Repositories\ClientRepository; use OAuth2ServerExamples\Repositories\ClientRepository;
use OAuth2ServerExamples\Repositories\RefreshTokenRepository; use OAuth2ServerExamples\Repositories\RefreshTokenRepository;
use OAuth2ServerExamples\Repositories\ScopeRepository; use OAuth2ServerExamples\Repositories\ScopeRepository;
use OAuth2ServerExamples\Repositories\UserRepository; use OAuth2ServerExamples\Repositories\UserRepository;
use Slim\App; use Slim\App;
use Slim\Http\Request; use Slim\Http\Request;
use Slim\Http\Response; use Slim\Http\Response;
include(__DIR__ . '/../vendor/autoload.php'); include __DIR__.'/../vendor/autoload.php';
// App // App
$app = new App([ $app = new App([
@ -27,8 +25,8 @@ $app = new App([
$userRepository = new UserRepository(); $userRepository = new UserRepository();
$refreshTokenRepository = new RefreshTokenRepository(); $refreshTokenRepository = new RefreshTokenRepository();
$privateKeyPath = 'file://' . __DIR__ . '/../private.key'; $privateKeyPath = 'file://'.__DIR__.'/../private.key';
$publicKeyPath = 'file://' . __DIR__ . '/../public.key'; $publicKeyPath = 'file://'.__DIR__.'/../public.key';
// Setup the authorization server // Setup the authorization server
$server = new Server( $server = new Server(
@ -46,7 +44,7 @@ $app = new App([
); );
return $server; return $server;
} },
]); ]);
$app->post('/access_token', function (Request $request, Response $response) { $app->post('/access_token', function (Request $request, Response $response) {

View File

@ -2,16 +2,14 @@
use League\OAuth2\Server\Middleware\ResourceServerMiddleware; use League\OAuth2\Server\Middleware\ResourceServerMiddleware;
use League\OAuth2\Server\Server; use League\OAuth2\Server\Server;
use OAuth2ServerExamples\Repositories\AccessTokenRepository; use OAuth2ServerExamples\Repositories\AccessTokenRepository;
use OAuth2ServerExamples\Repositories\ClientRepository; use OAuth2ServerExamples\Repositories\ClientRepository;
use OAuth2ServerExamples\Repositories\ScopeRepository; use OAuth2ServerExamples\Repositories\ScopeRepository;
use Slim\App; use Slim\App;
use Slim\Http\Request; use Slim\Http\Request;
use Slim\Http\Response; use Slim\Http\Response;
include(__DIR__ . '/../vendor/autoload.php'); include __DIR__.'/../vendor/autoload.php';
// App // App
$app = new App([ $app = new App([
@ -25,8 +23,8 @@ $app = new App([
$scopeRepository = new ScopeRepository(); $scopeRepository = new ScopeRepository();
$accessTokenRepository = new AccessTokenRepository(); $accessTokenRepository = new AccessTokenRepository();
$privateKeyPath = 'file://' . __DIR__ . '/../private.key'; $privateKeyPath = 'file://'.__DIR__.'/../private.key';
$publicKeyPath = 'file://' . __DIR__ . '/../public.key'; $publicKeyPath = 'file://'.__DIR__.'/../public.key';
// Setup the authorization server // Setup the authorization server
$server = new Server( $server = new Server(
@ -38,7 +36,7 @@ $app = new App([
); );
return $server; return $server;
} },
]); ]);
$app->add(new ResourceServerMiddleware($app->getContainer()->get(Server::class))); $app->add(new ResourceServerMiddleware($app->getContainer()->get(Server::class)));
@ -50,7 +48,7 @@ $app->post('/api/example', function (Request $request, Response $response) {
$params = [ $params = [
'id' => 1, 'id' => 1,
'name' => 'Alex', 'name' => 'Alex',
'city' => 'London' 'city' => 'London',
]; ];
} }

View File

@ -3,19 +3,15 @@
use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Exception\OAuthServerException;
use League\OAuth2\Server\Grant\RefreshTokenGrant; use League\OAuth2\Server\Grant\RefreshTokenGrant;
use League\OAuth2\Server\Server; use League\OAuth2\Server\Server;
use OAuth2ServerExamples\Repositories\AccessTokenRepository; use OAuth2ServerExamples\Repositories\AccessTokenRepository;
use OAuth2ServerExamples\Repositories\ClientRepository; use OAuth2ServerExamples\Repositories\ClientRepository;
use OAuth2ServerExamples\Repositories\RefreshTokenRepository; use OAuth2ServerExamples\Repositories\RefreshTokenRepository;
use OAuth2ServerExamples\Repositories\ScopeRepository; use OAuth2ServerExamples\Repositories\ScopeRepository;
use Slim\App; use Slim\App;
use Slim\Http\Request; use Slim\Http\Request;
use Slim\Http\Response; use Slim\Http\Response;
include(__DIR__ . '/../vendor/autoload.php'); include __DIR__.'/../vendor/autoload.php';
// App // App
$app = new App([Server::class => function () { $app = new App([Server::class => function () {
@ -25,8 +21,8 @@ $app = new App([Server::class => function () {
$accessTokenRepository = new AccessTokenRepository(); $accessTokenRepository = new AccessTokenRepository();
$refreshTokenRepository = new RefreshTokenRepository(); $refreshTokenRepository = new RefreshTokenRepository();
$privateKeyPath = 'file://' . __DIR__ . '/../private.key'; $privateKeyPath = 'file://'.__DIR__.'/../private.key';
$publicKeyPath = 'file://' . __DIR__ . '/../public.key'; $publicKeyPath = 'file://'.__DIR__.'/../public.key';
// Setup the authorization server // Setup the authorization server
$server = new Server( $server = new Server(

View File

@ -7,7 +7,8 @@ use League\OAuth2\Server\Entities\Interfaces\UserEntityInterface;
class UserEntity implements UserEntityInterface class UserEntity implements UserEntityInterface
{ {
/** /**
* Return the user's identifier * Return the user's identifier.
*
* @return mixed * @return mixed
*/ */
public function getIdentifier() public function getIdentifier()

View File

@ -1,4 +1,5 @@
<?php <?php
namespace OAuth2ServerExamples\Repositories; namespace OAuth2ServerExamples\Repositories;
use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface;
@ -7,7 +8,7 @@ use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
class AccessTokenRepository implements AccessTokenRepositoryInterface class AccessTokenRepository implements AccessTokenRepositoryInterface
{ {
/** /**
* Persists a new access token to permanent storage * Persists a new access token to permanent storage.
* *
* @param \League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface $accessTokenEntity * @param \League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface $accessTokenEntity
*/ */
@ -17,7 +18,7 @@ class AccessTokenRepository implements AccessTokenRepositoryInterface
} }
/** /**
* Revoke an access token * Revoke an access token.
* *
* @param string $tokenId * @param string $tokenId
*/ */
@ -27,7 +28,7 @@ class AccessTokenRepository implements AccessTokenRepositoryInterface
} }
/** /**
* Check if the access token has been revoked * Check if the access token has been revoked.
* *
* @param string $tokenId * @param string $tokenId
* *

View File

@ -7,9 +7,8 @@ use League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface;
class AuthCodeRepository implements AuthCodeRepositoryInterface class AuthCodeRepository implements AuthCodeRepositoryInterface
{ {
/** /**
* Persists a new auth code to permanent storage * Persists a new auth code to permanent storage.
* *
* @param \League\OAuth2\Server\Entities\Interfaces\AuthCodeEntityInterface $authCodeEntity * @param \League\OAuth2\Server\Entities\Interfaces\AuthCodeEntityInterface $authCodeEntity
*/ */
@ -19,7 +18,7 @@ class AuthCodeRepository implements AuthCodeRepositoryInterface
} }
/** /**
* Revoke an auth code * Revoke an auth code.
* *
* @param string $codeId * @param string $codeId
*/ */
@ -29,7 +28,7 @@ class AuthCodeRepository implements AuthCodeRepositoryInterface
} }
/** /**
* Check if the auth code has been revoked * Check if the auth code has been revoked.
* *
* @param string $codeId * @param string $codeId
* *

View File

@ -1,4 +1,5 @@
<?php <?php
namespace OAuth2ServerExamples\Repositories; namespace OAuth2ServerExamples\Repositories;
use League\OAuth2\Server\Entities\ClientEntity; use League\OAuth2\Server\Entities\ClientEntity;
@ -7,7 +8,7 @@ use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
class ClientRepository implements ClientRepositoryInterface class ClientRepository implements ClientRepositoryInterface
{ {
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function getClientEntity($clientIdentifier, $clientSecret = null, $redirectUri = null, $grantType = null) public function getClientEntity($clientIdentifier, $clientSecret = null, $redirectUri = null, $grantType = null)
{ {
@ -15,23 +16,23 @@ class ClientRepository implements ClientRepositoryInterface
'myawesomeapp' => [ 'myawesomeapp' => [
'secret' => password_hash('abc123', PASSWORD_BCRYPT), 'secret' => password_hash('abc123', PASSWORD_BCRYPT),
'name' => 'My Awesome App', 'name' => 'My Awesome App',
'redirect_uri' => 'http://foo/bar' 'redirect_uri' => 'http://foo/bar',
] ],
]; ];
// Check if client is registered // Check if client is registered
if (array_key_exists($clientIdentifier, $clients) === false) { if (array_key_exists($clientIdentifier, $clients) === false) {
return null; return;
} }
// Check if client secret is valid // Check if client secret is valid
if ($clientSecret !== null && password_verify($clientSecret, $clients[$clientIdentifier]['secret']) === false) { if ($clientSecret !== null && password_verify($clientSecret, $clients[$clientIdentifier]['secret']) === false) {
return null; return;
} }
// Check if redirect URI is valid // Check if redirect URI is valid
if ($redirectUri !== null && $redirectUri !== $clients[$clientIdentifier]['redirect_uri']) { if ($redirectUri !== null && $redirectUri !== $clients[$clientIdentifier]['redirect_uri']) {
return null; return;
} }
$client = new ClientEntity(); $client = new ClientEntity();

View File

@ -7,9 +7,8 @@ use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
class RefreshTokenRepository implements RefreshTokenRepositoryInterface class RefreshTokenRepository implements RefreshTokenRepositoryInterface
{ {
/** /**
* Create a new refresh token_name * Create a new refresh token_name.
* *
* @param \League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface $refreshTokenEntityInterface * @param \League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface $refreshTokenEntityInterface
*/ */
@ -19,7 +18,7 @@ class RefreshTokenRepository implements RefreshTokenRepositoryInterface
} }
/** /**
* Revoke the refresh token * Revoke the refresh token.
* *
* @param string $tokenId * @param string $tokenId
*/ */
@ -29,7 +28,7 @@ class RefreshTokenRepository implements RefreshTokenRepositoryInterface
} }
/** /**
* Check if the refresh token has been revoked * Check if the refresh token has been revoked.
* *
* @param string $tokenId * @param string $tokenId
* *

View File

@ -1,4 +1,5 @@
<?php <?php
namespace OAuth2ServerExamples\Repositories; namespace OAuth2ServerExamples\Repositories;
use League\OAuth2\Server\Entities\ScopeEntity; use League\OAuth2\Server\Entities\ScopeEntity;
@ -7,21 +8,21 @@ use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
class ScopeRepository implements ScopeRepositoryInterface class ScopeRepository implements ScopeRepositoryInterface
{ {
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function getScopeEntityByIdentifier($scopeIdentifier, $grantType, $clientId = null) public function getScopeEntityByIdentifier($scopeIdentifier, $grantType, $clientId = null)
{ {
$scopes = [ $scopes = [
'basic' => [ 'basic' => [
'description' => 'Basic details about you' 'description' => 'Basic details about you',
], ],
'email' => [ 'email' => [
'description' => 'Your email address' 'description' => 'Your email address',
] ],
]; ];
if (array_key_exists($scopeIdentifier, $scopes) === false) { if (array_key_exists($scopeIdentifier, $scopes) === false) {
return null; return;
} }
$scope = new ScopeEntity(); $scope = new ScopeEntity();

View File

@ -1,4 +1,5 @@
<?php <?php
namespace OAuth2ServerExamples\Repositories; namespace OAuth2ServerExamples\Repositories;
use League\OAuth2\Server\Repositories\UserRepositoryInterface; use League\OAuth2\Server\Repositories\UserRepositoryInterface;
@ -7,7 +8,7 @@ use OAuth2ServerExamples\Entities\UserEntity;
class UserRepository implements UserRepositoryInterface class UserRepository implements UserRepositoryInterface
{ {
/** /**
* Get a user entity * Get a user entity.
* *
* @param string $username * @param string $username
* @param string $password * @param string $password
@ -20,6 +21,6 @@ class UserRepository implements UserRepositoryInterface
return new UserEntity(); return new UserEntity();
} }
return null; return;
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
namespace League\OAuth2\Server\Entities; namespace League\OAuth2\Server\Entities;
use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface;

View File

@ -1,4 +1,5 @@
<?php <?php
namespace League\OAuth2\Server\Entities; namespace League\OAuth2\Server\Entities;
use League\OAuth2\Server\Entities\Interfaces\AuthCodeEntityInterface; use League\OAuth2\Server\Entities\Interfaces\AuthCodeEntityInterface;
@ -6,8 +7,7 @@ use League\OAuth2\Server\Entities\Traits\EntityTrait;
use League\OAuth2\Server\Entities\Traits\TokenEntityTrait; use League\OAuth2\Server\Entities\Traits\TokenEntityTrait;
/** /**
* Class AuthCodeEntity * Class AuthCodeEntity.
* @package League\OAuth2\Server
*/ */
class AuthCodeEntity implements AuthCodeEntityInterface class AuthCodeEntity implements AuthCodeEntityInterface
{ {

View File

@ -1,4 +1,5 @@
<?php <?php
namespace League\OAuth2\Server\Entities; namespace League\OAuth2\Server\Entities;
use League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface; use League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface;
@ -6,8 +7,7 @@ use League\OAuth2\Server\Entities\Traits\ClientEntityTrait;
use League\OAuth2\Server\Entities\Traits\EntityTrait; use League\OAuth2\Server\Entities\Traits\EntityTrait;
/** /**
* Class ClientEntity * Class ClientEntity.
* @package League\OAuth2\Server
*/ */
class ClientEntity implements ClientEntityInterface class ClientEntity implements ClientEntityInterface
{ {

View File

@ -1,7 +1,7 @@
<?php <?php
namespace League\OAuth2\Server\Entities\Interfaces; namespace League\OAuth2\Server\Entities\Interfaces;
interface AccessTokenEntityInterface extends TokenInterface interface AccessTokenEntityInterface extends TokenInterface
{ {
} }

View File

@ -1,29 +1,32 @@
<?php <?php
namespace League\OAuth2\Server\Entities\Interfaces; namespace League\OAuth2\Server\Entities\Interfaces;
interface ClientEntityInterface interface ClientEntityInterface
{ {
/** /**
* Get the client's identifier * Get the client's identifier.
*
* @return string * @return string
*/ */
public function getIdentifier(); public function getIdentifier();
/** /**
* Set the client's identifier * Set the client's identifier.
* *
* @param $identifier * @param $identifier
*/ */
public function setIdentifier($identifier); public function setIdentifier($identifier);
/** /**
* Get the client's name * Get the client's name.
*
* @return string * @return string
*/ */
public function getName(); public function getName();
/** /**
* Set the client's name * Set the client's name.
* *
* @param string $name * @param string $name
*/ */
@ -35,31 +38,32 @@ interface ClientEntityInterface
public function setSecret($secret); public function setSecret($secret);
/** /**
* Validate the secret provided by the client * Validate the secret provided by the client.
* *
* @param string $submittedSecret * @param string $submittedSecret
* *
* @return boolean * @return bool
*/ */
public function validateSecret($submittedSecret); public function validateSecret($submittedSecret);
/** /**
* Set the client's redirect uri * Set the client's redirect uri.
* *
* @param string $redirectUri * @param string $redirectUri
*/ */
public function setRedirectUri($redirectUri); public function setRedirectUri($redirectUri);
/** /**
* Returns the registered redirect URI * Returns the registered redirect URI.
* *
* @return string * @return string
*/ */
public function getRedirectUri(); public function getRedirectUri();
/** /**
* Returns true if the client is capable of keeping it's secrets secret * Returns true if the client is capable of keeping it's secrets secret.
* @return boolean *
* @return bool
*/ */
public function canKeepASecret(); public function canKeepASecret();
} }

View File

@ -1,47 +1,54 @@
<?php <?php
namespace League\OAuth2\Server\Entities\Interfaces; namespace League\OAuth2\Server\Entities\Interfaces;
interface RefreshTokenEntityInterface interface RefreshTokenEntityInterface
{ {
/** /**
* Get the token's identifier * Get the token's identifier.
*
* @return string * @return string
*/ */
public function getIdentifier(); public function getIdentifier();
/** /**
* Set the token's identifier * Set the token's identifier.
*
* @param $identifier * @param $identifier
*/ */
public function setIdentifier($identifier); public function setIdentifier($identifier);
/** /**
* Get the token's expiry date time * Get the token's expiry date time.
*
* @return \DateTime * @return \DateTime
*/ */
public function getExpiryDateTime(); public function getExpiryDateTime();
/** /**
* Set the date time when the token expires * Set the date time when the token expires.
*
* @param \DateTime $dateTime * @param \DateTime $dateTime
*/ */
public function setExpiryDateTime(\DateTime $dateTime); public function setExpiryDateTime(\DateTime $dateTime);
/** /**
* Set the access token that the refresh token was associated with * Set the access token that the refresh token was associated with.
* *
* @param \League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface $accessToken * @param \League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface $accessToken
*/ */
public function setAccessToken(AccessTokenEntityInterface $accessToken); public function setAccessToken(AccessTokenEntityInterface $accessToken);
/** /**
* Get the access token that the refresh token was originally associated with * Get the access token that the refresh token was originally associated with.
*
* @return \League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface * @return \League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface
*/ */
public function getAccessToken(); public function getAccessToken();
/** /**
* Has the token expired? * Has the token expired?
*
* @return bool * @return bool
*/ */
public function isExpired(); public function isExpired();

View File

@ -1,16 +1,19 @@
<?php <?php
namespace League\OAuth2\Server\Entities\Interfaces; namespace League\OAuth2\Server\Entities\Interfaces;
interface ScopeEntityInterface extends \JsonSerializable interface ScopeEntityInterface extends \JsonSerializable
{ {
/** /**
* Get the scope's identifier * Get the scope's identifier.
*
* @return string * @return string
*/ */
public function getIdentifier(); public function getIdentifier();
/** /**
* Set the scope's identifier * Set the scope's identifier.
*
* @param $identifier * @param $identifier
*/ */
public function setIdentifier($identifier); public function setIdentifier($identifier);

View File

@ -1,78 +1,91 @@
<?php <?php
namespace League\OAuth2\Server\Entities\Interfaces; namespace League\OAuth2\Server\Entities\Interfaces;
interface TokenInterface interface TokenInterface
{ {
/** /**
* Get the token's identifier * Get the token's identifier.
*
* @return string * @return string
*/ */
public function getIdentifier(); public function getIdentifier();
/** /**
* Set the token's identifier * Set the token's identifier.
*
* @param $identifier * @param $identifier
*/ */
public function setIdentifier($identifier); public function setIdentifier($identifier);
/** /**
* Get the token's expiry date time * Get the token's expiry date time.
*
* @return \DateTime * @return \DateTime
*/ */
public function getExpiryDateTime(); public function getExpiryDateTime();
/** /**
* Set the date time when the token expires * Set the date time when the token expires.
*
* @param \DateTime $dateTime * @param \DateTime $dateTime
*/ */
public function setExpiryDateTime(\DateTime $dateTime); public function setExpiryDateTime(\DateTime $dateTime);
/** /**
* Set the identifier of the user associated with the token * Set the identifier of the user associated with the token.
* *
* @param string|int $identifier The identifier of the user * @param string|int $identifier The identifier of the user
*/ */
public function setUserIdentifier($identifier); public function setUserIdentifier($identifier);
/** /**
* Get the token user's identifier * Get the token user's identifier.
*
* @return string|int * @return string|int
*/ */
public function getUserIdentifier(); public function getUserIdentifier();
/** /**
* Get the client that the token was issued to * Get the client that the token was issued to.
*
* @return ClientEntityInterface * @return ClientEntityInterface
*/ */
public function getClient(); public function getClient();
/** /**
* Set the client that the token was issued to * Set the client that the token was issued to.
*
* @param \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface $client * @param \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface $client
*/ */
public function setClient(ClientEntityInterface $client); public function setClient(ClientEntityInterface $client);
/** /**
* Associate a scope with the token * Associate a scope with the token.
*
* @param \League\OAuth2\Server\Entities\Interfaces\ScopeEntityInterface $scope * @param \League\OAuth2\Server\Entities\Interfaces\ScopeEntityInterface $scope
*/ */
public function addScope(ScopeEntityInterface $scope); public function addScope(ScopeEntityInterface $scope);
/** /**
* Get an associated scope by the scope's identifier * Get an associated scope by the scope's identifier.
*
* @param string $identifier * @param string $identifier
* @return ScopeEntityInterface|null The scope or null if not found *
* @return ScopeEntityInterface|null The scope or null if not found
*/ */
public function getScopeWithIdentifier($identifier); public function getScopeWithIdentifier($identifier);
/** /**
* Return an array of scopes associated with the token * Return an array of scopes associated with the token.
*
* @return ScopeEntityInterface[] * @return ScopeEntityInterface[]
*/ */
public function getScopes(); public function getScopes();
/** /**
* Has the token expired? * Has the token expired?
*
* @return bool * @return bool
*/ */
public function isExpired(); public function isExpired();

View File

@ -5,7 +5,8 @@ namespace League\OAuth2\Server\Entities\Interfaces;
interface UserEntityInterface interface UserEntityInterface
{ {
/** /**
* Return the user's identifier * Return the user's identifier.
*
* @return mixed * @return mixed
*/ */
public function getIdentifier(); public function getIdentifier();

View File

@ -1,4 +1,5 @@
<?php <?php
namespace League\OAuth2\Server\Entities; namespace League\OAuth2\Server\Entities;
use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface; use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface;
@ -6,8 +7,7 @@ use League\OAuth2\Server\Entities\Traits\EntityTrait;
use League\OAuth2\Server\Entities\Traits\RefreshTokenTrait; use League\OAuth2\Server\Entities\Traits\RefreshTokenTrait;
/** /**
* Class RefreshTokenEntity * Class RefreshTokenEntity.
* @package League\OAuth2\Server
*/ */
class RefreshTokenEntity implements RefreshTokenEntityInterface class RefreshTokenEntity implements RefreshTokenEntityInterface
{ {

View File

@ -1,19 +1,19 @@
<?php <?php
namespace League\OAuth2\Server\Entities; namespace League\OAuth2\Server\Entities;
use League\OAuth2\Server\Entities\Interfaces\ScopeEntityInterface; use League\OAuth2\Server\Entities\Interfaces\ScopeEntityInterface;
use League\OAuth2\Server\Entities\Traits\EntityTrait; use League\OAuth2\Server\Entities\Traits\EntityTrait;
/** /**
* Class ScopeEntity * Class ScopeEntity.
* @package League\OAuth2\Server
*/ */
class ScopeEntity implements ScopeEntityInterface class ScopeEntity implements ScopeEntityInterface
{ {
use EntityTrait; use EntityTrait;
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function jsonSerialize() public function jsonSerialize()
{ {

View File

@ -1,4 +1,5 @@
<?php <?php
namespace League\OAuth2\Server\Entities\Traits; namespace League\OAuth2\Server\Entities\Traits;
trait ClientEntityTrait trait ClientEntityTrait
@ -19,7 +20,7 @@ trait ClientEntityTrait
protected $redirectUri; protected $redirectUri;
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function getName() public function getName()
{ {
@ -27,7 +28,7 @@ trait ClientEntityTrait
} }
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function setName($name) public function setName($name)
{ {
@ -35,7 +36,7 @@ trait ClientEntityTrait
} }
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function canKeepASecret() public function canKeepASecret()
{ {
@ -43,7 +44,7 @@ trait ClientEntityTrait
} }
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function setSecret($secret) public function setSecret($secret)
{ {
@ -51,7 +52,7 @@ trait ClientEntityTrait
} }
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function validateSecret($submittedSecret) public function validateSecret($submittedSecret)
{ {
@ -59,7 +60,7 @@ trait ClientEntityTrait
} }
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function setRedirectUri($redirectUri) public function setRedirectUri($redirectUri)
{ {
@ -67,7 +68,7 @@ trait ClientEntityTrait
} }
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function getRedirectUri() public function getRedirectUri()
{ {

View File

@ -1,4 +1,5 @@
<?php <?php
namespace League\OAuth2\Server\Entities\Traits; namespace League\OAuth2\Server\Entities\Traits;
trait EntityTrait trait EntityTrait

View File

@ -1,4 +1,5 @@
<?php <?php
namespace League\OAuth2\Server\Entities\Traits; namespace League\OAuth2\Server\Entities\Traits;
use DateTime; use DateTime;
@ -17,7 +18,7 @@ trait RefreshTokenTrait
protected $expiryDateTime; protected $expiryDateTime;
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function setAccessToken(AccessTokenEntityInterface $accessToken) public function setAccessToken(AccessTokenEntityInterface $accessToken)
{ {
@ -25,7 +26,7 @@ trait RefreshTokenTrait
} }
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function getAccessToken() public function getAccessToken()
{ {
@ -33,7 +34,8 @@ trait RefreshTokenTrait
} }
/** /**
* Get the token's expiry date time * Get the token's expiry date time.
*
* @return DateTime * @return DateTime
*/ */
public function getExpiryDateTime() public function getExpiryDateTime()
@ -42,7 +44,7 @@ trait RefreshTokenTrait
} }
/** /**
* Set the date time when the token expires * Set the date time when the token expires.
* *
* @param DateTime $dateTime * @param DateTime $dateTime
*/ */
@ -53,6 +55,7 @@ trait RefreshTokenTrait
/** /**
* Has the token expired? * Has the token expired?
*
* @return bool * @return bool
*/ */
public function isExpired() public function isExpired()

View File

@ -1,4 +1,5 @@
<?php <?php
namespace League\OAuth2\Server\Entities\Traits; namespace League\OAuth2\Server\Entities\Traits;
use DateTime; use DateTime;
@ -28,7 +29,7 @@ trait TokenEntityTrait
protected $client; protected $client;
/** /**
* Associate a scope with the token * Associate a scope with the token.
* *
* @param \League\OAuth2\Server\Entities\Interfaces\ScopeEntityInterface $scope * @param \League\OAuth2\Server\Entities\Interfaces\ScopeEntityInterface $scope
*/ */
@ -38,11 +39,11 @@ trait TokenEntityTrait
} }
/** /**
* Get an associated scope by the scope's identifier * Get an associated scope by the scope's identifier.
* *
* @param string $identifier * @param string $identifier
* *
* @return ScopeEntityInterface|null The scope or null if not found * @return ScopeEntityInterface|null The scope or null if not found
*/ */
public function getScopeWithIdentifier($identifier) public function getScopeWithIdentifier($identifier)
{ {
@ -50,7 +51,8 @@ trait TokenEntityTrait
} }
/** /**
* Return an array of scopes associated with the token * Return an array of scopes associated with the token.
*
* @return ScopeEntityInterface[] * @return ScopeEntityInterface[]
*/ */
public function getScopes() public function getScopes()
@ -59,7 +61,8 @@ trait TokenEntityTrait
} }
/** /**
* Get the token's expiry date time * Get the token's expiry date time.
*
* @return DateTime * @return DateTime
*/ */
public function getExpiryDateTime() public function getExpiryDateTime()
@ -68,7 +71,7 @@ trait TokenEntityTrait
} }
/** /**
* Set the date time when the token expires * Set the date time when the token expires.
* *
* @param DateTime $dateTime * @param DateTime $dateTime
*/ */
@ -78,7 +81,7 @@ trait TokenEntityTrait
} }
/** /**
* Set the identifier of the user associated with the token * Set the identifier of the user associated with the token.
* *
* @param string|int $identifier The identifier of the user * @param string|int $identifier The identifier of the user
*/ */
@ -88,7 +91,8 @@ trait TokenEntityTrait
} }
/** /**
* Get the token user's identifier * Get the token user's identifier.
*
* @return string|int * @return string|int
*/ */
public function getUserIdentifier() public function getUserIdentifier()
@ -97,7 +101,8 @@ trait TokenEntityTrait
} }
/** /**
* Get the client that the token was issued to * Get the client that the token was issued to.
*
* @return ClientEntityInterface * @return ClientEntityInterface
*/ */
public function getClient() public function getClient()
@ -106,7 +111,7 @@ trait TokenEntityTrait
} }
/** /**
* Set the client that the token was issued to * Set the client that the token was issued to.
* *
* @param \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface $client * @param \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface $client
*/ */
@ -117,6 +122,7 @@ trait TokenEntityTrait
/** /**
* Has the token expired? * Has the token expired?
*
* @return bool * @return bool
*/ */
public function isExpired() public function isExpired()

View File

@ -30,7 +30,7 @@ class OAuthServerException extends \Exception
private $redirectUri; private $redirectUri;
/** /**
* Throw a new exception * Throw a new exception.
* *
* @param string $message Error message * @param string $message Error message
* @param string $errorType Error type * @param string $errorType Error type
@ -48,7 +48,7 @@ class OAuthServerException extends \Exception
} }
/** /**
* Invalid grant type error * Invalid grant type error.
* *
* @param null|string $localizedError * @param null|string $localizedError
* @param null|string $localizedHint * @param null|string $localizedHint
@ -60,7 +60,7 @@ class OAuthServerException extends \Exception
$localizedHint = null $localizedHint = null
) { ) {
$errorMessage = (is_null($localizedError)) $errorMessage = (is_null($localizedError))
? 'The provided authorization grant is invalid, expired, revoked, does not match ' . ? 'The provided authorization grant is invalid, expired, revoked, does not match '.
'the redirection URI used in the authorization request, or was issued to another client.' 'the redirection URI used in the authorization request, or was issued to another client.'
: $localizedError; : $localizedError;
$hint = (is_null($localizedHint)) $hint = (is_null($localizedHint))
@ -71,7 +71,7 @@ class OAuthServerException extends \Exception
} }
/** /**
* Unsupported grant type error * Unsupported grant type error.
* *
* @param null|string $localizedError * @param null|string $localizedError
* @param null|string $localizedHint * @param null|string $localizedHint
@ -93,9 +93,9 @@ class OAuthServerException extends \Exception
} }
/** /**
* Invalid request error * Invalid request error.
* *
* @param string $parameter The invalid parameter * @param string $parameter The invalid parameter
* @param null|string $localizedError * @param null|string $localizedError
* @param null|string $localizedHint * @param null|string $localizedHint
* *
@ -107,7 +107,7 @@ class OAuthServerException extends \Exception
$localizedHint = null $localizedHint = null
) { ) {
$errorMessage = (is_null($localizedError)) $errorMessage = (is_null($localizedError))
? 'The request is missing a required parameter, includes an invalid parameter value, ' . ? 'The request is missing a required parameter, includes an invalid parameter value, '.
'includes a parameter more than once, or is otherwise malformed.' 'includes a parameter more than once, or is otherwise malformed.'
: $localizedError; : $localizedError;
$hint = (is_null($localizedHint)) $hint = (is_null($localizedHint))
@ -118,7 +118,7 @@ class OAuthServerException extends \Exception
} }
/** /**
* Invalid client error * Invalid client error.
* *
* @param null|string $localizedError * @param null|string $localizedError
* *
@ -134,7 +134,7 @@ class OAuthServerException extends \Exception
} }
/** /**
* Invalid scope error * Invalid scope error.
* *
* @param string $scope The bad scope * @param string $scope The bad scope
* @param null|string $localizedError A localized error message * @param null|string $localizedError A localized error message
@ -156,7 +156,7 @@ class OAuthServerException extends \Exception
} }
/** /**
* Invalid credentials error * Invalid credentials error.
* *
* @return static * @return static
*/ */
@ -166,7 +166,7 @@ class OAuthServerException extends \Exception
} }
/** /**
* Server error * Server error.
* *
* @param $hint * @param $hint
* *
@ -176,7 +176,7 @@ class OAuthServerException extends \Exception
{ {
return new static( return new static(
'The authorization server encountered an unexpected condition which prevented it from fulfilling' 'The authorization server encountered an unexpected condition which prevented it from fulfilling'
. 'the request.', .'the request.',
'server_error', 'server_error',
500, 500,
$hint $hint
@ -184,9 +184,10 @@ class OAuthServerException extends \Exception
} }
/** /**
* Invalid refresh token * Invalid refresh token.
* *
* @param string|null $hint * @param string|null $hint
*
* @return static * @return static
*/ */
public static function invalidRefreshToken($hint = null) public static function invalidRefreshToken($hint = null)
@ -195,7 +196,7 @@ class OAuthServerException extends \Exception
} }
/** /**
* Access denied * Access denied.
* *
* @param string|null $hint * @param string|null $hint
* @param string|null $redirectUri * @param string|null $redirectUri
@ -222,7 +223,7 @@ class OAuthServerException extends \Exception
} }
/** /**
* Generate a HTTP response * Generate a HTTP response.
* *
* @param \Psr\Http\Message\ResponseInterface $response * @param \Psr\Http\Message\ResponseInterface $response
* *
@ -238,7 +239,7 @@ class OAuthServerException extends \Exception
$payload = [ $payload = [
'error' => $this->errorType, 'error' => $this->errorType,
'message' => $this->getMessage() 'message' => $this->getMessage(),
]; ];
if ($this->hint !== null) { if ($this->hint !== null) {
@ -264,14 +265,14 @@ class OAuthServerException extends \Exception
} }
/** /**
* Get all headers that have to be send with the error response * Get all headers that have to be send with the error response.
* *
* @return array Array with header values * @return array Array with header values
*/ */
public function getHttpHeaders() public function getHttpHeaders()
{ {
$headers = [ $headers = [
'Content-type' => 'application/json' 'Content-type' => 'application/json',
]; ];
// Add "WWW-Authenticate" header // Add "WWW-Authenticate" header
@ -303,7 +304,7 @@ class OAuthServerException extends \Exception
} }
} }
if ($authScheme !== null) { if ($authScheme !== null) {
$headers[] = 'WWW-Authenticate: ' . $authScheme . ' realm="OAuth"'; $headers[] = 'WWW-Authenticate: '.$authScheme.' realm="OAuth"';
} }
} }
@ -312,7 +313,7 @@ class OAuthServerException extends \Exception
} }
/** /**
* Returns the HTTP status code to send when the exceptions is output * Returns the HTTP status code to send when the exceptions is output.
* *
* @return int * @return int
*/ */

View File

@ -1,14 +1,13 @@
<?php <?php
/** /**
* OAuth 2.0 Abstract grant * OAuth 2.0 Abstract grant.
* *
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com> * @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie * @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/ * @license http://mit-license.org/
*
* @link https://github.com/thephpleague/oauth2-server * @link https://github.com/thephpleague/oauth2-server
*/ */
namespace League\OAuth2\Server\Grant; namespace League\OAuth2\Server\Grant;
use League\Event\EmitterAwareTrait; use League\Event\EmitterAwareTrait;
@ -29,7 +28,7 @@ use OAuth2ServerExamples\Repositories\AuthCodeRepository;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
/** /**
* Abstract grant class * Abstract grant class.
*/ */
abstract class AbstractGrant implements GrantTypeInterface abstract class AbstractGrant implements GrantTypeInterface
{ {
@ -139,7 +138,7 @@ abstract class AbstractGrant implements GrantTypeInterface
} }
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function setEmitter(EmitterInterface $emitter = null) public function setEmitter(EmitterInterface $emitter = null)
{ {
@ -147,7 +146,7 @@ abstract class AbstractGrant implements GrantTypeInterface
} }
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function setRefreshTokenTTL(\DateInterval $refreshTokenTTL) public function setRefreshTokenTTL(\DateInterval $refreshTokenTTL)
{ {
@ -171,12 +170,13 @@ abstract class AbstractGrant implements GrantTypeInterface
} }
/** /**
* Validate the client * Validate the client.
* *
* @param \Psr\Http\Message\ServerRequestInterface $request * @param \Psr\Http\Message\ServerRequestInterface $request
* *
* @return \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface
* @throws \League\OAuth2\Server\Exception\OAuthServerException * @throws \League\OAuth2\Server\Exception\OAuthServerException
*
* @return \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface
*/ */
protected function validateClient(ServerRequestInterface $request) protected function validateClient(ServerRequestInterface $request)
{ {
@ -224,15 +224,15 @@ abstract class AbstractGrant implements GrantTypeInterface
} }
/** /**
* Validate scopes in the request * Validate scopes in the request.
* *
* @param \Psr\Http\Message\ServerRequestInterface $request * @param \Psr\Http\Message\ServerRequestInterface $request
* @param \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface $client * @param \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface $client
* @param string $redirectUri * @param string $redirectUri
* *
* @return \League\OAuth2\Server\Entities\ScopeEntity[]
*
* @throws \League\OAuth2\Server\Exception\OAuthServerException * @throws \League\OAuth2\Server\Exception\OAuthServerException
*
* @return \League\OAuth2\Server\Entities\ScopeEntity[]
*/ */
public function validateScopes( public function validateScopes(
ServerRequestInterface $request, ServerRequestInterface $request,
@ -322,7 +322,7 @@ abstract class AbstractGrant implements GrantTypeInterface
} }
/** /**
* Issue an access token * Issue an access token.
* *
* @param \DateInterval $tokenTTL * @param \DateInterval $tokenTTL
* @param \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface $client * @param \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface $client
@ -353,7 +353,7 @@ abstract class AbstractGrant implements GrantTypeInterface
} }
/** /**
* Issue an auth code * Issue an auth code.
* *
* @param \DateInterval $tokenTTL * @param \DateInterval $tokenTTL
* @param \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface $client * @param \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface $client
@ -361,8 +361,9 @@ abstract class AbstractGrant implements GrantTypeInterface
* @param string $redirectUri * @param string $redirectUri
* @param array $scopes * @param array $scopes
* *
* @return \League\OAuth2\Server\Entities\AuthCodeEntity
* @throws \League\OAuth2\Server\Exception\OAuthServerException * @throws \League\OAuth2\Server\Exception\OAuthServerException
*
* @return \League\OAuth2\Server\Entities\AuthCodeEntity
*/ */
protected function issueAuthCode( protected function issueAuthCode(
\DateInterval $tokenTTL, \DateInterval $tokenTTL,
@ -405,13 +406,13 @@ abstract class AbstractGrant implements GrantTypeInterface
} }
/** /**
* Generate a new unique identifier * Generate a new unique identifier.
* *
* @param int $length * @param int $length
* *
* @return string
*
* @throws \League\OAuth2\Server\Exception\OAuthServerException * @throws \League\OAuth2\Server\Exception\OAuthServerException
*
* @return string
*/ */
protected function generateUniqueIdentifier($length = 40) protected function generateUniqueIdentifier($length = 40)
{ {
@ -430,13 +431,12 @@ abstract class AbstractGrant implements GrantTypeInterface
} }
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function canRespondToRequest(ServerRequestInterface $request) public function canRespondToRequest(ServerRequestInterface $request)
{ {
return ( return
isset($request->getParsedBody()['grant_type']) isset($request->getParsedBody()['grant_type'])
&& $request->getParsedBody()['grant_type'] === $this->getIdentifier() && $request->getParsedBody()['grant_type'] === $this->getIdentifier();
);
} }
} }

View File

@ -3,6 +3,7 @@
namespace League\OAuth2\Server\Grant; namespace League\OAuth2\Server\Grant;
use DateInterval; use DateInterval;
use League\Event\Event;
use League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface; use League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface;
use League\OAuth2\Server\Entities\Interfaces\UserEntityInterface; use League\OAuth2\Server\Entities\Interfaces\UserEntityInterface;
use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Exception\OAuthServerException;
@ -12,7 +13,6 @@ use League\OAuth2\Server\Repositories\UserRepositoryInterface;
use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface; use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
use League\OAuth2\Server\Utils\KeyCrypt; use League\OAuth2\Server\Utils\KeyCrypt;
use League\Plates\Engine; use League\Plates\Engine;
use League\Event\Event;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
use Zend\Diactoros\Uri; use Zend\Diactoros\Uri;
@ -39,7 +39,6 @@ class AuthCodeGrant extends AbstractGrant
*/ */
private $pathToAuthorizeTemplate; private $pathToAuthorizeTemplate;
/** /**
* @param \League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface $authCodeRepository * @param \League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface $authCodeRepository
* @param \League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface $refreshTokenRepository * @param \League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface $refreshTokenRepository
@ -61,22 +60,22 @@ class AuthCodeGrant extends AbstractGrant
$this->userRepository = $userRepository; $this->userRepository = $userRepository;
$this->authCodeTTL = $authCodeTTL; $this->authCodeTTL = $authCodeTTL;
$this->pathToLoginTemplate = ($pathToLoginTemplate === null) $this->pathToLoginTemplate = ($pathToLoginTemplate === null)
? __DIR__ . '/../ResponseTypes/DefaultTemplates/login_user.php' ? __DIR__.'/../ResponseTypes/DefaultTemplates/login_user.php'
: $this->pathToLoginTemplate; : $this->pathToLoginTemplate;
$this->pathToAuthorizeTemplate = ($pathToLoginTemplate === null) $this->pathToAuthorizeTemplate = ($pathToLoginTemplate === null)
? __DIR__ . '/../ResponseTypes/DefaultTemplates/authorize_client.php' ? __DIR__.'/../ResponseTypes/DefaultTemplates/authorize_client.php'
: $this->pathToAuthorizeTemplate; : $this->pathToAuthorizeTemplate;
$this->refreshTokenTTL = new \DateInterval('P1M'); $this->refreshTokenTTL = new \DateInterval('P1M');
} }
/** /**
* Respond to an authorization request * Respond to an authorization request.
* *
* @param \Psr\Http\Message\ServerRequestInterface $request * @param \Psr\Http\Message\ServerRequestInterface $request
* *
* @return \Psr\Http\Message\ResponseInterface
* @throws \League\OAuth2\Server\Exception\OAuthServerException * @throws \League\OAuth2\Server\Exception\OAuthServerException
*
* @return \Psr\Http\Message\ResponseInterface
*/ */
protected function respondToAuthorizationRequest( protected function respondToAuthorizationRequest(
ServerRequestInterface $request ServerRequestInterface $request
@ -153,7 +152,6 @@ class AuthCodeGrant extends AbstractGrant
return new Response\HtmlResponse($html); return new Response\HtmlResponse($html);
} }
// The user hasn't approved the client yet so show an authorize form // The user hasn't approved the client yet so show an authorize form
if ($userId !== null && $userHasApprovedClient === null) { if ($userId !== null && $userHasApprovedClient === null) {
$engine = new Engine(dirname($this->pathToAuthorizeTemplate)); $engine = new Engine(dirname($this->pathToAuthorizeTemplate));
@ -219,18 +217,20 @@ class AuthCodeGrant extends AbstractGrant
} }
$exception = OAuthServerException::accessDenied('The user denied the request', (string) $redirectUri); $exception = OAuthServerException::accessDenied('The user denied the request', (string) $redirectUri);
return $exception->generateHttpResponse(); return $exception->generateHttpResponse();
} }
/** /**
* Respond to an access token request * Respond to an access token request.
* *
* @param \Psr\Http\Message\ServerRequestInterface $request * @param \Psr\Http\Message\ServerRequestInterface $request
* @param \League\OAuth2\Server\ResponseTypes\ResponseTypeInterface $responseType * @param \League\OAuth2\Server\ResponseTypes\ResponseTypeInterface $responseType
* @param \DateInterval $accessTokenTTL * @param \DateInterval $accessTokenTTL
* *
* @return \League\OAuth2\Server\ResponseTypes\ResponseTypeInterface
* @throws \League\OAuth2\Server\Exception\OAuthServerException * @throws \League\OAuth2\Server\Exception\OAuthServerException
*
* @return \League\OAuth2\Server\ResponseTypes\ResponseTypeInterface
*/ */
protected function respondToAccessTokenRequest( protected function respondToAccessTokenRequest(
ServerRequestInterface $request, ServerRequestInterface $request,
@ -286,21 +286,20 @@ class AuthCodeGrant extends AbstractGrant
} }
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function canRespondToRequest(ServerRequestInterface $request) public function canRespondToRequest(ServerRequestInterface $request)
{ {
return ( return
( (
isset($request->getQueryParams()['response_type']) isset($request->getQueryParams()['response_type'])
&& $request->getQueryParams()['response_type'] === 'code' && $request->getQueryParams()['response_type'] === 'code'
&& isset($request->getQueryParams()['client_id']) && isset($request->getQueryParams()['client_id'])
) || (parent::canRespondToRequest($request)) ) || (parent::canRespondToRequest($request));
);
} }
/** /**
* Return the grant identifier that can be used in matching up requests * Return the grant identifier that can be used in matching up requests.
* *
* @return string * @return string
*/ */
@ -310,7 +309,7 @@ class AuthCodeGrant extends AbstractGrant
} }
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function respondToRequest( public function respondToRequest(
ServerRequestInterface $request, ServerRequestInterface $request,

View File

@ -1,26 +1,25 @@
<?php <?php
/** /**
* OAuth 2.0 Client credentials grant * OAuth 2.0 Client credentials grant.
* *
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com> * @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie * @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/ * @license http://mit-license.org/
*
* @link https://github.com/thephpleague/oauth2-server * @link https://github.com/thephpleague/oauth2-server
*/ */
namespace League\OAuth2\Server\Grant; namespace League\OAuth2\Server\Grant;
use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface; use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
/** /**
* Client credentials grant class * Client credentials grant class.
*/ */
class ClientCredentialsGrant extends AbstractGrant class ClientCredentialsGrant extends AbstractGrant
{ {
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function respondToRequest( public function respondToRequest(
ServerRequestInterface $request, ServerRequestInterface $request,
@ -41,7 +40,7 @@ class ClientCredentialsGrant extends AbstractGrant
} }
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function getIdentifier() public function getIdentifier()
{ {

View File

@ -1,14 +1,13 @@
<?php <?php
/** /**
* OAuth 2.0 Grant type interface * OAuth 2.0 Grant type interface.
* *
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com> * @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie * @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/ * @license http://mit-license.org/
*
* @link https://github.com/thephpleague/oauth2-server * @link https://github.com/thephpleague/oauth2-server
*/ */
namespace League\OAuth2\Server\Grant; namespace League\OAuth2\Server\Grant;
use League\Event\EmitterAwareInterface; use League\Event\EmitterAwareInterface;
@ -19,26 +18,26 @@ use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
/** /**
* Grant type interface * Grant type interface.
*/ */
interface GrantTypeInterface extends EmitterAwareInterface interface GrantTypeInterface extends EmitterAwareInterface
{ {
/** /**
* Set refresh token TTL * Set refresh token TTL.
* *
* @param \DateInterval $refreshTokenTTL * @param \DateInterval $refreshTokenTTL
*/ */
public function setRefreshTokenTTL(\DateInterval $refreshTokenTTL); public function setRefreshTokenTTL(\DateInterval $refreshTokenTTL);
/** /**
* Return the grant identifier that can be used in matching up requests * Return the grant identifier that can be used in matching up requests.
* *
* @return string * @return string
*/ */
public function getIdentifier(); public function getIdentifier();
/** /**
* Respond to an incoming request * Respond to an incoming request.
* *
* @param \Psr\Http\Message\ServerRequestInterface $request * @param \Psr\Http\Message\ServerRequestInterface $request
* @param \League\OAuth2\Server\ResponseTypes\ResponseTypeInterface $responseType * @param \League\OAuth2\Server\ResponseTypes\ResponseTypeInterface $responseType
@ -62,40 +61,40 @@ interface GrantTypeInterface extends EmitterAwareInterface
* *
* @param \Psr\Http\Message\ServerRequestInterface $request * @param \Psr\Http\Message\ServerRequestInterface $request
* *
* @return boolean * @return bool
*/ */
public function canRespondToRequest(ServerRequestInterface $request); public function canRespondToRequest(ServerRequestInterface $request);
/** /**
* Set the client repository * Set the client repository.
* *
* @param \League\OAuth2\Server\Repositories\ClientRepositoryInterface $clientRepository * @param \League\OAuth2\Server\Repositories\ClientRepositoryInterface $clientRepository
*/ */
public function setClientRepository(ClientRepositoryInterface $clientRepository); public function setClientRepository(ClientRepositoryInterface $clientRepository);
/** /**
* Set the access token repository * Set the access token repository.
* *
* @param \League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface $accessTokenRepository * @param \League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface $accessTokenRepository
*/ */
public function setAccessTokenRepository(AccessTokenRepositoryInterface $accessTokenRepository); public function setAccessTokenRepository(AccessTokenRepositoryInterface $accessTokenRepository);
/** /**
* Set the scope repository * Set the scope repository.
* *
* @param \League\OAuth2\Server\Repositories\ScopeRepositoryInterface $scopeRepository * @param \League\OAuth2\Server\Repositories\ScopeRepositoryInterface $scopeRepository
*/ */
public function setScopeRepository(ScopeRepositoryInterface $scopeRepository); public function setScopeRepository(ScopeRepositoryInterface $scopeRepository);
/** /**
* Set the path to the private key * Set the path to the private key.
* *
* @param string $pathToPrivateKey * @param string $pathToPrivateKey
*/ */
public function setPathToPrivateKey($pathToPrivateKey); public function setPathToPrivateKey($pathToPrivateKey);
/** /**
* Set the path to the public key * Set the path to the public key.
* *
* @param string $pathToPublicKey * @param string $pathToPublicKey
*/ */

View File

@ -1,14 +1,13 @@
<?php <?php
/** /**
* OAuth 2.0 Password grant * OAuth 2.0 Password grant.
* *
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com> * @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie * @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/ * @license http://mit-license.org/
*
* @link https://github.com/thephpleague/oauth2-server * @link https://github.com/thephpleague/oauth2-server
*/ */
namespace League\OAuth2\Server\Grant; namespace League\OAuth2\Server\Grant;
use League\Event\Event; use League\Event\Event;
@ -20,7 +19,7 @@ use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
/** /**
* Password grant class * Password grant class.
*/ */
class PasswordGrant extends AbstractGrant class PasswordGrant extends AbstractGrant
{ {
@ -44,7 +43,7 @@ class PasswordGrant extends AbstractGrant
} }
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function respondToRequest( public function respondToRequest(
ServerRequestInterface $request, ServerRequestInterface $request,
@ -53,7 +52,7 @@ class PasswordGrant extends AbstractGrant
) { ) {
// Validate request // Validate request
$client = $this->validateClient($request); $client = $this->validateClient($request);
$user = $this->validateUser($request); $user = $this->validateUser($request);
$scopes = $this->validateScopes($request, $client); $scopes = $this->validateScopes($request, $client);
// Issue and persist new tokens // Issue and persist new tokens
@ -70,9 +69,9 @@ class PasswordGrant extends AbstractGrant
/** /**
* @param \Psr\Http\Message\ServerRequestInterface $request * @param \Psr\Http\Message\ServerRequestInterface $request
* *
* @return \League\OAuth2\Server\Entities\Interfaces\UserEntityInterface
*
* @throws \League\OAuth2\Server\Exception\OAuthServerException * @throws \League\OAuth2\Server\Exception\OAuthServerException
*
* @return \League\OAuth2\Server\Entities\Interfaces\UserEntityInterface
*/ */
protected function validateUser(ServerRequestInterface $request) protected function validateUser(ServerRequestInterface $request)
{ {
@ -97,7 +96,7 @@ class PasswordGrant extends AbstractGrant
} }
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function getIdentifier() public function getIdentifier()
{ {

View File

@ -1,14 +1,13 @@
<?php <?php
/** /**
* OAuth 2.0 Refresh token grant * OAuth 2.0 Refresh token grant.
* *
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com> * @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie * @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/ * @license http://mit-license.org/
*
* @link https://github.com/thephpleague/oauth2-server * @link https://github.com/thephpleague/oauth2-server
*/ */
namespace League\OAuth2\Server\Grant; namespace League\OAuth2\Server\Grant;
use League\Event\Event; use League\Event\Event;
@ -20,7 +19,7 @@ use League\OAuth2\Server\Utils\KeyCrypt;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
/** /**
* Refresh token grant * Refresh token grant.
*/ */
class RefreshTokenGrant extends AbstractGrant class RefreshTokenGrant extends AbstractGrant
{ {
@ -35,7 +34,7 @@ class RefreshTokenGrant extends AbstractGrant
} }
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function respondToRequest( public function respondToRequest(
ServerRequestInterface $request, ServerRequestInterface $request,
@ -52,6 +51,7 @@ class RefreshTokenGrant extends AbstractGrant
$scopes = array_map(function ($scopeId) { $scopes = array_map(function ($scopeId) {
$scope = new ScopeEntity(); $scope = new ScopeEntity();
$scope->setIdentifier($scopeId); $scope->setIdentifier($scopeId);
return $scope; return $scope;
}, $oldRefreshToken['scopes']); }, $oldRefreshToken['scopes']);
} else { } else {
@ -87,9 +87,9 @@ class RefreshTokenGrant extends AbstractGrant
* @param \Psr\Http\Message\ServerRequestInterface $request * @param \Psr\Http\Message\ServerRequestInterface $request
* @param string $clientId * @param string $clientId
* *
* @return array
*
* @throws \League\OAuth2\Server\Exception\OAuthServerException * @throws \League\OAuth2\Server\Exception\OAuthServerException
*
* @return array
*/ */
protected function validateOldRefreshToken(ServerRequestInterface $request, $clientId) protected function validateOldRefreshToken(ServerRequestInterface $request, $clientId)
{ {
@ -102,7 +102,7 @@ class RefreshTokenGrant extends AbstractGrant
try { try {
$refreshToken = KeyCrypt::decrypt($encryptedRefreshToken, $this->pathToPublicKey); $refreshToken = KeyCrypt::decrypt($encryptedRefreshToken, $this->pathToPublicKey);
} catch (\LogicException $e) { } catch (\LogicException $e) {
throw OAuthServerException::invalidRefreshToken('Cannot parse refresh token: ' . $e->getMessage()); throw OAuthServerException::invalidRefreshToken('Cannot parse refresh token: '.$e->getMessage());
} }
$refreshTokenData = json_decode($refreshToken, true); $refreshTokenData = json_decode($refreshToken, true);
@ -110,9 +110,9 @@ class RefreshTokenGrant extends AbstractGrant
$this->getEmitter()->emit(new Event('refresh_token.client.failed', $request)); $this->getEmitter()->emit(new Event('refresh_token.client.failed', $request));
throw OAuthServerException::invalidRefreshToken( throw OAuthServerException::invalidRefreshToken(
'Token is not linked to client,' . 'Token is not linked to client,'.
' got: ' . $clientId . ' got: '.$clientId.
' expected: ' . $refreshTokenData['client_id'] ' expected: '.$refreshTokenData['client_id']
); );
} }
@ -128,7 +128,7 @@ class RefreshTokenGrant extends AbstractGrant
} }
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function getIdentifier() public function getIdentifier()
{ {

View File

@ -1,39 +1,38 @@
<?php <?php
/** /**
* OAuth 2.0 Access token storage interface * OAuth 2.0 Access token storage interface.
* *
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com> * @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie * @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/ * @license http://mit-license.org/
*
* @link https://github.com/thephpleague/oauth2-server * @link https://github.com/thephpleague/oauth2-server
*/ */
namespace League\OAuth2\Server\Repositories; namespace League\OAuth2\Server\Repositories;
use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface;
/** /**
* Access token interface * Access token interface.
*/ */
interface AccessTokenRepositoryInterface extends RepositoryInterface interface AccessTokenRepositoryInterface extends RepositoryInterface
{ {
/** /**
* Persists a new access token to permanent storage * Persists a new access token to permanent storage.
* *
* @param \League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface $accessTokenEntity * @param \League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface $accessTokenEntity
*/ */
public function persistNewAccessToken(AccessTokenEntityInterface $accessTokenEntity); public function persistNewAccessToken(AccessTokenEntityInterface $accessTokenEntity);
/** /**
* Revoke an access token * Revoke an access token.
* *
* @param string $tokenId * @param string $tokenId
*/ */
public function revokeAccessToken($tokenId); public function revokeAccessToken($tokenId);
/** /**
* Check if the access token has been revoked * Check if the access token has been revoked.
* *
* @param string $tokenId * @param string $tokenId
* *

View File

@ -1,39 +1,38 @@
<?php <?php
/** /**
* OAuth 2.0 Auth code storage interface * OAuth 2.0 Auth code storage interface.
* *
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com> * @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie * @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/ * @license http://mit-license.org/
*
* @link https://github.com/thephpleague/oauth2-server * @link https://github.com/thephpleague/oauth2-server
*/ */
namespace League\OAuth2\Server\Repositories; namespace League\OAuth2\Server\Repositories;
use League\OAuth2\Server\Entities\Interfaces\AuthCodeEntityInterface; use League\OAuth2\Server\Entities\Interfaces\AuthCodeEntityInterface;
/** /**
* Auth code storage interface * Auth code storage interface.
*/ */
interface AuthCodeRepositoryInterface extends RepositoryInterface interface AuthCodeRepositoryInterface extends RepositoryInterface
{ {
/** /**
* Persists a new auth code to permanent storage * Persists a new auth code to permanent storage.
* *
* @param \League\OAuth2\Server\Entities\Interfaces\AuthCodeEntityInterface $authCodeEntity * @param \League\OAuth2\Server\Entities\Interfaces\AuthCodeEntityInterface $authCodeEntity
*/ */
public function persistNewAuthCode(AuthCodeEntityInterface $authCodeEntity); public function persistNewAuthCode(AuthCodeEntityInterface $authCodeEntity);
/** /**
* Revoke an auth code * Revoke an auth code.
* *
* @param string $codeId * @param string $codeId
*/ */
public function revokeAuthCode($codeId); public function revokeAuthCode($codeId);
/** /**
* Check if the auth code has been revoked * Check if the auth code has been revoked.
* *
* @param string $codeId * @param string $codeId
* *

View File

@ -1,26 +1,25 @@
<?php <?php
/** /**
* OAuth 2.0 Client storage interface * OAuth 2.0 Client storage interface.
* *
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com> * @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie * @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/ * @license http://mit-license.org/
*
* @link https://github.com/thephpleague/oauth2-server * @link https://github.com/thephpleague/oauth2-server
*/ */
namespace League\OAuth2\Server\Repositories; namespace League\OAuth2\Server\Repositories;
/** /**
* Client storage interface * Client storage interface.
*/ */
interface ClientRepositoryInterface extends RepositoryInterface interface ClientRepositoryInterface extends RepositoryInterface
{ {
/** /**
* Get a client * Get a client.
* *
* @param string $clientIdentifier The client's identifier * @param string $clientIdentifier The client's identifier
* @param string $grantType The grant type used * @param string $grantType The grant type used
* *
* @return \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface * @return \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface
*/ */

View File

@ -1,25 +1,24 @@
<?php <?php
/** /**
* OAuth 2.0 MAC Token Interface * OAuth 2.0 MAC Token Interface.
* *
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com> * @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie * @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/ * @license http://mit-license.org/
*
* @link https://github.com/thephpleague/oauth2-server * @link https://github.com/thephpleague/oauth2-server
*/ */
namespace League\OAuth2\Server\Storage; namespace League\OAuth2\Server\Storage;
use League\OAuth2\Server\Repositories\RepositoryInterface; use League\OAuth2\Server\Repositories\RepositoryInterface;
/** /**
* MacTokenInterface * MacTokenInterface.
*/ */
interface MacTokenInterface extends RepositoryInterface interface MacTokenInterface extends RepositoryInterface
{ {
/** /**
* Create a MAC key linked to an access token * Create a MAC key linked to an access token.
* *
* @param string $macKey * @param string $macKey
* @param string $accessToken * @param string $accessToken
@ -27,9 +26,9 @@ interface MacTokenInterface extends RepositoryInterface
public function persistMacTokenEntity($macKey, $accessToken); public function persistMacTokenEntity($macKey, $accessToken);
/** /**
* Get a MAC key by access token * Get a MAC key by access token.
* *
* @param string $accessToken * @param string $accessToken
* *
* @return string * @return string
*/ */

View File

@ -1,39 +1,38 @@
<?php <?php
/** /**
* OAuth 2.0 Refresh token storage interface * OAuth 2.0 Refresh token storage interface.
* *
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com> * @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie * @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/ * @license http://mit-license.org/
*
* @link https://github.com/thephpleague/oauth2-server * @link https://github.com/thephpleague/oauth2-server
*/ */
namespace League\OAuth2\Server\Repositories; namespace League\OAuth2\Server\Repositories;
use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface; use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface;
/** /**
* Refresh token interface * Refresh token interface.
*/ */
interface RefreshTokenRepositoryInterface extends RepositoryInterface interface RefreshTokenRepositoryInterface extends RepositoryInterface
{ {
/** /**
* Create a new refresh token_name * Create a new refresh token_name.
* *
* @param \League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface $refreshTokenEntity * @param \League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface $refreshTokenEntity
*/ */
public function persistNewRefreshToken(RefreshTokenEntityInterface $refreshTokenEntity); public function persistNewRefreshToken(RefreshTokenEntityInterface $refreshTokenEntity);
/** /**
* Revoke the refresh token * Revoke the refresh token.
* *
* @param string $tokenId * @param string $tokenId
*/ */
public function revokeRefreshToken($tokenId); public function revokeRefreshToken($tokenId);
/** /**
* Check if the refresh token has been revoked * Check if the refresh token has been revoked.
* *
* @param string $tokenId * @param string $tokenId
* *

View File

@ -1,18 +1,17 @@
<?php <?php
/** /**
* OAuth 2.0 Repository interface * OAuth 2.0 Repository interface.
* *
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com> * @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie * @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/ * @license http://mit-license.org/
*
* @link https://github.com/thephpleague/oauth2-server * @link https://github.com/thephpleague/oauth2-server
*/ */
namespace League\OAuth2\Server\Repositories; namespace League\OAuth2\Server\Repositories;
/** /**
* Repository interface * Repository interface.
*/ */
interface RepositoryInterface interface RepositoryInterface
{ {

View File

@ -1,23 +1,22 @@
<?php <?php
/** /**
* OAuth 2.0 Scope storage interface * OAuth 2.0 Scope storage interface.
* *
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com> * @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie * @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/ * @license http://mit-license.org/
*
* @link https://github.com/thephpleague/oauth2-server * @link https://github.com/thephpleague/oauth2-server
*/ */
namespace League\OAuth2\Server\Repositories; namespace League\OAuth2\Server\Repositories;
/** /**
* Scope interface * Scope interface.
*/ */
interface ScopeRepositoryInterface extends RepositoryInterface interface ScopeRepositoryInterface extends RepositoryInterface
{ {
/** /**
* Return information about a scope * Return information about a scope.
* *
* @param string $identifier The scope identifier * @param string $identifier The scope identifier
* @param string $grantType The grant type used in the request * @param string $grantType The grant type used in the request

View File

@ -5,7 +5,7 @@ namespace League\OAuth2\Server\Repositories;
interface UserRepositoryInterface extends RepositoryInterface interface UserRepositoryInterface extends RepositoryInterface
{ {
/** /**
* Get a user entity * Get a user entity.
* *
* @param string $username * @param string $username
* @param string $password * @param string $password

View File

@ -1,14 +1,13 @@
<?php <?php
/** /**
* OAuth 2.0 Abstract Response Type * OAuth 2.0 Abstract Response Type.
* *
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com> * @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie * @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/ * @license http://mit-license.org/
*
* @link https://github.com/thephpleague/oauth2-server * @link https://github.com/thephpleague/oauth2-server
*/ */
namespace League\OAuth2\Server\ResponseTypes; namespace League\OAuth2\Server\ResponseTypes;
use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface;

View File

@ -1,14 +1,13 @@
<?php <?php
/** /**
* OAuth 2.0 Bearer Token Type * OAuth 2.0 Bearer Token Type.
* *
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com> * @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie * @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/ * @license http://mit-license.org/
*
* @link https://github.com/thephpleague/oauth2-server * @link https://github.com/thephpleague/oauth2-server
*/ */
namespace League\OAuth2\Server\ResponseTypes; namespace League\OAuth2\Server\ResponseTypes;
use Lcobucci\JWT\Builder; use Lcobucci\JWT\Builder;
@ -43,7 +42,7 @@ class BearerTokenResponse extends AbstractResponseType
$responseParams = [ $responseParams = [
'token_type' => 'Bearer', 'token_type' => 'Bearer',
'expires_in' => $expireDateTime - (new \DateTime)->getTimestamp(), 'expires_in' => $expireDateTime - (new \DateTime())->getTimestamp(),
'access_token' => (string) $jwtAccessToken, 'access_token' => (string) $jwtAccessToken,
]; ];

View File

@ -1,14 +1,13 @@
<?php <?php
/** /**
* OAuth 2.0 MAC Token Type * OAuth 2.0 MAC Token Type.
* *
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com> * @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie * @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/ * @license http://mit-license.org/
*
* @link https://github.com/thephpleague/oauth2-server * @link https://github.com/thephpleague/oauth2-server
*/ */
namespace League\OAuth2\Server\TokenTypes; namespace League\OAuth2\Server\TokenTypes;
use League\OAuth2\Server\Util\SecureKey; use League\OAuth2\Server\Util\SecureKey;
@ -16,7 +15,7 @@ use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
/** /**
* MAC Token Type * MAC Token Type.
*/ */
class MAC extends AbstractTokenType implements TokenTypeInterface class MAC extends AbstractTokenType implements TokenTypeInterface
{ {
@ -29,11 +28,11 @@ class MAC extends AbstractTokenType implements TokenTypeInterface
$this->server->getMacStorage()->create($macKey, $this->getParam('access_token')); $this->server->getMacStorage()->create($macKey, $this->getParam('access_token'));
$response = [ $response = [
'access_token' => $this->getParam('access_token'), 'access_token' => $this->getParam('access_token'),
'token_type' => 'mac', 'token_type' => 'mac',
'expires_in' => $this->getParam('expires_in'), 'expires_in' => $this->getParam('expires_in'),
'mac_key' => $macKey, 'mac_key' => $macKey,
'mac_algorithm' => 'hmac-sha-256', 'mac_algorithm' => 'hmac-sha-256',
]; ];
return $response; return $response;
@ -121,9 +120,11 @@ class MAC extends AbstractTokenType implements TokenTypeInterface
} }
/** /**
* Prevent timing attack * Prevent timing attack.
* @param string $knownString *
* @param string $userString * @param string $knownString
* @param string $userString
*
* @return bool * @return bool
*/ */
private function hash_equals($knownString, $userString) private function hash_equals($knownString, $userString)

View File

@ -1,14 +1,13 @@
<?php <?php
/** /**
* OAuth 2.0 Response Type Interface * OAuth 2.0 Response Type Interface.
* *
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com> * @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie * @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/ * @license http://mit-license.org/
*
* @link https://github.com/thephpleague/oauth2-server * @link https://github.com/thephpleague/oauth2-server
*/ */
namespace League\OAuth2\Server\ResponseTypes; namespace League\OAuth2\Server\ResponseTypes;
use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface;
@ -30,7 +29,7 @@ interface ResponseTypeInterface
/** /**
* Determine the access token in the authorization header and append OAUth properties to the request * Determine the access token in the authorization header and append OAUth properties to the request
* as attributes * as attributes.
* *
* @param ServerRequestInterface $request * @param ServerRequestInterface $request
* *

View File

@ -62,7 +62,7 @@ class Server implements EmitterAwareInterface
private $scopeRepository; private $scopeRepository;
/** /**
* New server instance * New server instance.
* *
* @param \League\OAuth2\Server\Repositories\ClientRepositoryInterface $clientRepository * @param \League\OAuth2\Server\Repositories\ClientRepositoryInterface $clientRepository
* @param \League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface $accessTokenRepository * @param \League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface $accessTokenRepository
@ -88,7 +88,7 @@ class Server implements EmitterAwareInterface
} }
/** /**
* Enable a grant type on the server * Enable a grant type on the server.
* *
* @param \League\OAuth2\Server\Grant\GrantTypeInterface $grantType * @param \League\OAuth2\Server\Grant\GrantTypeInterface $grantType
* @param \DateInterval $accessTokenTTL * @param \DateInterval $accessTokenTTL
@ -108,13 +108,14 @@ class Server implements EmitterAwareInterface
} }
/** /**
* Return an access token response * Return an access token response.
* *
* @param \Psr\Http\Message\ServerRequestInterface|null $request * @param \Psr\Http\Message\ServerRequestInterface|null $request
* @param \Psr\Http\Message\ResponseInterface|null $response * @param \Psr\Http\Message\ResponseInterface|null $response
* *
* @return \Psr\Http\Message\ResponseInterface
* @throws \League\OAuth2\Server\Exception\OAuthServerException * @throws \League\OAuth2\Server\Exception\OAuthServerException
*
* @return \Psr\Http\Message\ResponseInterface
*/ */
public function respondToRequest(ServerRequestInterface $request = null, ResponseInterface $response = null) public function respondToRequest(ServerRequestInterface $request = null, ResponseInterface $response = null)
{ {
@ -149,13 +150,13 @@ class Server implements EmitterAwareInterface
} }
/** /**
* Determine the access token validity * Determine the access token validity.
* *
* @param \Psr\Http\Message\ServerRequestInterface $request * @param \Psr\Http\Message\ServerRequestInterface $request
* *
* @return \Psr\Http\Message\ServerRequestInterface
*
* @throws \League\OAuth2\Server\Exception\OAuthServerException * @throws \League\OAuth2\Server\Exception\OAuthServerException
*
* @return \Psr\Http\Message\ServerRequestInterface
*/ */
public function validateRequest(ServerRequestInterface $request) public function validateRequest(ServerRequestInterface $request)
{ {
@ -163,7 +164,7 @@ class Server implements EmitterAwareInterface
} }
/** /**
* Get the token type that grants will return in the HTTP response * Get the token type that grants will return in the HTTP response.
* *
* @return ResponseTypeInterface * @return ResponseTypeInterface
*/ */

View File

@ -1,20 +1,19 @@
<?php <?php
/** /**
* Public/private key encryption * Public/private key encryption.
* *
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com> * @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie * @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/ * @license http://mit-license.org/
*
* @link https://github.com/thephpleague/oauth2-server * @link https://github.com/thephpleague/oauth2-server
*/ */
namespace League\OAuth2\Server\Utils; namespace League\OAuth2\Server\Utils;
class KeyCrypt class KeyCrypt
{ {
/** /**
* Encrypt data with a private key * Encrypt data with a private key.
* *
* @param string $unencryptedData * @param string $unencryptedData
* @param string $pathToPrivateKey * @param string $pathToPrivateKey
@ -48,7 +47,7 @@ class KeyCrypt
} }
/** /**
* Decrypt data with a public key * Decrypt data with a public key.
* *
* @param string $encryptedData * @param string $encryptedData
* @param string $pathToPublicKey * @param string $pathToPublicKey

View File

@ -1,31 +1,30 @@
<?php <?php
/** /**
* OAuth 2.0 Secure key generator * OAuth 2.0 Secure key generator.
* *
* @package php-loep/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com> * @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) 2013 PHP League of Extraordinary Packages * @copyright Copyright (c) 2013 PHP League of Extraordinary Packages
* @license http://mit-license.org/ * @license http://mit-license.org/
*
* @link http://github.com/php-loep/oauth2-server * @link http://github.com/php-loep/oauth2-server
*/ */
namespace League\OAuth2\Server\Utils; namespace League\OAuth2\Server\Utils;
use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Exception\OAuthServerException;
/** /**
* SecureKey class * SecureKey class.
*/ */
class SecureKey class SecureKey
{ {
/** /**
* Generate a new unique code * Generate a new unique code.
* *
* @param integer $len Length of the generated code * @param int $len Length of the generated code
*
* @throws \League\OAuth2\Server\Exception\OAuthServerException
* *
* @return string * @return string
* @throws \League\OAuth2\Server\Exception\OAuthServerException
*/ */
public static function generate($len = 40) public static function generate($len = 40)
{ {
@ -34,13 +33,13 @@ class SecureKey
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
} catch (\TypeError $e) { } catch (\TypeError $e) {
// Well, it's an integer, so this IS unexpected. // Well, it's an integer, so this IS unexpected.
throw OAuthServerException::serverError("An unexpected error has occurred"); throw OAuthServerException::serverError('An unexpected error has occurred');
} catch (\Error $e) { } catch (\Error $e) {
// This is also unexpected because 32 is a reasonable integer. // This is also unexpected because 32 is a reasonable integer.
throw OAuthServerException::serverError("An unexpected error has occurred"); throw OAuthServerException::serverError('An unexpected error has occurred');
} catch (\Exception $e) { } catch (\Exception $e) {
// If you get this message, the CSPRNG failed hard. // If you get this message, the CSPRNG failed hard.
throw OAuthServerException::serverError("Could not generate a random string. Is our OS secure?"); throw OAuthServerException::serverError('Could not generate a random string. Is our OS secure?');
} }
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd

View File

@ -1,5 +1,5 @@
<?php <?php
if (! @include_once __DIR__ . '/../vendor/autoload.php') { if (!@include_once __DIR__.'/../vendor/autoload.php') {
exit("You must set up the project dependencies, run the following commands:\n> wget http://getcomposer.org/composer.phar\n> php composer.phar install\n"); exit("You must set up the project dependencies, run the following commands:\n> wget http://getcomposer.org/composer.phar\n> php composer.phar install\n");
} }

View File

@ -10,11 +10,11 @@ use League\OAuth2\Server\Entities\Interfaces\AuthCodeEntityInterface;
use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface; use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface;
use League\OAuth2\Server\Entities\ScopeEntity; use League\OAuth2\Server\Entities\ScopeEntity;
use League\OAuth2\Server\Grant\AbstractGrant; use League\OAuth2\Server\Grant\AbstractGrant;
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
use League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface; use League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface;
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
use Zend\Diactoros\ServerRequest; use Zend\Diactoros\ServerRequest;
class AbstractGrantTest extends \PHPUnit_Framework_TestCase class AbstractGrantTest extends \PHPUnit_Framework_TestCase
@ -151,7 +151,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase
$serverRequest = new ServerRequest(); $serverRequest = new ServerRequest();
$serverRequest = $serverRequest->withParsedBody([ $serverRequest = $serverRequest->withParsedBody([
'client_id' => 'foo', 'client_id' => 'foo',
'client_secret' => 'foo', 'client_secret' => 'foo',
]); ]);
@ -180,7 +180,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase
$serverRequest = new ServerRequest(); $serverRequest = new ServerRequest();
$serverRequest = $serverRequest->withParsedBody([ $serverRequest = $serverRequest->withParsedBody([
'client_id' => 'foo', 'client_id' => 'foo',
'redirect_uri' => 'http://bar/foo' 'redirect_uri' => 'http://bar/foo',
]); ]);
$validateClientMethod = $abstractGrantReflection->getMethod('validateClient'); $validateClientMethod = $abstractGrantReflection->getMethod('validateClient');

View File

@ -5,7 +5,6 @@ namespace LeagueTests\Grant;
use League\OAuth2\Server\Entities\ClientEntity; use League\OAuth2\Server\Entities\ClientEntity;
use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface;
use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface; use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface;
use League\OAuth2\Server\Grant\PasswordGrant;
use League\OAuth2\Server\Grant\RefreshTokenGrant; use League\OAuth2\Server\Grant\RefreshTokenGrant;
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
use League\OAuth2\Server\Repositories\ClientRepositoryInterface; use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
@ -14,7 +13,6 @@ use League\OAuth2\Server\Repositories\UserRepositoryInterface;
use League\OAuth2\Server\Utils\KeyCrypt; use League\OAuth2\Server\Utils\KeyCrypt;
use LeagueTests\Stubs\StubResponseType; use LeagueTests\Stubs\StubResponseType;
use LeagueTests\Stubs\UserEntity; use LeagueTests\Stubs\UserEntity;
use OAuth2ServerExamples\Repositories\RefreshTokenRepository;
use Zend\Diactoros\ServerRequest; use Zend\Diactoros\ServerRequest;
class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase

View File

@ -4,11 +4,11 @@ namespace LeagueTests;
use League\OAuth2\Server\Entities\ClientEntity; use League\OAuth2\Server\Entities\ClientEntity;
use League\OAuth2\Server\Grant\ClientCredentialsGrant; use League\OAuth2\Server\Grant\ClientCredentialsGrant;
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
use League\OAuth2\Server\Server; use League\OAuth2\Server\Server;
use LeagueTests\Stubs\StubResponseType; use LeagueTests\Stubs\StubResponseType;
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
class ServerTest extends \PHPUnit_Framework_TestCase class ServerTest extends \PHPUnit_Framework_TestCase

View File

@ -11,7 +11,9 @@ use Zend\Diactoros\Response;
class StubResponseType extends AbstractResponseType class StubResponseType extends AbstractResponseType
{ {
public function __construct() {} public function __construct()
{
}
public function getAccessToken() public function getAccessToken()
{ {