Skip to content

Commit

Permalink
PubNub SDK v4.2.0 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
client-engineering-bot committed Feb 2, 2021
1 parent 18c60ce commit 4d0303d
Show file tree
Hide file tree
Showing 98 changed files with 8,087 additions and 114 deletions.
17 changes: 16 additions & 1 deletion .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
name: php
version: 4.1.7
version: 4.2.0
schema: 1
scm: github.com/pubnub/php
changelog:
- version: v4.2.0
date: Feb 2, 21
changes:
-
text: "Add support for device channel registration with apns2."
type: feature
-
text: "Allows management of users and channels with metadata."
type: feature
-
text: "Implement v2 signatures required for push and objects."
type: feature
-
text: "Implement v2 grant endpoint with support for user level grant."
type: feature
- version: v4.1.7
date: Sep 14, 20
changes:
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## [v4.2.0](https://github.com/pubnub/php/releases/tag/v4.2.0)
February-2-2021

- 🌟️ Add support for device channel registration with apns2.
- 🌟️ Allows management of users and channels with metadata.
- 🌟️ Implement v2 signatures required for push and objects.
- 🌟️ Implement v2 grant endpoint with support for user level grant.

## [v4.1.7](https://github.com/pubnub/php/releases/tag/v4.1.7)
September-14-2020

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# PubNub PHP SDK (V4)
[![Build Status](https://travis-ci.org/pubnub/php.svg?branch=master)](https://travis-ci.org/pubnub/php)
[![Build Status](https://travis-ci.com/pubnub/php.svg?branch=master)](https://travis-ci.com/pubnub/php)
[![codecov](https://codecov.io/gh/pubnub/php/branch/master/graph/badge.svg)](https://codecov.io/gh/pubnub/php)
[![Docs](https://img.shields.io/badge/docs-online-blue.svg)](https://www.pubnub.com/docs/php/pubnub-php-sdk)

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"keywords": ["api", "real-time", "realtime", "real time", "ajax", "push"],
"homepage": "http://www.pubnub.com/",
"license": "MIT",
"version": "4.1.7",
"version": "4.2.0",
"authors": [
{
"name": "PubNub",
Expand Down
83 changes: 81 additions & 2 deletions src/PubNub/Endpoints/Access/Grant.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@

class Grant extends Endpoint
{
const PATH = "/v1/auth/grant/sub-key/%s";
const PATH = "/v2/auth/grant/sub-key/%s";

/** @var string[] */
protected $authKeys = [];

/** @var string[] */
protected $channels = [];

/** @var string[] */
protected $uuids = [];

/** @var string[] */
protected $groups = [];

Expand All @@ -35,6 +38,15 @@ class Grant extends Endpoint
/** @var bool */
protected $delete;

/** @var bool */
protected $get;

/** @var bool */
protected $update;

/** @var bool */
protected $join;

/** @var int */
protected $ttl;

Expand All @@ -58,6 +70,16 @@ public function channels($channels)
return $this;
}

/**
* @param string|string[] $uuids
* @return $this
*/
public function uuids($uuids)
{
$this->uuids = PubNubUtil::extendArray($this->uuids, $uuids);
return $this;
}

/**
* @param string[]|string $channelsGroups
* @return $this
Expand Down Expand Up @@ -113,6 +135,39 @@ public function delete($flag)
return $this;
}

/**
* @param bool $flag
* @return $this
*/
public function get($flag)
{
$this->get = $flag;

return $this;
}

/**
* @param bool $flag
* @return $this
*/
public function update($flag)
{
$this->update = $flag;

return $this;
}

/**
* @param bool $flag
* @return $this
*/
public function join($flag)
{
$this->join = $flag;

return $this;
}

/**
* Set time in minutes for which granted permissions are valid
*
Expand Down Expand Up @@ -140,7 +195,7 @@ public function validateParams()
$this->validateSubscribeKey();
$this->validateSecretKey();

if ($this->write === null && $this->read === null && $this->manage === null) {
if ($this->write === null && $this->read === null && $this->manage === null && $this->get === null && $this->update === null && $this->join === null) {
throw new PubNubValidationException("At least one flag should be specified");
}
}
Expand Down Expand Up @@ -168,6 +223,18 @@ public function customParams()
$params["d"] = ($this->delete) ? "1" : "0";
}

if ($this->get !== null) {
$params["g"] = ($this->get) ? "1" : "0";
}

if ($this->update !== null) {
$params["u"] = ($this->update) ? "1" : "0";
}

if ($this->join !== null) {
$params["j"] = ($this->join) ? "1" : "0";
}

if (count($this->authKeys) > 0) {
$params["auth"] = PubNubUtil::joinItems($this->authKeys);
}
Expand All @@ -176,6 +243,10 @@ public function customParams()
$params["channel"] = PubNubUtil::joinItems($this->channels);
}

if (count($this->uuids) > 0) {
$params["target-uuid"] = PubNubUtil::joinItems($this->uuids);
}

if (count($this->groups) > 0) {
$params["channel-group"] = PubNubUtil::joinItems($this->groups);
}
Expand Down Expand Up @@ -246,6 +317,14 @@ public function getAffectedChannelGroups()
return $this->groups;
}

/**
* @return \string[]
*/
public function getAffectedUsers()
{
return $this->uuids;
}

/**
* @return int
*/
Expand Down
56 changes: 41 additions & 15 deletions src/PubNub/Endpoints/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use PubNub\Models\ResponseHelpers\ResponseInfo;
use PubNub\PubNub;
use PubNub\PubNubUtil;
use PubNub\Managers\TelemetryManager;
use Requests_Exception;


Expand Down Expand Up @@ -166,31 +165,45 @@ protected function defaultParams()
* @return array
*/
protected function buildParams()
{
{
$params = array_merge($this->customParams(), $this->defaultParams());
$config = $this->pubnub->getConfiguration();

if ($config->getSecretKey()) {
$params['timestamp'] = (string) $this->pubnub->timestamp();
$signedInput = $config->getSubscribeKey() . "\n" . $config->getPublishKey() . "\n";

if ($this->getOperationType() == PNOperationType::PNAccessManagerGrant ||
$this->getOperationType() == PNOperationType::PNAccessManagerRevoke) {
$signedInput .= "grant\n";
} else if ($this->getOperationType() === PNOperationType::PNAccessManagerAudit) {
$signedInput .= "audit\n";
} else {
$signedInput .= $this->buildPath() . "\n";
$httpMethod = $this->httpMethod();

if ($this->getName() == "Publish") {
// This is because of a server-side bug, old publish using post should be deprecated
$httpMethod = PNHttpMethod::GET;
}

$signedInput .= PubNubUtil::preparePamParams($params);
$params['timestamp'] = (string) $this->pubnub->timestamp();

ksort($params);

$params['signature'] = PubNubUtil::signSha256(
$signedInput = $httpMethod
. "\n"
. $config->getPublishKey()
. "\n"
. $this->buildPath()
. "\n"
. PubNubUtil::preparePamParams($params)
. "\n";

if (PNHttpMethod::POST == $this->httpMethod() || PNHttpMethod::PATCH == $this->httpMethod()) {
$signedInput .= $this->buildData();
}

$signature = 'v2.' . PubNubUtil::signSha256(
$this->pubnub->getConfiguration()->getSecretKey(),
$signedInput
);
}

$signature = preg_replace('/=+$/', '', $signature);

$params['signature'] = $signature;
}

if ($this->getOperationType() == PNOperationType::PNPublishOperation
&& array_key_exists('meta', $this->customParams())) {
$params['meta'] = PubNubUtil::urlEncode($params['meta']);
Expand All @@ -217,6 +230,10 @@ protected function buildParams()
$params['channel'] = PubNubUtil::urlEncode($params['channel']);
}

if (array_key_exists('channel-group', $params)) {
$params['channel-group'] = PubNubUtil::urlEncode($params['channel-group']);
}

return $params;
}

Expand Down Expand Up @@ -310,6 +327,9 @@ protected function invokeRequest()
if ($this->httpMethod() == PNHttpMethod::POST) {
$method = \Requests::POST;
}
else if ($this->httpMethod() == PNHttpMethod::PATCH) {
$method = \Requests::PATCH;
}
else if ($this->httpMethod() == PNHttpMethod::DELETE) {
$method = \Requests::DELETE;
}
Expand Down Expand Up @@ -499,6 +519,7 @@ private function createStatus($category, $response, $responseInfo, $exception)
$pnStatus->setCategory($category);
$pnStatus->setAffectedChannels($this->getAffectedChannels());
$pnStatus->setAffectedChannelGroups($this->getAffectedChannelGroups());
$pnStatus->setAffectedUsers($this->getAffectedUsers());

return $pnStatus;
}
Expand All @@ -513,6 +534,11 @@ protected function getAffectedChannelGroups()
return null;
}

protected function getAffectedUsers()
{
return null;
}

/**
* @return \Requests_Transport
* @throws \Exception
Expand Down
Loading

0 comments on commit 4d0303d

Please sign in to comment.