-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from trikoder/v3.x
Merge v3.x into master
- Loading branch information
Showing
22 changed files
with
495 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Trikoder\Bundle\OAuth2Bundle\League\AuthorizationServer; | ||
|
||
use League\OAuth2\Server\AuthorizationServer; | ||
|
||
final class GrantConfigurator | ||
{ | ||
/** | ||
* @var iterable|GrantTypeInterface[] | ||
*/ | ||
private $grants; | ||
|
||
public function __construct(iterable $grants) | ||
{ | ||
$this->grants = $grants; | ||
} | ||
|
||
public function __invoke(AuthorizationServer $authorizationServer): void | ||
{ | ||
foreach ($this->grants as $grant) { | ||
$authorizationServer->enableGrantType($grant, $grant->getAccessTokenTTL()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Trikoder\Bundle\OAuth2Bundle\League\AuthorizationServer; | ||
|
||
use DateInterval; | ||
use League\OAuth2\Server\Grant\GrantTypeInterface as LeagueGrantTypeInterface; | ||
|
||
interface GrantTypeInterface extends LeagueGrantTypeInterface | ||
{ | ||
public function getAccessTokenTTL(): ?DateInterval; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Trikoder\Bundle\OAuth2Bundle\Service; | ||
|
||
use Trikoder\Bundle\OAuth2Bundle\Model\Client; | ||
|
||
/** | ||
* @api | ||
*/ | ||
interface ClientFinderInterface | ||
{ | ||
public function find(string $identifier): ?Client; | ||
} |
101 changes: 101 additions & 0 deletions
101
Service/CredentialsRevoker/DoctrineCredentialsRevoker.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Trikoder\Bundle\OAuth2Bundle\Service\CredentialsRevoker; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use Symfony\Component\Security\Core\User\UserInterface; | ||
use Trikoder\Bundle\OAuth2Bundle\Model\AccessToken; | ||
use Trikoder\Bundle\OAuth2Bundle\Model\AuthorizationCode; | ||
use Trikoder\Bundle\OAuth2Bundle\Model\Client; | ||
use Trikoder\Bundle\OAuth2Bundle\Model\RefreshToken; | ||
use Trikoder\Bundle\OAuth2Bundle\Service\CredentialsRevokerInterface; | ||
|
||
final class DoctrineCredentialsRevoker implements CredentialsRevokerInterface | ||
{ | ||
/** | ||
* @var EntityManagerInterface | ||
*/ | ||
private $entityManager; | ||
|
||
public function __construct(EntityManagerInterface $entityManager) | ||
{ | ||
$this->entityManager = $entityManager; | ||
} | ||
|
||
public function revokeCredentialsForUser(UserInterface $user): void | ||
{ | ||
$userIdentifier = $user->getUsername(); | ||
|
||
$this->entityManager->createQueryBuilder() | ||
->update(AccessToken::class, 'at') | ||
->set('at.revoked', true) | ||
->where('at.userIdentifier = :userIdentifier') | ||
->setParameter('userIdentifier', $userIdentifier) | ||
->getQuery() | ||
->execute(); | ||
|
||
$queryBuilder = $this->entityManager->createQueryBuilder(); | ||
$queryBuilder | ||
->update(RefreshToken::class, 'rt') | ||
->set('rt.revoked', true) | ||
->where($queryBuilder->expr()->in( | ||
'rt.accessToken', | ||
$this->entityManager->createQueryBuilder() | ||
->select('at.identifier') | ||
->from(AccessToken::class, 'at') | ||
->where('at.userIdentifier = :userIdentifier') | ||
->getDQL() | ||
)) | ||
->setParameter('userIdentifier', $userIdentifier) | ||
->getQuery() | ||
->execute(); | ||
|
||
$this->entityManager->createQueryBuilder() | ||
->update(AuthorizationCode::class, 'ac') | ||
->set('ac.revoked', true) | ||
->where('ac.userIdentifier = :userIdentifier') | ||
->setParameter('userIdentifier', $userIdentifier) | ||
->getQuery() | ||
->execute(); | ||
} | ||
|
||
public function revokeCredentialsForClient(Client $client): void | ||
{ | ||
$doctrineClient = $this->entityManager | ||
->getRepository(Client::class) | ||
->findOneBy(['identifier' => $client->getIdentifier()]); | ||
|
||
$this->entityManager->createQueryBuilder() | ||
->update(AccessToken::class, 'at') | ||
->set('at.revoked', true) | ||
->where('at.client = :client') | ||
->setParameter('client', $doctrineClient) | ||
->getQuery() | ||
->execute(); | ||
|
||
$queryBuilder = $this->entityManager->createQueryBuilder(); | ||
$queryBuilder->update(RefreshToken::class, 'rt') | ||
->set('rt.revoked', true) | ||
->where($queryBuilder->expr()->in( | ||
'rt.accessToken', | ||
$this->entityManager->createQueryBuilder() | ||
->select('at.identifier') | ||
->from(AccessToken::class, 'at') | ||
->where('at.client = :client') | ||
->getDQL() | ||
)) | ||
->setParameter('client', $doctrineClient) | ||
->getQuery() | ||
->execute(); | ||
|
||
$this->entityManager->createQueryBuilder() | ||
->update(AuthorizationCode::class, 'ac') | ||
->set('ac.revoked', true) | ||
->where('ac.client = :client') | ||
->setParameter('client', $doctrineClient) | ||
->getQuery() | ||
->execute(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Trikoder\Bundle\OAuth2Bundle\Service; | ||
|
||
use Symfony\Component\Security\Core\User\UserInterface; | ||
use Trikoder\Bundle\OAuth2Bundle\Model\Client; | ||
|
||
/** | ||
* Service responsible for revoking credentials on client-level and user-level. | ||
* Credentials = access tokens, refresh tokens and authorization codes. | ||
* | ||
* @api | ||
*/ | ||
interface CredentialsRevokerInterface | ||
{ | ||
public function revokeCredentialsForUser(UserInterface $user): void; | ||
|
||
public function revokeCredentialsForClient(Client $client): void; | ||
} |
Oops, something went wrong.