Skip to content

Commit

Permalink
Add generateJwtToken() method (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
fre5h authored Dec 6, 2024
1 parent 543c394 commit 67ab273
Show file tree
Hide file tree
Showing 41 changed files with 162 additions and 101 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

## Features 🎁

- [x] Compatible with latest [Centrifugo 5.4.5](https://github.com/centrifugal/centrifugo/releases/tag/v5.4.5) 🚀
- [x] Compatible with latest [Centrifugo 5.4.7](https://github.com/centrifugal/centrifugo/releases/tag/v5.4.7) 🚀
- [x] Wrapper over [Centrifugo HTTP API](https://centrifugal.dev/docs/server/server_api#http-api) 🔌
- [X] Authentication with JWT token (HMAC algorithm) for [anonymous](./Resources/docs/authentication.md#anonymous), [authenticated user](./Resources/docs/authentication.md#authenticated-user) and [private channel](./Resources/docs/authentication.md#private-channel) 🗝️
- [x] [Batch request](./Resources/docs/centrifugo_service_methods.md#batch-request) in [JSON streaming format](https://en.wikipedia.org/wiki/JSON_streaming) 💪
Expand All @@ -35,7 +35,7 @@ $ composer req fresh/centrifugo-bundle

| Bundle Version (X.Y.Z) | PHP | Symfony | Comment |
|:----------------------:|:--------:|:-------:|:--------------------|
| `6.1.*` | `>= 8.3` | `7.*` | **Current version** |
| `6.2.*` | `>= 8.3` | `7.*` | **Current version** |
| `5.3.*` | `>= 8.2` | `7.*` | Previous version |

By default, [Symfony Flex](https://symfony.com/doc/current/setup/flex.html) adds this bundle to the `config/bundles.php` file and adds required environment variables into `.env` file.
Expand Down
23 changes: 23 additions & 0 deletions Service/Credentials/CredentialsGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,29 @@ public function generateJwtTokenForUser(CentrifugoUserInterface|CentrifugoUserMe
return $this->jwtGenerator->generateToken($jwtPayload);
}

/**
* @param string $subject
* @param array $info
* @param array $meta
* @param string|null $base64info
* @param array $channels
*
* @return string
*/
public function generateJwtToken(string $subject, array $info = [], array $meta = [], ?string $base64info = null, array $channels = []): string
{
$jwtPayload = new JwtPayload(
subject: $subject,
info: $info,
meta: $meta,
expirationTime: $this->getExpirationTime(),
base64info: $base64info,
channels: $channels,
);

return $this->jwtGenerator->generateToken($jwtPayload);
}

/**
* @param string|null $base64info
* @param array $channels
Expand Down
4 changes: 2 additions & 2 deletions Tests/Command/Argument/ArgumentChannelTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
*/
final class ArgumentChannelTraitTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoChecker|MockObject $centrifugoChecker;
private CentrifugoInterface&MockObject $centrifugo;
private CentrifugoChecker&MockObject $centrifugoChecker;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
4 changes: 2 additions & 2 deletions Tests/Command/Argument/ArgumentChannelsTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
*/
final class ArgumentChannelsTraitTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoChecker|MockObject $centrifugoChecker;
private CentrifugoInterface&MockObject $centrifugo;
private CentrifugoChecker&MockObject $centrifugoChecker;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
4 changes: 2 additions & 2 deletions Tests/Command/Argument/ArgumentDataTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
*/
final class ArgumentDataTraitTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoChecker|MockObject $centrifugoChecker;
private CentrifugoInterface&MockObject $centrifugo;
private CentrifugoChecker&MockObject $centrifugoChecker;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
2 changes: 1 addition & 1 deletion Tests/Command/Argument/ArgumentUserTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
final class ArgumentUserTraitTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoInterface&MockObject $centrifugo;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
4 changes: 2 additions & 2 deletions Tests/Command/BroadcastCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
*/
final class BroadcastCommandTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoChecker|MockObject $centrifugoChecker;
private CentrifugoInterface&MockObject $centrifugo;
private CentrifugoChecker&MockObject $centrifugoChecker;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
2 changes: 1 addition & 1 deletion Tests/Command/ChannelsCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
final class ChannelsCommandTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoInterface&MockObject $centrifugo;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
2 changes: 1 addition & 1 deletion Tests/Command/DisconnectCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
final class DisconnectCommandTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoInterface&MockObject $centrifugo;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
4 changes: 2 additions & 2 deletions Tests/Command/HistoryCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
*/
final class HistoryCommandTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoChecker|MockObject $centrifugoChecker;
private CentrifugoInterface&MockObject $centrifugo;
private CentrifugoChecker&MockObject $centrifugoChecker;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
4 changes: 2 additions & 2 deletions Tests/Command/HistoryRemoveCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
*/
final class HistoryRemoveCommandTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoChecker|MockObject $centrifugoChecker;
private CentrifugoInterface&MockObject $centrifugo;
private CentrifugoChecker&MockObject $centrifugoChecker;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
2 changes: 1 addition & 1 deletion Tests/Command/InfoCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
final class InfoCommandTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoInterface&MockObject $centrifugo;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
4 changes: 2 additions & 2 deletions Tests/Command/Option/OptionBase64DataTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
*/
final class OptionBase64DataTraitTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoChecker|MockObject $centrifugoChecker;
private CentrifugoInterface&MockObject $centrifugo;
private CentrifugoChecker&MockObject $centrifugoChecker;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
4 changes: 2 additions & 2 deletions Tests/Command/Option/OptionBase64InfoTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
*/
final class OptionBase64InfoTraitTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoChecker|MockObject $centrifugoChecker;
private CentrifugoInterface&MockObject $centrifugo;
private CentrifugoChecker&MockObject $centrifugoChecker;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
4 changes: 2 additions & 2 deletions Tests/Command/Option/OptionDataTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
*/
final class OptionDataTraitTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoChecker|MockObject $centrifugoChecker;
private CentrifugoInterface&MockObject $centrifugo;
private CentrifugoChecker&MockObject $centrifugoChecker;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
2 changes: 1 addition & 1 deletion Tests/Command/Option/OptionDisconnectCodeTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
final class OptionDisconnectCodeTraitTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoInterface&MockObject $centrifugo;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
2 changes: 1 addition & 1 deletion Tests/Command/Option/OptionDisconnectReasonTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
final class OptionDisconnectReasonTraitTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoInterface&MockObject $centrifugo;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
4 changes: 2 additions & 2 deletions Tests/Command/Option/OptionEpochTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
*/
final class OptionEpochTraitTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoChecker|MockObject $centrifugoChecker;
private CentrifugoInterface&MockObject $centrifugo;
private CentrifugoChecker&MockObject $centrifugoChecker;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
2 changes: 1 addition & 1 deletion Tests/Command/Option/OptionExpireAtTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
final class OptionExpireAtTraitTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoInterface&MockObject $centrifugo;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
2 changes: 1 addition & 1 deletion Tests/Command/Option/OptionExpiredTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
final class OptionExpiredTraitTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoInterface&MockObject $centrifugo;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
4 changes: 2 additions & 2 deletions Tests/Command/Option/OptionInfoTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
*/
final class OptionInfoTraitTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoChecker|MockObject $centrifugoChecker;
private CentrifugoInterface&MockObject $centrifugo;
private CentrifugoChecker&MockObject $centrifugoChecker;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
4 changes: 2 additions & 2 deletions Tests/Command/Option/OptionLimitTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
*/
final class OptionLimitTraitTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoChecker|MockObject $centrifugoChecker;
private CentrifugoInterface&MockObject $centrifugo;
private CentrifugoChecker&MockObject $centrifugoChecker;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
4 changes: 2 additions & 2 deletions Tests/Command/Option/OptionOffsetTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
*/
final class OptionOffsetTraitTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoChecker|MockObject $centrifugoChecker;
private CentrifugoInterface&MockObject $centrifugo;
private CentrifugoChecker&MockObject $centrifugoChecker;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
4 changes: 2 additions & 2 deletions Tests/Command/Option/OptionReverseTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
*/
final class OptionReverseTraitTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoChecker|MockObject $centrifugoChecker;
private CentrifugoInterface&MockObject $centrifugo;
private CentrifugoChecker&MockObject $centrifugoChecker;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
4 changes: 2 additions & 2 deletions Tests/Command/Option/OptionSkipHistoryTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
*/
final class OptionSkipHistoryTraitTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoChecker|MockObject $centrifugoChecker;
private CentrifugoInterface&MockObject $centrifugo;
private CentrifugoChecker&MockObject $centrifugoChecker;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
4 changes: 2 additions & 2 deletions Tests/Command/Option/OptionTagsTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
*/
final class OptionTagsTraitTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoChecker|MockObject $centrifugoChecker;
private CentrifugoInterface&MockObject $centrifugo;
private CentrifugoChecker&MockObject $centrifugoChecker;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
4 changes: 2 additions & 2 deletions Tests/Command/PresenceCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
*/
final class PresenceCommandTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoChecker|MockObject $centrifugoChecker;
private CentrifugoInterface&MockObject $centrifugo;
private CentrifugoChecker&MockObject $centrifugoChecker;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
4 changes: 2 additions & 2 deletions Tests/Command/PresenceStatsCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
*/
final class PresenceStatsCommandTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoChecker|MockObject $centrifugoChecker;
private CentrifugoInterface&MockObject $centrifugo;
private CentrifugoChecker&MockObject $centrifugoChecker;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
4 changes: 2 additions & 2 deletions Tests/Command/PublishCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
*/
final class PublishCommandTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoChecker|MockObject $centrifugoChecker;
private CentrifugoInterface&MockObject $centrifugo;
private CentrifugoChecker&MockObject $centrifugoChecker;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
2 changes: 1 addition & 1 deletion Tests/Command/RefreshCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
final class RefreshCommandTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoInterface&MockObject $centrifugo;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
4 changes: 2 additions & 2 deletions Tests/Command/SubscribeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
*/
final class SubscribeCommandTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoChecker|MockObject $centrifugoChecker;
private CentrifugoInterface&MockObject $centrifugo;
private CentrifugoChecker&MockObject $centrifugoChecker;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
4 changes: 2 additions & 2 deletions Tests/Command/UnsubscribeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
*/
final class UnsubscribeCommandTest extends TestCase
{
private CentrifugoInterface|MockObject $centrifugo;
private CentrifugoChecker|MockObject $centrifugoChecker;
private CentrifugoInterface&MockObject $centrifugo;
private CentrifugoChecker&MockObject $centrifugoChecker;
private Command $command;
private Application $application;
private CommandTester $commandTester;
Expand Down
2 changes: 1 addition & 1 deletion Tests/DataCollector/CommandCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
final class CommandCollectorTest extends TestCase
{
private CommandHistoryLogger|MockObject $commandHistoryLogger;
private CommandHistoryLogger&MockObject $commandHistoryLogger;
private CentrifugoCollector $centrifugoCollector;

protected function setUp(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class RegisterCentrifugoPassTest extends TestCase
{
use ConsecutiveParams;

private ContainerBuilder|MockObject $containerBuilder;
private ContainerBuilder&MockObject $containerBuilder;
private RegisterCentrifugoPass $registerCentrifugoPass;

protected function setUp(): void
Expand Down
4 changes: 2 additions & 2 deletions Tests/Exception/CentrifugoErrorExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
final class CentrifugoErrorExceptionTest extends TestCase
{
private CentrifugoErrorException $exception;
private CommandInterface|MockObject $command;
private ResponseInterface|MockObject $response;
private CommandInterface&MockObject $command;
private ResponseInterface&MockObject $response;

protected function setUp(): void
{
Expand Down
2 changes: 1 addition & 1 deletion Tests/Exception/CentrifugoExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
final class CentrifugoExceptionTest extends TestCase
{
private CentrifugoException $exception;
private ResponseInterface|MockObject $response;
private ResponseInterface&MockObject $response;

protected function setUp(): void
{
Expand Down
Loading

0 comments on commit 67ab273

Please sign in to comment.