Skip to content

Commit

Permalink
Change \OAuth\Server\Storage\ClientStorageInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
Vragov Roman committed Jun 24, 2024
1 parent 5c73ad9 commit 193916c
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 25 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"symfony/event-dispatcher": "^5.4|^6.0|^7.0",
"symfony/http-foundation": "^5.4|^6.0|^7.0",
"symfony/http-kernel": "^5.4|^6.0|^7.0",
"symfony/routing": "^5.4|^6.0|^7.0",
"symfony/security-bundle": "^5.4|^6.0|^7.0"
},
"require-dev": {
Expand Down
3 changes: 2 additions & 1 deletion src/Command/CreateClientCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace OAuth\Command;

use OAuth\Server\Storage\ClientStorageInterface;
use OAuth\Utils\Random;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -52,7 +53,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$io->title('Client Credentials');

$client = $this->clientStorage->createClient();
$client = $this->clientStorage->createClient(Random::generateToken(), Random::generateToken());

$client->setRedirectUris($input->getOption('redirect-uri'));
$client->setGrantTypes($input->getOption('grant-type'));
Expand Down
5 changes: 5 additions & 0 deletions src/DependencyInjection/OAuthServerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ public function load(array $configs, ContainerBuilder $container): void
$loader->load('command.php');
$loader->load('security.php');
}

public function getAlias(): string
{
return 'oauth_server';
}
}
2 changes: 1 addition & 1 deletion src/Doctrine/Repository/ClientRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

interface ClientRepositoryInterface
{
public function createClient(): ClientInterface;
public function createClient(string $publicId, ?string $secret): ClientInterface;

public function updateClient(ClientInterface $client): void;

Expand Down
4 changes: 2 additions & 2 deletions src/Doctrine/Storage/ClientStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public function __construct(
$this->repository = $repository;
}

public function createClient(): ClientInterface
public function createClient(string $publicId, ?string $secret): ClientInterface
{
return $this->repository->createClient();
return $this->repository->createClient($publicId, $secret);
}

public function updateClient(ClientInterface $client): void
Expand Down
2 changes: 2 additions & 0 deletions src/Model/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

interface ClientInterface extends UserInterface
{
public function setPublicId(string $publicId): self;

public function getPublicId(): string;

public function setSecret(?string $secret): self;
Expand Down
7 changes: 7 additions & 0 deletions src/OAuthServerBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
namespace OAuth;

use OAuth\DependencyInjection\Compiler\GrantExtensionsCompilerPass;
use OAuth\DependencyInjection\OAuthServerExtension;
use OAuth\DependencyInjection\Security\Factory\OAuthFactory;
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class OAuthServerBundle extends Bundle
Expand All @@ -21,4 +23,9 @@ public function build(ContainerBuilder $container): void
$extension->addAuthenticatorFactory(new OAuthFactory());
$container->addCompilerPass(new GrantExtensionsCompilerPass());
}

public function getContainerExtension(): ?ExtensionInterface
{
return new OAuthServerExtension();
}
}
15 changes: 0 additions & 15 deletions src/Resources/routing/token.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Server/Storage/ClientStorageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

interface ClientStorageInterface
{
public function createClient(): ClientInterface;
public function createClient(string $publicId, ?string $secret): ClientInterface;

public function updateClient(ClientInterface $client): void;

Expand Down
7 changes: 7 additions & 0 deletions tests/Stub/Entity/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public function __construct(string $publicId)
$this->randomId = $publicId;
}

public function setPublicId(string $publicId): self
{
$this->randomId = $publicId;

return $this;
}

public function getPublicId(): string
{
return $this->randomId;
Expand Down
7 changes: 3 additions & 4 deletions tests/Stub/Repository/ClientRepositoryStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@
use OAuth\Doctrine\Repository\ClientRepositoryInterface;
use OAuth\Model\ClientInterface;
use OAuth\Tests\Stub\Entity\Client;
use OAuth\Utils\Random;

class ClientRepositoryStub implements ClientRepositoryInterface
{
/** @var array<string, ClientInterface> */
private array $tokens = [];

public function createClient(): ClientInterface
public function createClient(string $publicId, ?string $secret): ClientInterface
{
$client = new Client(Random::generateToken());
$client->setSecret(Random::generateToken());
$client = new Client($publicId);
$client->setSecret($secret);

$this->tokens[$client->getPublicId()] = $client;

Expand Down

0 comments on commit 193916c

Please sign in to comment.