mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-11-08 21:52:24 +05:30
Applied fixes from StyleCI
This commit is contained in:
parent
60c45ab8fe
commit
a2460886f6
@ -3,19 +3,17 @@
|
||||
use League\OAuth2\Server\Exception\OAuthServerException;
|
||||
use League\OAuth2\Server\Grant\AuthCodeGrant;
|
||||
use League\OAuth2\Server\Server;
|
||||
|
||||
use OAuth2ServerExamples\Repositories\AccessTokenRepository;
|
||||
use OAuth2ServerExamples\Repositories\AuthCodeRepository;
|
||||
use OAuth2ServerExamples\Repositories\ClientRepository;
|
||||
use OAuth2ServerExamples\Repositories\RefreshTokenRepository;
|
||||
use OAuth2ServerExamples\Repositories\ScopeRepository;
|
||||
use OAuth2ServerExamples\Repositories\UserRepository;
|
||||
|
||||
use Slim\App;
|
||||
use Slim\Http\Request;
|
||||
use Slim\Http\Response;
|
||||
|
||||
include(__DIR__ . '/../vendor/autoload.php');
|
||||
include __DIR__.'/../vendor/autoload.php';
|
||||
|
||||
// App
|
||||
$app = new App([
|
||||
@ -29,8 +27,8 @@ $app = new App([
|
||||
$refreshTokenRepository = new RefreshTokenRepository();
|
||||
$authCodeRepository = new AuthCodeRepository();
|
||||
|
||||
$privateKeyPath = 'file://' . __DIR__ . '/../private.key';
|
||||
$publicKeyPath = 'file://' . __DIR__ . '/../public.key';
|
||||
$privateKeyPath = 'file://'.__DIR__.'/../private.key';
|
||||
$publicKeyPath = 'file://'.__DIR__.'/../public.key';
|
||||
|
||||
// Setup the authorization server
|
||||
$server = new Server(
|
||||
|
@ -3,16 +3,14 @@
|
||||
use League\OAuth2\Server\Exception\OAuthServerException;
|
||||
use League\OAuth2\Server\Grant\ClientCredentialsGrant;
|
||||
use League\OAuth2\Server\Server;
|
||||
|
||||
use OAuth2ServerExamples\Repositories\AccessTokenRepository;
|
||||
use OAuth2ServerExamples\Repositories\ClientRepository;
|
||||
use OAuth2ServerExamples\Repositories\ScopeRepository;
|
||||
|
||||
use Slim\App;
|
||||
use Slim\Http\Request;
|
||||
use Slim\Http\Response;
|
||||
|
||||
include(__DIR__ . '/../vendor/autoload.php');
|
||||
include __DIR__.'/../vendor/autoload.php';
|
||||
|
||||
// App
|
||||
$app = new App([
|
||||
@ -23,8 +21,8 @@ $app = new App([
|
||||
$scopeRepository = new ScopeRepository();
|
||||
$accessTokenRepository = new AccessTokenRepository();
|
||||
|
||||
$privateKeyPath = 'file://' . __DIR__ . '/../private.key';
|
||||
$publicKeyPath = 'file://' . __DIR__ . '/../public.key';
|
||||
$privateKeyPath = 'file://'.__DIR__.'/../private.key';
|
||||
$publicKeyPath = 'file://'.__DIR__.'/../public.key';
|
||||
|
||||
// Setup the authorization server
|
||||
$server = new Server(
|
||||
@ -39,7 +37,7 @@ $app = new App([
|
||||
$server->enableGrantType(new ClientCredentialsGrant(), new \DateInterval('PT1H'));
|
||||
|
||||
return $server;
|
||||
}
|
||||
},
|
||||
]);
|
||||
|
||||
$app->post('/access_token', function (Request $request, Response $response) {
|
||||
|
@ -4,16 +4,14 @@ use League\OAuth2\Server\Grant\PasswordGrant;
|
||||
use League\OAuth2\Server\Grant\RefreshTokenGrant;
|
||||
use League\OAuth2\Server\Middleware\AuthenticationServerMiddleware;
|
||||
use League\OAuth2\Server\Server;
|
||||
|
||||
use OAuth2ServerExamples\Repositories\AccessTokenRepository;
|
||||
use OAuth2ServerExamples\Repositories\ClientRepository;
|
||||
use OAuth2ServerExamples\Repositories\RefreshTokenRepository;
|
||||
use OAuth2ServerExamples\Repositories\ScopeRepository;
|
||||
use OAuth2ServerExamples\Repositories\UserRepository;
|
||||
|
||||
use Slim\App;
|
||||
|
||||
include(__DIR__ . '/../vendor/autoload.php');
|
||||
include __DIR__.'/../vendor/autoload.php';
|
||||
|
||||
// App
|
||||
$app = new App([
|
||||
@ -29,8 +27,8 @@ $app = new App([
|
||||
$userRepository = new UserRepository();
|
||||
$refreshTokenRepository = new RefreshTokenRepository();
|
||||
|
||||
$privateKeyPath = 'file://' . __DIR__ . '/../private.key';
|
||||
$publicKeyPath = 'file://' . __DIR__ . '/../public.key';
|
||||
$privateKeyPath = 'file://'.__DIR__.'/../private.key';
|
||||
$publicKeyPath = 'file://'.__DIR__.'/../public.key';
|
||||
|
||||
// Setup the authorization server
|
||||
$server = new Server(
|
||||
@ -52,7 +50,7 @@ $app = new App([
|
||||
);
|
||||
|
||||
return $server;
|
||||
}
|
||||
},
|
||||
]);
|
||||
|
||||
$app->post('/access_token', function () {
|
||||
|
@ -3,18 +3,16 @@
|
||||
use League\OAuth2\Server\Exception\OAuthServerException;
|
||||
use League\OAuth2\Server\Grant\PasswordGrant;
|
||||
use League\OAuth2\Server\Server;
|
||||
|
||||
use OAuth2ServerExamples\Repositories\AccessTokenRepository;
|
||||
use OAuth2ServerExamples\Repositories\ClientRepository;
|
||||
use OAuth2ServerExamples\Repositories\RefreshTokenRepository;
|
||||
use OAuth2ServerExamples\Repositories\ScopeRepository;
|
||||
use OAuth2ServerExamples\Repositories\UserRepository;
|
||||
|
||||
use Slim\App;
|
||||
use Slim\Http\Request;
|
||||
use Slim\Http\Response;
|
||||
|
||||
include(__DIR__ . '/../vendor/autoload.php');
|
||||
include __DIR__.'/../vendor/autoload.php';
|
||||
|
||||
// App
|
||||
$app = new App([
|
||||
@ -27,8 +25,8 @@ $app = new App([
|
||||
$userRepository = new UserRepository();
|
||||
$refreshTokenRepository = new RefreshTokenRepository();
|
||||
|
||||
$privateKeyPath = 'file://' . __DIR__ . '/../private.key';
|
||||
$publicKeyPath = 'file://' . __DIR__ . '/../public.key';
|
||||
$privateKeyPath = 'file://'.__DIR__.'/../private.key';
|
||||
$publicKeyPath = 'file://'.__DIR__.'/../public.key';
|
||||
|
||||
// Setup the authorization server
|
||||
$server = new Server(
|
||||
@ -46,7 +44,7 @@ $app = new App([
|
||||
);
|
||||
|
||||
return $server;
|
||||
}
|
||||
},
|
||||
]);
|
||||
|
||||
$app->post('/access_token', function (Request $request, Response $response) {
|
||||
|
@ -2,16 +2,14 @@
|
||||
|
||||
use League\OAuth2\Server\Middleware\ResourceServerMiddleware;
|
||||
use League\OAuth2\Server\Server;
|
||||
|
||||
use OAuth2ServerExamples\Repositories\AccessTokenRepository;
|
||||
use OAuth2ServerExamples\Repositories\ClientRepository;
|
||||
use OAuth2ServerExamples\Repositories\ScopeRepository;
|
||||
|
||||
use Slim\App;
|
||||
use Slim\Http\Request;
|
||||
use Slim\Http\Response;
|
||||
|
||||
include(__DIR__ . '/../vendor/autoload.php');
|
||||
include __DIR__.'/../vendor/autoload.php';
|
||||
|
||||
// App
|
||||
$app = new App([
|
||||
@ -25,8 +23,8 @@ $app = new App([
|
||||
$scopeRepository = new ScopeRepository();
|
||||
$accessTokenRepository = new AccessTokenRepository();
|
||||
|
||||
$privateKeyPath = 'file://' . __DIR__ . '/../private.key';
|
||||
$publicKeyPath = 'file://' . __DIR__ . '/../public.key';
|
||||
$privateKeyPath = 'file://'.__DIR__.'/../private.key';
|
||||
$publicKeyPath = 'file://'.__DIR__.'/../public.key';
|
||||
|
||||
// Setup the authorization server
|
||||
$server = new Server(
|
||||
@ -38,7 +36,7 @@ $app = new App([
|
||||
);
|
||||
|
||||
return $server;
|
||||
}
|
||||
},
|
||||
]);
|
||||
|
||||
$app->add(new ResourceServerMiddleware($app->getContainer()->get(Server::class)));
|
||||
@ -50,7 +48,7 @@ $app->post('/api/example', function (Request $request, Response $response) {
|
||||
$params = [
|
||||
'id' => 1,
|
||||
'name' => 'Alex',
|
||||
'city' => 'London'
|
||||
'city' => 'London',
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -3,19 +3,15 @@
|
||||
use League\OAuth2\Server\Exception\OAuthServerException;
|
||||
use League\OAuth2\Server\Grant\RefreshTokenGrant;
|
||||
use League\OAuth2\Server\Server;
|
||||
|
||||
use OAuth2ServerExamples\Repositories\AccessTokenRepository;
|
||||
use OAuth2ServerExamples\Repositories\ClientRepository;
|
||||
use OAuth2ServerExamples\Repositories\RefreshTokenRepository;
|
||||
use OAuth2ServerExamples\Repositories\ScopeRepository;
|
||||
|
||||
use Slim\App;
|
||||
use Slim\Http\Request;
|
||||
use Slim\Http\Response;
|
||||
|
||||
include(__DIR__ . '/../vendor/autoload.php');
|
||||
|
||||
|
||||
include __DIR__.'/../vendor/autoload.php';
|
||||
|
||||
// App
|
||||
$app = new App([Server::class => function () {
|
||||
@ -25,8 +21,8 @@ $app = new App([Server::class => function () {
|
||||
$accessTokenRepository = new AccessTokenRepository();
|
||||
$refreshTokenRepository = new RefreshTokenRepository();
|
||||
|
||||
$privateKeyPath = 'file://' . __DIR__ . '/../private.key';
|
||||
$publicKeyPath = 'file://' . __DIR__ . '/../public.key';
|
||||
$privateKeyPath = 'file://'.__DIR__.'/../private.key';
|
||||
$publicKeyPath = 'file://'.__DIR__.'/../public.key';
|
||||
|
||||
// Setup the authorization server
|
||||
$server = new Server(
|
||||
|
@ -7,11 +7,12 @@ use League\OAuth2\Server\Entities\Interfaces\UserEntityInterface;
|
||||
class UserEntity implements UserEntityInterface
|
||||
{
|
||||
/**
|
||||
* Return the user's identifier
|
||||
* Return the user's identifier.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getIdentifier()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace OAuth2ServerExamples\Repositories;
|
||||
|
||||
use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface;
|
||||
@ -7,7 +8,7 @@ use League\OAuth2\Server\Repositories\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
|
||||
*/
|
||||
@ -17,7 +18,7 @@ class AccessTokenRepository implements AccessTokenRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Revoke an access token
|
||||
* Revoke an access token.
|
||||
*
|
||||
* @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
|
||||
*
|
||||
|
@ -7,9 +7,8 @@ use League\OAuth2\Server\Repositories\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
|
||||
*/
|
||||
@ -19,7 +18,7 @@ class AuthCodeRepository implements AuthCodeRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Revoke an auth code
|
||||
* Revoke an auth code.
|
||||
*
|
||||
* @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
|
||||
*
|
||||
@ -39,4 +38,4 @@ class AuthCodeRepository implements AuthCodeRepositoryInterface
|
||||
{
|
||||
// TODO: Implement isAuthCodeRevoked() method.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace OAuth2ServerExamples\Repositories;
|
||||
|
||||
use League\OAuth2\Server\Entities\ClientEntity;
|
||||
@ -7,7 +8,7 @@ use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
|
||||
class ClientRepository implements ClientRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getClientEntity($clientIdentifier, $clientSecret = null, $redirectUri = null, $grantType = null)
|
||||
{
|
||||
@ -15,23 +16,23 @@ class ClientRepository implements ClientRepositoryInterface
|
||||
'myawesomeapp' => [
|
||||
'secret' => password_hash('abc123', PASSWORD_BCRYPT),
|
||||
'name' => 'My Awesome App',
|
||||
'redirect_uri' => 'http://foo/bar'
|
||||
]
|
||||
'redirect_uri' => 'http://foo/bar',
|
||||
],
|
||||
];
|
||||
|
||||
// Check if client is registered
|
||||
if (array_key_exists($clientIdentifier, $clients) === false) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if client secret is valid
|
||||
if ($clientSecret !== null && password_verify($clientSecret, $clients[$clientIdentifier]['secret']) === false) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if redirect URI is valid
|
||||
if ($redirectUri !== null && $redirectUri !== $clients[$clientIdentifier]['redirect_uri']) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
$client = new ClientEntity();
|
||||
|
@ -7,9 +7,8 @@ use League\OAuth2\Server\Repositories\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
|
||||
*/
|
||||
@ -19,7 +18,7 @@ class RefreshTokenRepository implements RefreshTokenRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Revoke the refresh token
|
||||
* Revoke the refresh token.
|
||||
*
|
||||
* @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
|
||||
*
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace OAuth2ServerExamples\Repositories;
|
||||
|
||||
use League\OAuth2\Server\Entities\ScopeEntity;
|
||||
@ -7,21 +8,21 @@ use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
|
||||
class ScopeRepository implements ScopeRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getScopeEntityByIdentifier($scopeIdentifier, $grantType, $clientId = null)
|
||||
{
|
||||
$scopes = [
|
||||
'basic' => [
|
||||
'description' => 'Basic details about you'
|
||||
'description' => 'Basic details about you',
|
||||
],
|
||||
'email' => [
|
||||
'description' => 'Your email address'
|
||||
]
|
||||
'description' => 'Your email address',
|
||||
],
|
||||
];
|
||||
|
||||
if (array_key_exists($scopeIdentifier, $scopes) === false) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
$scope = new ScopeEntity();
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace OAuth2ServerExamples\Repositories;
|
||||
|
||||
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
|
||||
@ -7,7 +8,7 @@ use OAuth2ServerExamples\Entities\UserEntity;
|
||||
class UserRepository implements UserRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Get a user entity
|
||||
* Get a user entity.
|
||||
*
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
@ -20,6 +21,6 @@ class UserRepository implements UserRepositoryInterface
|
||||
return new UserEntity();
|
||||
}
|
||||
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace League\OAuth2\Server\Entities;
|
||||
|
||||
use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface;
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace League\OAuth2\Server\Entities;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Class AuthCodeEntity
|
||||
* @package League\OAuth2\Server
|
||||
* Class AuthCodeEntity.
|
||||
*/
|
||||
class AuthCodeEntity implements AuthCodeEntityInterface
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace League\OAuth2\Server\Entities;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Class ClientEntity
|
||||
* @package League\OAuth2\Server
|
||||
* Class ClientEntity.
|
||||
*/
|
||||
class ClientEntity implements ClientEntityInterface
|
||||
{
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace League\OAuth2\Server\Entities\Interfaces;
|
||||
|
||||
interface AccessTokenEntityInterface extends TokenInterface
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -1,29 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace League\OAuth2\Server\Entities\Interfaces;
|
||||
|
||||
interface ClientEntityInterface
|
||||
{
|
||||
/**
|
||||
* Get the client's identifier
|
||||
* Get the client's identifier.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIdentifier();
|
||||
|
||||
/**
|
||||
* Set the client's identifier
|
||||
* Set the client's identifier.
|
||||
*
|
||||
* @param $identifier
|
||||
*/
|
||||
public function setIdentifier($identifier);
|
||||
|
||||
/**
|
||||
* Get the client's name
|
||||
* Get the client's name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Set the client's name
|
||||
* Set the client's name.
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
@ -35,31 +38,32 @@ interface ClientEntityInterface
|
||||
public function setSecret($secret);
|
||||
|
||||
/**
|
||||
* Validate the secret provided by the client
|
||||
* Validate the secret provided by the client.
|
||||
*
|
||||
* @param string $submittedSecret
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function validateSecret($submittedSecret);
|
||||
|
||||
/**
|
||||
* Set the client's redirect uri
|
||||
* Set the client's redirect uri.
|
||||
*
|
||||
* @param string $redirectUri
|
||||
*/
|
||||
public function setRedirectUri($redirectUri);
|
||||
|
||||
/**
|
||||
* Returns the registered redirect URI
|
||||
* Returns the registered redirect URI.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRedirectUri();
|
||||
|
||||
/**
|
||||
* Returns true if the client is capable of keeping it's secrets secret
|
||||
* @return boolean
|
||||
* Returns true if the client is capable of keeping it's secrets secret.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canKeepASecret();
|
||||
}
|
||||
|
@ -1,47 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace League\OAuth2\Server\Entities\Interfaces;
|
||||
|
||||
interface RefreshTokenEntityInterface
|
||||
{
|
||||
/**
|
||||
* Get the token's identifier
|
||||
* Get the token's identifier.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIdentifier();
|
||||
|
||||
/**
|
||||
* Set the token's identifier
|
||||
* Set the token's identifier.
|
||||
*
|
||||
* @param $identifier
|
||||
*/
|
||||
public function setIdentifier($identifier);
|
||||
|
||||
/**
|
||||
* Get the token's expiry date time
|
||||
* Get the token's expiry date time.
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getExpiryDateTime();
|
||||
|
||||
/**
|
||||
* Set the date time when the token expires
|
||||
* Set the date time when the token expires.
|
||||
*
|
||||
* @param \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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
public function getAccessToken();
|
||||
|
||||
/**
|
||||
* Has the token expired?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isExpired();
|
||||
|
@ -1,16 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace League\OAuth2\Server\Entities\Interfaces;
|
||||
|
||||
interface ScopeEntityInterface extends \JsonSerializable
|
||||
{
|
||||
/**
|
||||
* Get the scope's identifier
|
||||
* Get the scope's identifier.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIdentifier();
|
||||
|
||||
/**
|
||||
* Set the scope's identifier
|
||||
* Set the scope's identifier.
|
||||
*
|
||||
* @param $identifier
|
||||
*/
|
||||
public function setIdentifier($identifier);
|
||||
|
@ -1,78 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace League\OAuth2\Server\Entities\Interfaces;
|
||||
|
||||
interface TokenInterface
|
||||
{
|
||||
/**
|
||||
* Get the token's identifier
|
||||
* Get the token's identifier.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIdentifier();
|
||||
|
||||
/**
|
||||
* Set the token's identifier
|
||||
* Set the token's identifier.
|
||||
*
|
||||
* @param $identifier
|
||||
*/
|
||||
public function setIdentifier($identifier);
|
||||
|
||||
/**
|
||||
* Get the token's expiry date time
|
||||
* Get the token's expiry date time.
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getExpiryDateTime();
|
||||
|
||||
/**
|
||||
* Set the date time when the token expires
|
||||
* Set the date time when the token expires.
|
||||
*
|
||||
* @param \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
|
||||
*/
|
||||
public function setUserIdentifier($identifier);
|
||||
|
||||
/**
|
||||
* Get the token user's identifier
|
||||
* Get the token user's identifier.
|
||||
*
|
||||
* @return string|int
|
||||
*/
|
||||
public function getUserIdentifier();
|
||||
|
||||
/**
|
||||
* Get the client that the token was issued to
|
||||
* Get the client that the token was issued to.
|
||||
*
|
||||
* @return ClientEntityInterface
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
* @return ScopeEntityInterface|null The scope or null if not found
|
||||
*
|
||||
* @return ScopeEntityInterface|null The scope or null if not found
|
||||
*/
|
||||
public function getScopeWithIdentifier($identifier);
|
||||
|
||||
/**
|
||||
* Return an array of scopes associated with the token
|
||||
* Return an array of scopes associated with the token.
|
||||
*
|
||||
* @return ScopeEntityInterface[]
|
||||
*/
|
||||
public function getScopes();
|
||||
|
||||
/**
|
||||
* Has the token expired?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isExpired();
|
||||
|
@ -5,7 +5,8 @@ namespace League\OAuth2\Server\Entities\Interfaces;
|
||||
interface UserEntityInterface
|
||||
{
|
||||
/**
|
||||
* Return the user's identifier
|
||||
* Return the user's identifier.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getIdentifier();
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace League\OAuth2\Server\Entities;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Class RefreshTokenEntity
|
||||
* @package League\OAuth2\Server
|
||||
* Class RefreshTokenEntity.
|
||||
*/
|
||||
class RefreshTokenEntity implements RefreshTokenEntityInterface
|
||||
{
|
||||
|
@ -1,19 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace League\OAuth2\Server\Entities;
|
||||
|
||||
use League\OAuth2\Server\Entities\Interfaces\ScopeEntityInterface;
|
||||
use League\OAuth2\Server\Entities\Traits\EntityTrait;
|
||||
|
||||
/**
|
||||
* Class ScopeEntity
|
||||
* @package League\OAuth2\Server
|
||||
* Class ScopeEntity.
|
||||
*/
|
||||
class ScopeEntity implements ScopeEntityInterface
|
||||
{
|
||||
use EntityTrait;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace League\OAuth2\Server\Entities\Traits;
|
||||
|
||||
trait ClientEntityTrait
|
||||
@ -19,7 +20,7 @@ trait ClientEntityTrait
|
||||
protected $redirectUri;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
@ -27,7 +28,7 @@ trait ClientEntityTrait
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
@ -35,7 +36,7 @@ trait ClientEntityTrait
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function canKeepASecret()
|
||||
{
|
||||
@ -43,7 +44,7 @@ trait ClientEntityTrait
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setSecret($secret)
|
||||
{
|
||||
@ -51,7 +52,7 @@ trait ClientEntityTrait
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validateSecret($submittedSecret)
|
||||
{
|
||||
@ -59,7 +60,7 @@ trait ClientEntityTrait
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setRedirectUri($redirectUri)
|
||||
{
|
||||
@ -67,7 +68,7 @@ trait ClientEntityTrait
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRedirectUri()
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace League\OAuth2\Server\Entities\Traits;
|
||||
|
||||
trait EntityTrait
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace League\OAuth2\Server\Entities\Traits;
|
||||
|
||||
use DateTime;
|
||||
@ -17,7 +18,7 @@ trait RefreshTokenTrait
|
||||
protected $expiryDateTime;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setAccessToken(AccessTokenEntityInterface $accessToken)
|
||||
{
|
||||
@ -25,7 +26,7 @@ trait RefreshTokenTrait
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
@ -53,6 +55,7 @@ trait RefreshTokenTrait
|
||||
|
||||
/**
|
||||
* Has the token expired?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isExpired()
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace League\OAuth2\Server\Entities\Traits;
|
||||
|
||||
use DateTime;
|
||||
@ -28,7 +29,7 @@ trait TokenEntityTrait
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* Associate a scope with the token
|
||||
* Associate a scope with the token.
|
||||
*
|
||||
* @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
|
||||
*
|
||||
* @return ScopeEntityInterface|null The scope or null if not found
|
||||
* @return ScopeEntityInterface|null The scope or null if not found
|
||||
*/
|
||||
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[]
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
@ -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
|
||||
*/
|
||||
@ -88,7 +91,8 @@ trait TokenEntityTrait
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the token user's identifier
|
||||
* Get the token user's identifier.
|
||||
*
|
||||
* @return string|int
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
@ -117,6 +122,7 @@ trait TokenEntityTrait
|
||||
|
||||
/**
|
||||
* Has the token expired?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isExpired()
|
||||
|
@ -30,7 +30,7 @@ class OAuthServerException extends \Exception
|
||||
private $redirectUri;
|
||||
|
||||
/**
|
||||
* Throw a new exception
|
||||
* Throw a new exception.
|
||||
*
|
||||
* @param string $message Error message
|
||||
* @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 $localizedHint
|
||||
@ -60,7 +60,7 @@ class OAuthServerException extends \Exception
|
||||
$localizedHint = null
|
||||
) {
|
||||
$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.'
|
||||
: $localizedError;
|
||||
$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 $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 $localizedHint
|
||||
*
|
||||
@ -107,7 +107,7 @@ class OAuthServerException extends \Exception
|
||||
$localizedHint = null
|
||||
) {
|
||||
$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.'
|
||||
: $localizedError;
|
||||
$hint = (is_null($localizedHint))
|
||||
@ -118,7 +118,7 @@ class OAuthServerException extends \Exception
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalid client error
|
||||
* Invalid client error.
|
||||
*
|
||||
* @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 null|string $localizedError A localized error message
|
||||
@ -156,7 +156,7 @@ class OAuthServerException extends \Exception
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalid credentials error
|
||||
* Invalid credentials error.
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
@ -166,7 +166,7 @@ class OAuthServerException extends \Exception
|
||||
}
|
||||
|
||||
/**
|
||||
* Server error
|
||||
* Server error.
|
||||
*
|
||||
* @param $hint
|
||||
*
|
||||
@ -176,7 +176,7 @@ class OAuthServerException extends \Exception
|
||||
{
|
||||
return new static(
|
||||
'The authorization server encountered an unexpected condition which prevented it from fulfilling'
|
||||
. 'the request.',
|
||||
.'the request.',
|
||||
'server_error',
|
||||
500,
|
||||
$hint
|
||||
@ -184,9 +184,10 @@ class OAuthServerException extends \Exception
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalid refresh token
|
||||
* Invalid refresh token.
|
||||
*
|
||||
* @param string|null $hint
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
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 $redirectUri
|
||||
@ -222,7 +223,7 @@ class OAuthServerException extends \Exception
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a HTTP response
|
||||
* Generate a HTTP response.
|
||||
*
|
||||
* @param \Psr\Http\Message\ResponseInterface $response
|
||||
*
|
||||
@ -238,7 +239,7 @@ class OAuthServerException extends \Exception
|
||||
|
||||
$payload = [
|
||||
'error' => $this->errorType,
|
||||
'message' => $this->getMessage()
|
||||
'message' => $this->getMessage(),
|
||||
];
|
||||
|
||||
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
|
||||
*/
|
||||
public function getHttpHeaders()
|
||||
{
|
||||
$headers = [
|
||||
'Content-type' => 'application/json'
|
||||
'Content-type' => 'application/json',
|
||||
];
|
||||
|
||||
// Add "WWW-Authenticate" header
|
||||
@ -303,7 +304,7 @@ class OAuthServerException extends \Exception
|
||||
}
|
||||
}
|
||||
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
|
||||
*/
|
||||
|
@ -1,14 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* OAuth 2.0 Abstract grant
|
||||
* OAuth 2.0 Abstract grant.
|
||||
*
|
||||
* @package league/oauth2-server
|
||||
* @author Alex Bilbie <hello@alexbilbie.com>
|
||||
* @copyright Copyright (c) Alex Bilbie
|
||||
* @license http://mit-license.org/
|
||||
*
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\Grant;
|
||||
|
||||
use League\Event\EmitterAwareTrait;
|
||||
@ -29,7 +28,7 @@ use OAuth2ServerExamples\Repositories\AuthCodeRepository;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
/**
|
||||
* Abstract grant class
|
||||
* Abstract grant class.
|
||||
*/
|
||||
abstract class AbstractGrant implements GrantTypeInterface
|
||||
{
|
||||
@ -139,7 +138,7 @@ abstract class AbstractGrant implements GrantTypeInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setEmitter(EmitterInterface $emitter = null)
|
||||
{
|
||||
@ -147,7 +146,7 @@ abstract class AbstractGrant implements GrantTypeInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @return \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface
|
||||
* @throws \League\OAuth2\Server\Exception\OAuthServerException
|
||||
*
|
||||
* @return \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface
|
||||
*/
|
||||
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 \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface $client
|
||||
* @param string $redirectUri
|
||||
*
|
||||
* @return \League\OAuth2\Server\Entities\ScopeEntity[]
|
||||
*
|
||||
* @throws \League\OAuth2\Server\Exception\OAuthServerException
|
||||
*
|
||||
* @return \League\OAuth2\Server\Entities\ScopeEntity[]
|
||||
*/
|
||||
public function validateScopes(
|
||||
ServerRequestInterface $request,
|
||||
@ -322,7 +322,7 @@ abstract class AbstractGrant implements GrantTypeInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue an access token
|
||||
* Issue an access token.
|
||||
*
|
||||
* @param \DateInterval $tokenTTL
|
||||
* @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 \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface $client
|
||||
@ -361,8 +361,9 @@ abstract class AbstractGrant implements GrantTypeInterface
|
||||
* @param string $redirectUri
|
||||
* @param array $scopes
|
||||
*
|
||||
* @return \League\OAuth2\Server\Entities\AuthCodeEntity
|
||||
* @throws \League\OAuth2\Server\Exception\OAuthServerException
|
||||
*
|
||||
* @return \League\OAuth2\Server\Entities\AuthCodeEntity
|
||||
*/
|
||||
protected function issueAuthCode(
|
||||
\DateInterval $tokenTTL,
|
||||
@ -405,13 +406,13 @@ abstract class AbstractGrant implements GrantTypeInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a new unique identifier
|
||||
* Generate a new unique identifier.
|
||||
*
|
||||
* @param int $length
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws \League\OAuth2\Server\Exception\OAuthServerException
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function generateUniqueIdentifier($length = 40)
|
||||
{
|
||||
@ -430,13 +431,12 @@ abstract class AbstractGrant implements GrantTypeInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function canRespondToRequest(ServerRequestInterface $request)
|
||||
{
|
||||
return (
|
||||
return
|
||||
isset($request->getParsedBody()['grant_type'])
|
||||
&& $request->getParsedBody()['grant_type'] === $this->getIdentifier()
|
||||
);
|
||||
&& $request->getParsedBody()['grant_type'] === $this->getIdentifier();
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace League\OAuth2\Server\Grant;
|
||||
|
||||
use DateInterval;
|
||||
use League\Event\Event;
|
||||
use League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface;
|
||||
use League\OAuth2\Server\Entities\Interfaces\UserEntityInterface;
|
||||
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\Utils\KeyCrypt;
|
||||
use League\Plates\Engine;
|
||||
use League\Event\Event;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Uri;
|
||||
@ -39,7 +39,6 @@ class AuthCodeGrant extends AbstractGrant
|
||||
*/
|
||||
private $pathToAuthorizeTemplate;
|
||||
|
||||
|
||||
/**
|
||||
* @param \League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface $authCodeRepository
|
||||
* @param \League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface $refreshTokenRepository
|
||||
@ -61,22 +60,22 @@ class AuthCodeGrant extends AbstractGrant
|
||||
$this->userRepository = $userRepository;
|
||||
$this->authCodeTTL = $authCodeTTL;
|
||||
$this->pathToLoginTemplate = ($pathToLoginTemplate === null)
|
||||
? __DIR__ . '/../ResponseTypes/DefaultTemplates/login_user.php'
|
||||
? __DIR__.'/../ResponseTypes/DefaultTemplates/login_user.php'
|
||||
: $this->pathToLoginTemplate;
|
||||
$this->pathToAuthorizeTemplate = ($pathToLoginTemplate === null)
|
||||
? __DIR__ . '/../ResponseTypes/DefaultTemplates/authorize_client.php'
|
||||
? __DIR__.'/../ResponseTypes/DefaultTemplates/authorize_client.php'
|
||||
: $this->pathToAuthorizeTemplate;
|
||||
$this->refreshTokenTTL = new \DateInterval('P1M');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Respond to an authorization request
|
||||
* Respond to an authorization request.
|
||||
*
|
||||
* @param \Psr\Http\Message\ServerRequestInterface $request
|
||||
*
|
||||
* @return \Psr\Http\Message\ResponseInterface
|
||||
* @throws \League\OAuth2\Server\Exception\OAuthServerException
|
||||
*
|
||||
* @return \Psr\Http\Message\ResponseInterface
|
||||
*/
|
||||
protected function respondToAuthorizationRequest(
|
||||
ServerRequestInterface $request
|
||||
@ -153,7 +152,6 @@ class AuthCodeGrant extends AbstractGrant
|
||||
return new Response\HtmlResponse($html);
|
||||
}
|
||||
|
||||
|
||||
// The user hasn't approved the client yet so show an authorize form
|
||||
if ($userId !== null && $userHasApprovedClient === null) {
|
||||
$engine = new Engine(dirname($this->pathToAuthorizeTemplate));
|
||||
@ -219,18 +217,20 @@ class AuthCodeGrant extends AbstractGrant
|
||||
}
|
||||
|
||||
$exception = OAuthServerException::accessDenied('The user denied the request', (string) $redirectUri);
|
||||
|
||||
return $exception->generateHttpResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond to an access token request
|
||||
* Respond to an access token request.
|
||||
*
|
||||
* @param \Psr\Http\Message\ServerRequestInterface $request
|
||||
* @param \League\OAuth2\Server\ResponseTypes\ResponseTypeInterface $responseType
|
||||
* @param \DateInterval $accessTokenTTL
|
||||
*
|
||||
* @return \League\OAuth2\Server\ResponseTypes\ResponseTypeInterface
|
||||
* @throws \League\OAuth2\Server\Exception\OAuthServerException
|
||||
*
|
||||
* @return \League\OAuth2\Server\ResponseTypes\ResponseTypeInterface
|
||||
*/
|
||||
protected function respondToAccessTokenRequest(
|
||||
ServerRequestInterface $request,
|
||||
@ -286,21 +286,20 @@ class AuthCodeGrant extends AbstractGrant
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function canRespondToRequest(ServerRequestInterface $request)
|
||||
{
|
||||
return (
|
||||
return
|
||||
(
|
||||
isset($request->getQueryParams()['response_type'])
|
||||
&& $request->getQueryParams()['response_type'] === 'code'
|
||||
&& 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
|
||||
*/
|
||||
@ -310,7 +309,7 @@ class AuthCodeGrant extends AbstractGrant
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function respondToRequest(
|
||||
ServerRequestInterface $request,
|
||||
|
@ -1,26 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* OAuth 2.0 Client credentials grant
|
||||
* OAuth 2.0 Client credentials grant.
|
||||
*
|
||||
* @package league/oauth2-server
|
||||
* @author Alex Bilbie <hello@alexbilbie.com>
|
||||
* @copyright Copyright (c) Alex Bilbie
|
||||
* @license http://mit-license.org/
|
||||
*
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\Grant;
|
||||
|
||||
use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
/**
|
||||
* Client credentials grant class
|
||||
* Client credentials grant class.
|
||||
*/
|
||||
class ClientCredentialsGrant extends AbstractGrant
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function respondToRequest(
|
||||
ServerRequestInterface $request,
|
||||
@ -41,7 +40,7 @@ class ClientCredentialsGrant extends AbstractGrant
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIdentifier()
|
||||
{
|
||||
|
@ -1,14 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* OAuth 2.0 Grant type interface
|
||||
* OAuth 2.0 Grant type interface.
|
||||
*
|
||||
* @package league/oauth2-server
|
||||
* @author Alex Bilbie <hello@alexbilbie.com>
|
||||
* @copyright Copyright (c) Alex Bilbie
|
||||
* @license http://mit-license.org/
|
||||
*
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\Grant;
|
||||
|
||||
use League\Event\EmitterAwareInterface;
|
||||
@ -19,26 +18,26 @@ use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
/**
|
||||
* Grant type interface
|
||||
* Grant type interface.
|
||||
*/
|
||||
interface GrantTypeInterface extends EmitterAwareInterface
|
||||
{
|
||||
/**
|
||||
* Set refresh token TTL
|
||||
* Set refresh token TTL.
|
||||
*
|
||||
* @param \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
|
||||
*/
|
||||
public function getIdentifier();
|
||||
|
||||
/**
|
||||
* Respond to an incoming request
|
||||
* Respond to an incoming request.
|
||||
*
|
||||
* @param \Psr\Http\Message\ServerRequestInterface $request
|
||||
* @param \League\OAuth2\Server\ResponseTypes\ResponseTypeInterface $responseType
|
||||
@ -62,40 +61,40 @@ interface GrantTypeInterface extends EmitterAwareInterface
|
||||
*
|
||||
* @param \Psr\Http\Message\ServerRequestInterface $request
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function canRespondToRequest(ServerRequestInterface $request);
|
||||
|
||||
/**
|
||||
* Set the client repository
|
||||
* Set the client repository.
|
||||
*
|
||||
* @param \League\OAuth2\Server\Repositories\ClientRepositoryInterface $clientRepository
|
||||
*/
|
||||
public function setClientRepository(ClientRepositoryInterface $clientRepository);
|
||||
|
||||
/**
|
||||
* Set the access token repository
|
||||
* Set the access token repository.
|
||||
*
|
||||
* @param \League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface $accessTokenRepository
|
||||
*/
|
||||
public function setAccessTokenRepository(AccessTokenRepositoryInterface $accessTokenRepository);
|
||||
|
||||
/**
|
||||
* Set the scope repository
|
||||
* Set the scope repository.
|
||||
*
|
||||
* @param \League\OAuth2\Server\Repositories\ScopeRepositoryInterface $scopeRepository
|
||||
*/
|
||||
public function setScopeRepository(ScopeRepositoryInterface $scopeRepository);
|
||||
|
||||
/**
|
||||
* Set the path to the private key
|
||||
* Set the path to the private key.
|
||||
*
|
||||
* @param string $pathToPrivateKey
|
||||
*/
|
||||
public function setPathToPrivateKey($pathToPrivateKey);
|
||||
|
||||
/**
|
||||
* Set the path to the public key
|
||||
* Set the path to the public key.
|
||||
*
|
||||
* @param string $pathToPublicKey
|
||||
*/
|
||||
|
@ -1,14 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* OAuth 2.0 Password grant
|
||||
* OAuth 2.0 Password grant.
|
||||
*
|
||||
* @package league/oauth2-server
|
||||
* @author Alex Bilbie <hello@alexbilbie.com>
|
||||
* @copyright Copyright (c) Alex Bilbie
|
||||
* @license http://mit-license.org/
|
||||
*
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\Grant;
|
||||
|
||||
use League\Event\Event;
|
||||
@ -20,7 +19,7 @@ use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
/**
|
||||
* Password grant class
|
||||
* Password grant class.
|
||||
*/
|
||||
class PasswordGrant extends AbstractGrant
|
||||
{
|
||||
@ -44,7 +43,7 @@ class PasswordGrant extends AbstractGrant
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function respondToRequest(
|
||||
ServerRequestInterface $request,
|
||||
@ -53,7 +52,7 @@ class PasswordGrant extends AbstractGrant
|
||||
) {
|
||||
// Validate request
|
||||
$client = $this->validateClient($request);
|
||||
$user = $this->validateUser($request);
|
||||
$user = $this->validateUser($request);
|
||||
$scopes = $this->validateScopes($request, $client);
|
||||
|
||||
// Issue and persist new tokens
|
||||
@ -70,9 +69,9 @@ class PasswordGrant extends AbstractGrant
|
||||
/**
|
||||
* @param \Psr\Http\Message\ServerRequestInterface $request
|
||||
*
|
||||
* @return \League\OAuth2\Server\Entities\Interfaces\UserEntityInterface
|
||||
*
|
||||
* @throws \League\OAuth2\Server\Exception\OAuthServerException
|
||||
*
|
||||
* @return \League\OAuth2\Server\Entities\Interfaces\UserEntityInterface
|
||||
*/
|
||||
protected function validateUser(ServerRequestInterface $request)
|
||||
{
|
||||
@ -97,7 +96,7 @@ class PasswordGrant extends AbstractGrant
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIdentifier()
|
||||
{
|
||||
|
@ -1,14 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* OAuth 2.0 Refresh token grant
|
||||
* OAuth 2.0 Refresh token grant.
|
||||
*
|
||||
* @package league/oauth2-server
|
||||
* @author Alex Bilbie <hello@alexbilbie.com>
|
||||
* @copyright Copyright (c) Alex Bilbie
|
||||
* @license http://mit-license.org/
|
||||
*
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\Grant;
|
||||
|
||||
use League\Event\Event;
|
||||
@ -20,7 +19,7 @@ use League\OAuth2\Server\Utils\KeyCrypt;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
/**
|
||||
* Refresh token grant
|
||||
* Refresh token grant.
|
||||
*/
|
||||
class RefreshTokenGrant extends AbstractGrant
|
||||
{
|
||||
@ -35,7 +34,7 @@ class RefreshTokenGrant extends AbstractGrant
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function respondToRequest(
|
||||
ServerRequestInterface $request,
|
||||
@ -52,6 +51,7 @@ class RefreshTokenGrant extends AbstractGrant
|
||||
$scopes = array_map(function ($scopeId) {
|
||||
$scope = new ScopeEntity();
|
||||
$scope->setIdentifier($scopeId);
|
||||
|
||||
return $scope;
|
||||
}, $oldRefreshToken['scopes']);
|
||||
} else {
|
||||
@ -87,9 +87,9 @@ class RefreshTokenGrant extends AbstractGrant
|
||||
* @param \Psr\Http\Message\ServerRequestInterface $request
|
||||
* @param string $clientId
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \League\OAuth2\Server\Exception\OAuthServerException
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function validateOldRefreshToken(ServerRequestInterface $request, $clientId)
|
||||
{
|
||||
@ -102,7 +102,7 @@ class RefreshTokenGrant extends AbstractGrant
|
||||
try {
|
||||
$refreshToken = KeyCrypt::decrypt($encryptedRefreshToken, $this->pathToPublicKey);
|
||||
} 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);
|
||||
@ -110,9 +110,9 @@ class RefreshTokenGrant extends AbstractGrant
|
||||
$this->getEmitter()->emit(new Event('refresh_token.client.failed', $request));
|
||||
|
||||
throw OAuthServerException::invalidRefreshToken(
|
||||
'Token is not linked to client,' .
|
||||
' got: ' . $clientId .
|
||||
' expected: ' . $refreshTokenData['client_id']
|
||||
'Token is not linked to client,'.
|
||||
' got: '.$clientId.
|
||||
' expected: '.$refreshTokenData['client_id']
|
||||
);
|
||||
}
|
||||
|
||||
@ -128,7 +128,7 @@ class RefreshTokenGrant extends AbstractGrant
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIdentifier()
|
||||
{
|
||||
|
@ -1,39 +1,38 @@
|
||||
<?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>
|
||||
* @copyright Copyright (c) Alex Bilbie
|
||||
* @license http://mit-license.org/
|
||||
*
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\Repositories;
|
||||
|
||||
use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface;
|
||||
|
||||
/**
|
||||
* Access token interface
|
||||
* Access token interface.
|
||||
*/
|
||||
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
|
||||
*/
|
||||
public function persistNewAccessToken(AccessTokenEntityInterface $accessTokenEntity);
|
||||
|
||||
/**
|
||||
* Revoke an access token
|
||||
* Revoke an access token.
|
||||
*
|
||||
* @param string $tokenId
|
||||
*/
|
||||
public function revokeAccessToken($tokenId);
|
||||
|
||||
/**
|
||||
* Check if the access token has been revoked
|
||||
* Check if the access token has been revoked.
|
||||
*
|
||||
* @param string $tokenId
|
||||
*
|
||||
|
@ -1,39 +1,38 @@
|
||||
<?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>
|
||||
* @copyright Copyright (c) Alex Bilbie
|
||||
* @license http://mit-license.org/
|
||||
*
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\Repositories;
|
||||
|
||||
use League\OAuth2\Server\Entities\Interfaces\AuthCodeEntityInterface;
|
||||
|
||||
/**
|
||||
* Auth code storage interface
|
||||
* Auth code storage interface.
|
||||
*/
|
||||
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
|
||||
*/
|
||||
public function persistNewAuthCode(AuthCodeEntityInterface $authCodeEntity);
|
||||
|
||||
/**
|
||||
* Revoke an auth code
|
||||
* Revoke an auth code.
|
||||
*
|
||||
* @param string $codeId
|
||||
*/
|
||||
public function revokeAuthCode($codeId);
|
||||
|
||||
/**
|
||||
* Check if the auth code has been revoked
|
||||
* Check if the auth code has been revoked.
|
||||
*
|
||||
* @param string $codeId
|
||||
*
|
||||
|
@ -1,26 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* OAuth 2.0 Client storage interface
|
||||
* OAuth 2.0 Client storage interface.
|
||||
*
|
||||
* @package league/oauth2-server
|
||||
* @author Alex Bilbie <hello@alexbilbie.com>
|
||||
* @copyright Copyright (c) Alex Bilbie
|
||||
* @license http://mit-license.org/
|
||||
*
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\Repositories;
|
||||
|
||||
/**
|
||||
* Client storage interface
|
||||
* Client storage interface.
|
||||
*/
|
||||
interface ClientRepositoryInterface extends RepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Get a client
|
||||
* Get a client.
|
||||
*
|
||||
* @param string $clientIdentifier The client's identifier
|
||||
* @param string $grantType The grant type used
|
||||
* @param string $clientIdentifier The client's identifier
|
||||
* @param string $grantType The grant type used
|
||||
*
|
||||
* @return \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface
|
||||
*/
|
||||
|
@ -1,25 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* OAuth 2.0 MAC Token Interface
|
||||
* OAuth 2.0 MAC Token Interface.
|
||||
*
|
||||
* @package league/oauth2-server
|
||||
* @author Alex Bilbie <hello@alexbilbie.com>
|
||||
* @copyright Copyright (c) Alex Bilbie
|
||||
* @license http://mit-license.org/
|
||||
*
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\Storage;
|
||||
|
||||
use League\OAuth2\Server\Repositories\RepositoryInterface;
|
||||
|
||||
/**
|
||||
* MacTokenInterface
|
||||
* MacTokenInterface.
|
||||
*/
|
||||
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 $accessToken
|
||||
@ -27,9 +26,9 @@ interface MacTokenInterface extends RepositoryInterface
|
||||
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
|
||||
*/
|
||||
|
@ -1,39 +1,38 @@
|
||||
<?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>
|
||||
* @copyright Copyright (c) Alex Bilbie
|
||||
* @license http://mit-license.org/
|
||||
*
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\Repositories;
|
||||
|
||||
use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface;
|
||||
|
||||
/**
|
||||
* Refresh token interface
|
||||
* Refresh token interface.
|
||||
*/
|
||||
interface RefreshTokenRepositoryInterface extends RepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Create a new refresh token_name
|
||||
* Create a new refresh token_name.
|
||||
*
|
||||
* @param \League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface $refreshTokenEntity
|
||||
*/
|
||||
public function persistNewRefreshToken(RefreshTokenEntityInterface $refreshTokenEntity);
|
||||
|
||||
/**
|
||||
* Revoke the refresh token
|
||||
* Revoke the refresh token.
|
||||
*
|
||||
* @param string $tokenId
|
||||
*/
|
||||
public function revokeRefreshToken($tokenId);
|
||||
|
||||
/**
|
||||
* Check if the refresh token has been revoked
|
||||
* Check if the refresh token has been revoked.
|
||||
*
|
||||
* @param string $tokenId
|
||||
*
|
||||
|
@ -1,18 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* OAuth 2.0 Repository interface
|
||||
* OAuth 2.0 Repository interface.
|
||||
*
|
||||
* @package league/oauth2-server
|
||||
* @author Alex Bilbie <hello@alexbilbie.com>
|
||||
* @copyright Copyright (c) Alex Bilbie
|
||||
* @license http://mit-license.org/
|
||||
*
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\Repositories;
|
||||
|
||||
/**
|
||||
* Repository interface
|
||||
* Repository interface.
|
||||
*/
|
||||
interface RepositoryInterface
|
||||
{
|
||||
|
@ -1,23 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* OAuth 2.0 Scope storage interface
|
||||
* OAuth 2.0 Scope storage interface.
|
||||
*
|
||||
* @package league/oauth2-server
|
||||
* @author Alex Bilbie <hello@alexbilbie.com>
|
||||
* @copyright Copyright (c) Alex Bilbie
|
||||
* @license http://mit-license.org/
|
||||
*
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\Repositories;
|
||||
|
||||
/**
|
||||
* Scope interface
|
||||
* Scope interface.
|
||||
*/
|
||||
interface ScopeRepositoryInterface extends RepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Return information about a scope
|
||||
* Return information about a scope.
|
||||
*
|
||||
* @param string $identifier The scope identifier
|
||||
* @param string $grantType The grant type used in the request
|
||||
|
@ -5,7 +5,7 @@ namespace League\OAuth2\Server\Repositories;
|
||||
interface UserRepositoryInterface extends RepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Get a user entity
|
||||
* Get a user entity.
|
||||
*
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
|
@ -1,14 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* OAuth 2.0 Abstract Response Type
|
||||
* OAuth 2.0 Abstract Response Type.
|
||||
*
|
||||
* @package league/oauth2-server
|
||||
* @author Alex Bilbie <hello@alexbilbie.com>
|
||||
* @copyright Copyright (c) Alex Bilbie
|
||||
* @license http://mit-license.org/
|
||||
*
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\ResponseTypes;
|
||||
|
||||
use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface;
|
||||
|
@ -1,14 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* OAuth 2.0 Bearer Token Type
|
||||
* OAuth 2.0 Bearer Token Type.
|
||||
*
|
||||
* @package league/oauth2-server
|
||||
* @author Alex Bilbie <hello@alexbilbie.com>
|
||||
* @copyright Copyright (c) Alex Bilbie
|
||||
* @license http://mit-license.org/
|
||||
*
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\ResponseTypes;
|
||||
|
||||
use Lcobucci\JWT\Builder;
|
||||
@ -43,7 +42,7 @@ class BearerTokenResponse extends AbstractResponseType
|
||||
|
||||
$responseParams = [
|
||||
'token_type' => 'Bearer',
|
||||
'expires_in' => $expireDateTime - (new \DateTime)->getTimestamp(),
|
||||
'expires_in' => $expireDateTime - (new \DateTime())->getTimestamp(),
|
||||
'access_token' => (string) $jwtAccessToken,
|
||||
];
|
||||
|
||||
|
@ -1,14 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* OAuth 2.0 MAC Token Type
|
||||
* OAuth 2.0 MAC Token Type.
|
||||
*
|
||||
* @package league/oauth2-server
|
||||
* @author Alex Bilbie <hello@alexbilbie.com>
|
||||
* @copyright Copyright (c) Alex Bilbie
|
||||
* @license http://mit-license.org/
|
||||
*
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\TokenTypes;
|
||||
|
||||
use League\OAuth2\Server\Util\SecureKey;
|
||||
@ -16,7 +15,7 @@ use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* MAC Token Type
|
||||
* MAC Token Type.
|
||||
*/
|
||||
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'));
|
||||
|
||||
$response = [
|
||||
'access_token' => $this->getParam('access_token'),
|
||||
'token_type' => 'mac',
|
||||
'expires_in' => $this->getParam('expires_in'),
|
||||
'mac_key' => $macKey,
|
||||
'mac_algorithm' => 'hmac-sha-256',
|
||||
'access_token' => $this->getParam('access_token'),
|
||||
'token_type' => 'mac',
|
||||
'expires_in' => $this->getParam('expires_in'),
|
||||
'mac_key' => $macKey,
|
||||
'mac_algorithm' => 'hmac-sha-256',
|
||||
];
|
||||
|
||||
return $response;
|
||||
@ -121,9 +120,11 @@ class MAC extends AbstractTokenType implements TokenTypeInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent timing attack
|
||||
* @param string $knownString
|
||||
* @param string $userString
|
||||
* Prevent timing attack.
|
||||
*
|
||||
* @param string $knownString
|
||||
* @param string $userString
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function hash_equals($knownString, $userString)
|
||||
|
@ -1,14 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* OAuth 2.0 Response Type Interface
|
||||
* OAuth 2.0 Response Type Interface.
|
||||
*
|
||||
* @package league/oauth2-server
|
||||
* @author Alex Bilbie <hello@alexbilbie.com>
|
||||
* @copyright Copyright (c) Alex Bilbie
|
||||
* @license http://mit-license.org/
|
||||
*
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\ResponseTypes;
|
||||
|
||||
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
|
||||
* as attributes
|
||||
* as attributes.
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
*
|
||||
|
@ -62,7 +62,7 @@ class Server implements EmitterAwareInterface
|
||||
private $scopeRepository;
|
||||
|
||||
/**
|
||||
* New server instance
|
||||
* New server instance.
|
||||
*
|
||||
* @param \League\OAuth2\Server\Repositories\ClientRepositoryInterface $clientRepository
|
||||
* @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 \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\ResponseInterface|null $response
|
||||
*
|
||||
* @return \Psr\Http\Message\ResponseInterface
|
||||
* @throws \League\OAuth2\Server\Exception\OAuthServerException
|
||||
*
|
||||
* @return \Psr\Http\Message\ResponseInterface
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @return \Psr\Http\Message\ServerRequestInterface
|
||||
*
|
||||
* @throws \League\OAuth2\Server\Exception\OAuthServerException
|
||||
*
|
||||
* @return \Psr\Http\Message\ServerRequestInterface
|
||||
*/
|
||||
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
|
||||
*/
|
||||
|
@ -1,20 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* Public/private key encryption
|
||||
* Public/private key encryption.
|
||||
*
|
||||
* @package league/oauth2-server
|
||||
* @author Alex Bilbie <hello@alexbilbie.com>
|
||||
* @copyright Copyright (c) Alex Bilbie
|
||||
* @license http://mit-license.org/
|
||||
*
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\Utils;
|
||||
|
||||
class KeyCrypt
|
||||
{
|
||||
/**
|
||||
* Encrypt data with a private key
|
||||
* Encrypt data with a private key.
|
||||
*
|
||||
* @param string $unencryptedData
|
||||
* @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 $pathToPublicKey
|
||||
|
@ -1,31 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* OAuth 2.0 Secure key generator
|
||||
* OAuth 2.0 Secure key generator.
|
||||
*
|
||||
* @package php-loep/oauth2-server
|
||||
* @author Alex Bilbie <hello@alexbilbie.com>
|
||||
* @copyright Copyright (c) 2013 PHP League of Extraordinary Packages
|
||||
* @license http://mit-license.org/
|
||||
*
|
||||
* @link http://github.com/php-loep/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\Utils;
|
||||
|
||||
use League\OAuth2\Server\Exception\OAuthServerException;
|
||||
|
||||
|
||||
/**
|
||||
* SecureKey class
|
||||
* SecureKey class.
|
||||
*/
|
||||
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
|
||||
* @throws \League\OAuth2\Server\Exception\OAuthServerException
|
||||
*/
|
||||
public static function generate($len = 40)
|
||||
{
|
||||
@ -34,13 +33,13 @@ class SecureKey
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (\TypeError $e) {
|
||||
// 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) {
|
||||
// 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) {
|
||||
// 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
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?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");
|
||||
}
|
||||
|
@ -10,11 +10,11 @@ use League\OAuth2\Server\Entities\Interfaces\AuthCodeEntityInterface;
|
||||
use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface;
|
||||
use League\OAuth2\Server\Entities\ScopeEntity;
|
||||
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\AuthCodeRepositoryInterface;
|
||||
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
|
||||
use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
|
||||
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
|
||||
use Zend\Diactoros\ServerRequest;
|
||||
|
||||
class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
||||
@ -151,7 +151,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$serverRequest = new ServerRequest();
|
||||
$serverRequest = $serverRequest->withParsedBody([
|
||||
'client_id' => 'foo',
|
||||
'client_id' => 'foo',
|
||||
'client_secret' => 'foo',
|
||||
]);
|
||||
|
||||
@ -180,7 +180,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
||||
$serverRequest = new ServerRequest();
|
||||
$serverRequest = $serverRequest->withParsedBody([
|
||||
'client_id' => 'foo',
|
||||
'redirect_uri' => 'http://bar/foo'
|
||||
'redirect_uri' => 'http://bar/foo',
|
||||
]);
|
||||
|
||||
$validateClientMethod = $abstractGrantReflection->getMethod('validateClient');
|
||||
|
@ -42,7 +42,7 @@ class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$responseType = new StubResponseType();
|
||||
$grant->respondToRequest($serverRequest, $responseType, new \DateInterval('PT5M'));
|
||||
|
||||
|
||||
$this->assertTrue($responseType->getAccessToken() instanceof AccessTokenEntityInterface);
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ namespace LeagueTests\Grant;
|
||||
use League\OAuth2\Server\Entities\ClientEntity;
|
||||
use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface;
|
||||
use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface;
|
||||
use League\OAuth2\Server\Grant\PasswordGrant;
|
||||
use League\OAuth2\Server\Grant\RefreshTokenGrant;
|
||||
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
|
||||
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
|
||||
@ -14,7 +13,6 @@ use League\OAuth2\Server\Repositories\UserRepositoryInterface;
|
||||
use League\OAuth2\Server\Utils\KeyCrypt;
|
||||
use LeagueTests\Stubs\StubResponseType;
|
||||
use LeagueTests\Stubs\UserEntity;
|
||||
use OAuth2ServerExamples\Repositories\RefreshTokenRepository;
|
||||
use Zend\Diactoros\ServerRequest;
|
||||
|
||||
class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
||||
|
@ -4,11 +4,11 @@ namespace LeagueTests;
|
||||
|
||||
use League\OAuth2\Server\Entities\ClientEntity;
|
||||
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 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;
|
||||
|
||||
class ServerTest extends \PHPUnit_Framework_TestCase
|
||||
|
@ -11,7 +11,9 @@ use Zend\Diactoros\Response;
|
||||
|
||||
class StubResponseType extends AbstractResponseType
|
||||
{
|
||||
public function __construct() {}
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function getAccessToken()
|
||||
{
|
||||
@ -58,4 +60,4 @@ class StubResponseType extends AbstractResponseType
|
||||
{
|
||||
return new Response();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,4 +10,4 @@ class UserEntity implements UserEntityInterface
|
||||
{
|
||||
return 123;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user