summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormatt <matt@twilio.com>2016-08-29 14:10:04 -0700
committermatt <matt@twilio.com>2016-08-29 14:10:04 -0700
commitb585f28cf7d3f8d26d4699f373ac960d749da9bc (patch)
treeca48cf95205768ada1c03f195f4789d3a91f3a9b
parent2e4edf57f95c18cc0b4dc1b81c2082afac39d54e (diff)
parente48aeac07471ed0f4c769bd46e7ea5a0a666bb6d (diff)
downloadtwilio-php-b585f28cf7d3f8d26d4699f373ac960d749da9bc.zip
twilio-php-b585f28cf7d3f8d26d4699f373ac960d749da9bc.tar.gz
twilio-php-b585f28cf7d3f8d26d4699f373ac960d749da9bc.tar.bz2
Merge branch 'ajtack-next-gen'
# Conflicts: # Twilio/Tests/Unit/Jwt/AccessTokenTest.php
-rw-r--r--Twilio/Jwt/Grants/SyncGrant.php138
-rw-r--r--Twilio/Tests/Unit/Jwt/AccessTokenTest.php21
2 files changed, 159 insertions, 0 deletions
diff --git a/Twilio/Jwt/Grants/SyncGrant.php b/Twilio/Jwt/Grants/SyncGrant.php
new file mode 100644
index 0000000..0d5fafe
--- /dev/null
+++ b/Twilio/Jwt/Grants/SyncGrant.php
@@ -0,0 +1,138 @@
+<?php
+
+namespace Twilio\Jwt\Grants;
+
+class SyncGrant implements Grant
+{
+ private $serviceSid;
+ private $endpointId;
+ private $deploymentRoleSid;
+ private $pushCredentialSid;
+
+ /**
+ * Returns the service sid
+ *
+ * @return string the service sid
+ */
+ public function getServiceSid()
+ {
+ return $this->serviceSid;
+ }
+
+ /**
+ * Set the service sid of this grant
+ *
+ * @param string $serviceSid service sid of the grant
+ *
+ * @return Services_Twilio_Auth_SyncGrant updated grant
+ */
+ public function setServiceSid($serviceSid)
+ {
+ $this->serviceSid = $serviceSid;
+ return $this;
+ }
+
+ /**
+ * Returns the endpoint id of the grant
+ *
+ * @return string the endpoint id
+ */
+ public function getEndpointId()
+ {
+ return $this->endpointId;
+ }
+
+ /**
+ * Set the endpoint id of the grant
+ *
+ * @param string $endpointId endpoint id of the grant
+ *
+ * @return Services_Twilio_Auth_SyncGrant updated grant
+ */
+ public function setEndpointId($endpointId)
+ {
+ $this->endpointId = $endpointId;
+ return $this;
+ }
+
+ /**
+ * Returns the deployment role sid of the grant
+ *
+ * @return string the deployment role sid
+ */
+ public function getDeploymentRoleSid()
+ {
+ return $this->deploymentRoleSid;
+ }
+
+ /**
+ * Set the role sid of the grant
+ *
+ * @param string $deploymentRoleSid role sid of the grant
+ *
+ * @return Services_Twilio_Auth_SyncGrant updated grant
+ */
+ public function setDeploymentRoleSid($deploymentRoleSid)
+ {
+ $this->deploymentRoleSid = $deploymentRoleSid;
+ return $this;
+ }
+
+ /**
+ * Returns the push credential sid of the grant
+ *
+ * @return string the push credential sid
+ */
+ public function getPushCredentialSid()
+ {
+ return $this->pushCredentialSid;
+ }
+
+ /**
+ * Set the credential sid of the grant
+ *
+ * @param string $pushCredentialSid push credential sid of the grant
+ *
+ * @return Services_Twilio_Auth_SyncGrant updated grant
+ */
+ public function setPushCredentialSid($pushCredentialSid)
+ {
+ $this->pushCredentialSid = $pushCredentialSid;
+ return $this;
+ }
+
+ /**
+ * Returns the grant type
+ *
+ * @return string type of the grant
+ */
+ public function getGrantKey()
+ {
+ return "data_sync";
+ }
+
+ /**
+ * Returns the grant data
+ *
+ * @return array data of the grant
+ */
+ public function getPayload()
+ {
+ $payload = array();
+ if ($this->serviceSid) {
+ $payload['service_sid'] = $this->serviceSid;
+ }
+ if ($this->endpointId) {
+ $payload['endpoint_id'] = $this->endpointId;
+ }
+ if ($this->deploymentRoleSid) {
+ $payload['deployment_role_sid'] = $this->deploymentRoleSid;
+ }
+ if ($this->pushCredentialSid) {
+ $payload['push_credential_sid'] = $this->pushCredentialSid;
+ }
+
+ return $payload;
+ }
+
+}
diff --git a/Twilio/Tests/Unit/Jwt/AccessTokenTest.php b/Twilio/Tests/Unit/Jwt/AccessTokenTest.php
index b6d84b8..53554ff 100644
--- a/Twilio/Tests/Unit/Jwt/AccessTokenTest.php
+++ b/Twilio/Tests/Unit/Jwt/AccessTokenTest.php
@@ -5,6 +5,7 @@ namespace Twilio\Tests\Unit\Jwt;
use Twilio\Jwt\Grants\ConversationsGrant;
use Twilio\Jwt\Grants\IpMessagingGrant;
use Twilio\Jwt\Grants\VoiceGrant;
+use Twilio\Jwt\Grants\SyncGrant;
use Twilio\Jwt\JWT;
use Twilio\Tests\Unit\UnitTest;
use Twilio\Jwt\AccessToken;
@@ -90,6 +91,26 @@ class AccessTokenTest extends UnitTest {
$this->assertEquals("IS123", $grants['ip_messaging']['service_sid']);
}
+ function testSyncGrant()
+ {
+ $scat = new AccessToken(self::ACCOUNT_SID, self::SIGNING_KEY_SID, 'secret');
+ $grant = new SyncGrant();
+ $grant->setEndpointId("EP123");
+ $grant->setServiceSid("IS123");
+ $scat->addGrant($grant);
+
+ $token = $scat->toJWT();
+ $this->assertNotNull($token);
+ $payload = JWT::decode($token, 'secret');
+ $this->validateClaims($payload);
+
+ $grants = json_decode(json_encode($payload->grants), true);
+ $this->assertEquals(1, count($grants));
+ $this->assertArrayHasKey("data_sync", $grants);
+ $this->assertEquals("EP123", $grants['data_sync']['endpoint_id']);
+ $this->assertEquals("IS123", $grants['data_sync']['service_sid']);
+ }
+
function testGrants() {
$scat = new AccessToken(self::ACCOUNT_SID, self::SIGNING_KEY_SID, 'secret');
$scat->setIdentity('test identity');