mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-23 05:29:52 +05:30
Inject client into getUserEntityByUserCredentials method
This commit is contained in:
parent
ca54a387c8
commit
09770dc537
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace OAuth2ServerExamples\Repositories;
|
namespace OAuth2ServerExamples\Repositories;
|
||||||
|
|
||||||
|
use League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface;
|
||||||
use League\OAuth2\Server\Entities\Interfaces\ScopeEntityInterface;
|
use League\OAuth2\Server\Entities\Interfaces\ScopeEntityInterface;
|
||||||
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
|
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
|
||||||
use OAuth2ServerExamples\Entities\ScopeEntity;
|
use OAuth2ServerExamples\Entities\ScopeEntity;
|
||||||
@ -13,15 +14,21 @@ class UserRepository implements UserRepositoryInterface
|
|||||||
/**
|
/**
|
||||||
* Get a user entity.
|
* Get a user entity.
|
||||||
*
|
*
|
||||||
* @param string $username
|
* @param string $username
|
||||||
* @param string $password
|
* @param string $password
|
||||||
* @param string $grantType The grant type used
|
* @param string $grantType The grant type used
|
||||||
* @param ScopeEntityInterface[] $scopes
|
* @param \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface $clientEntity
|
||||||
|
* @param ScopeEntityInterface[] $scopes
|
||||||
*
|
*
|
||||||
* @return \League\OAuth2\Server\Entities\Interfaces\UserEntityInterface
|
* @return \League\OAuth2\Server\Entities\Interfaces\UserEntityInterface
|
||||||
*/
|
*/
|
||||||
public function getUserEntityByUserCredentials($username, $password, $grantType, array &$scopes)
|
public function getUserEntityByUserCredentials(
|
||||||
{
|
$username,
|
||||||
|
$password,
|
||||||
|
$grantType,
|
||||||
|
ClientEntityInterface $clientEntity,
|
||||||
|
array &$scopes
|
||||||
|
) {
|
||||||
if ($username === 'alex' && $password === 'whisky') {
|
if ($username === 'alex' && $password === 'whisky') {
|
||||||
$scope = new ScopeEntity();
|
$scope = new ScopeEntity();
|
||||||
$scope->setIdentifier('email');
|
$scope->setIdentifier('email');
|
||||||
|
@ -125,6 +125,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant
|
|||||||
$usernameParameter,
|
$usernameParameter,
|
||||||
$passwordParameter,
|
$passwordParameter,
|
||||||
$this->getIdentifier(),
|
$this->getIdentifier(),
|
||||||
|
$client,
|
||||||
$scopes
|
$scopes
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -123,6 +123,7 @@ class ImplicitGrant extends AbstractAuthorizeGrant
|
|||||||
$usernameParameter,
|
$usernameParameter,
|
||||||
$passwordParameter,
|
$passwordParameter,
|
||||||
$this->getIdentifier(),
|
$this->getIdentifier(),
|
||||||
|
$client,
|
||||||
$scopes
|
$scopes
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
namespace League\OAuth2\Server\Grant;
|
namespace League\OAuth2\Server\Grant;
|
||||||
|
|
||||||
use League\Event\Event;
|
use League\Event\Event;
|
||||||
|
use League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface;
|
||||||
use League\OAuth2\Server\Entities\Interfaces\ScopeEntityInterface;
|
use League\OAuth2\Server\Entities\Interfaces\ScopeEntityInterface;
|
||||||
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;
|
||||||
@ -49,7 +50,7 @@ class PasswordGrant extends AbstractGrant
|
|||||||
// Validate request
|
// Validate request
|
||||||
$client = $this->validateClient($request);
|
$client = $this->validateClient($request);
|
||||||
$scopes = $this->validateScopes($this->getRequestParameter('scope', $request), $client);
|
$scopes = $this->validateScopes($this->getRequestParameter('scope', $request), $client);
|
||||||
$user = $this->validateUser($request, $scopes);
|
$user = $this->validateUser($request, $client, $scopes);
|
||||||
|
|
||||||
// Issue and persist new tokens
|
// Issue and persist new tokens
|
||||||
$accessToken = $this->issueAccessToken($accessTokenTTL, $client, $user->getIdentifier(), $scopes);
|
$accessToken = $this->issueAccessToken($accessTokenTTL, $client, $user->getIdentifier(), $scopes);
|
||||||
@ -63,14 +64,14 @@ class PasswordGrant extends AbstractGrant
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Psr\Http\Message\ServerRequestInterface $request
|
* @param \Psr\Http\Message\ServerRequestInterface $request
|
||||||
* @param ScopeEntityInterface[] $scopes
|
* @param \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface $client
|
||||||
*
|
* @param ScopeEntityInterface[] $scopes
|
||||||
* @throws \League\OAuth2\Server\Exception\OAuthServerException
|
|
||||||
*
|
*
|
||||||
* @return \League\OAuth2\Server\Entities\Interfaces\UserEntityInterface
|
* @return \League\OAuth2\Server\Entities\Interfaces\UserEntityInterface
|
||||||
|
* @throws \League\OAuth2\Server\Exception\OAuthServerException
|
||||||
*/
|
*/
|
||||||
protected function validateUser(ServerRequestInterface $request, array &$scopes)
|
protected function validateUser(ServerRequestInterface $request, ClientEntityInterface $client, array &$scopes)
|
||||||
{
|
{
|
||||||
$username = $this->getRequestParameter('username', $request);
|
$username = $this->getRequestParameter('username', $request);
|
||||||
if (is_null($username)) {
|
if (is_null($username)) {
|
||||||
@ -86,6 +87,7 @@ class PasswordGrant extends AbstractGrant
|
|||||||
$username,
|
$username,
|
||||||
$password,
|
$password,
|
||||||
$this->getIdentifier(),
|
$this->getIdentifier(),
|
||||||
|
$client,
|
||||||
$scopes
|
$scopes
|
||||||
);
|
);
|
||||||
if (!$user instanceof UserEntityInterface) {
|
if (!$user instanceof UserEntityInterface) {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace League\OAuth2\Server\Repositories;
|
namespace League\OAuth2\Server\Repositories;
|
||||||
|
|
||||||
|
use League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface;
|
||||||
use League\OAuth2\Server\Entities\Interfaces\ScopeEntityInterface;
|
use League\OAuth2\Server\Entities\Interfaces\ScopeEntityInterface;
|
||||||
|
|
||||||
interface UserRepositoryInterface extends RepositoryInterface
|
interface UserRepositoryInterface extends RepositoryInterface
|
||||||
@ -9,12 +10,19 @@ interface UserRepositoryInterface extends RepositoryInterface
|
|||||||
/**
|
/**
|
||||||
* Get a user entity.
|
* Get a user entity.
|
||||||
*
|
*
|
||||||
* @param string $username
|
* @param string $username
|
||||||
* @param string $password
|
* @param string $password
|
||||||
* @param string $grantType The grant type used
|
* @param string $grantType The grant type used
|
||||||
* @param ScopeEntityInterface[] $scopes
|
* @param \League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface $clientEntity
|
||||||
|
* @param ScopeEntityInterface[] $scopes
|
||||||
*
|
*
|
||||||
* @return \League\OAuth2\Server\Entities\Interfaces\UserEntityInterface
|
* @return \League\OAuth2\Server\Entities\Interfaces\UserEntityInterface
|
||||||
*/
|
*/
|
||||||
public function getUserEntityByUserCredentials($username, $password, $grantType, array &$scopes);
|
public function getUserEntityByUserCredentials(
|
||||||
|
$username,
|
||||||
|
$password,
|
||||||
|
$grantType,
|
||||||
|
ClientEntityInterface $clientEntity,
|
||||||
|
array &$scopes
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user