Skip to content

Commit

Permalink
Wrong typing of the Grant Token endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
seba-aln committed Oct 18, 2024
1 parent 6acaa88 commit 1ed00d0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
33 changes: 18 additions & 15 deletions examples/GrantToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,38 @@

require_once __DIR__ . '/../vendor/autoload.php';

use PubNub\Models\Access\Permissions;
use PubNub\Models\Consumer\AccessManager\PNAccessManagerTokenResult;


$pnconfig = new \PubNub\PNConfiguration();
$pnconfig->setPublishKey('my-publish-key');
$pnconfig->setSubscribeKey('my-subscribe-key');
$pnconfig->setSecretKey('my-secret-key');
$pnconfig->setPublishKey(getenv("PUBLISH_PAM_KEY"));
$pnconfig->setSubscribeKey(getenv("SUBSCRIBE_PAM_KEY"));
$pnconfig->setSecretKey(getenv("SECRET_PAM_KEY"));
$pnconfig->setUuid('example-uuid');

$pubnub = new \PubNub\PubNub($pnconfig);

try {
$token = $pubnub->grantToken()
->ttl(30)
->authorizedUuid('my-uuid')
->authorizedUuid('example-uuid')
->addChannelResources([
'my-channel' => ['read' => true]
])
->sync();

/** @var PNAccessManagerTokenResult */
$parsedToken = $pubnub->parseToken($token);
$parsedToken->getTtl();
$parsedToken->getChannelResource('my-channel')
->hasRead();
print("Token granted: $token\n");

/** @var PNAccessManagerTokenResult */
$parsedToken = $pubnub->parseToken($token);

$tokensTTL = $parsedToken->getTtl();
$tokensMyChannelRead = $parsedToken->getChannelResource('my-channel')->hasRead();
$tokensMyChannelWrite = $parsedToken->getChannelResource('my-channel')->hasWrite();

print("Token TTL: $tokensTTL\n");
print("Token My Channel Read: " . (int)$tokensMyChannelRead . "\n");
print("Token My Channel Write: " . (int)$tokensMyChannelWrite . "\n");

} catch (\PubNub\Exceptions\PubNubServerException $e) {
var_dump($e->getBody());
}

var_dump(
$pubnub->parseToken($token)->toArray()
); die;
8 changes: 4 additions & 4 deletions src/PubNub/Endpoints/Access/GrantToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,18 +237,18 @@ public function buildPath()
}

/**
* @return PNAccessManagerGrantResult
* @return string
*/
public function sync(): PNAccessManagerGrantResult
public function sync(): string
{
return parent::sync();
}

/**
* @param string $token
* @return : PNAccessManagerGrantResult
* @return : string
*/
public function createResponse($response): PNAccessManagerGrantResult
public function createResponse($response): string

Check failure on line 251 in src/PubNub/Endpoints/Access/GrantToken.php

View workflow job for this annotation

GitHub Actions / Lint project

PHPDoc tag @return has invalid value (: string): Unexpected token ":", expected type at offset 47
{
return $response['data']['token'];
}
Expand Down

0 comments on commit 1ed00d0

Please sign in to comment.