diff options
-rw-r--r-- | Twilio/Jwt/Grants/VideoGrant.php | 54 | ||||
-rw-r--r-- | Twilio/Tests/Unit/Jwt/AccessTokenTest.php | 23 |
2 files changed, 76 insertions, 1 deletions
diff --git a/Twilio/Jwt/Grants/VideoGrant.php b/Twilio/Jwt/Grants/VideoGrant.php new file mode 100644 index 0000000..6a7d176 --- /dev/null +++ b/Twilio/Jwt/Grants/VideoGrant.php @@ -0,0 +1,54 @@ +<?php + + +namespace Twilio\Jwt\Grants; + + +class VideoGrant implements Grant { + + private $configurationProfileSid; + + /** + * Returns the configuration profile sid + * + * @return string the configuration profile sid + */ + public function getConfigurationProfileSid() { + return $this->configurationProfileSid; + } + + /** + * Set the configuration profile sid of the grant + * + * @param string $configurationProfileSid configuration profile sid of grant + * + * @return $this updated grant + */ + public function setConfigurationProfileSid($configurationProfileSid) { + $this->configurationProfileSid = $configurationProfileSid; + return $this; + } + + /** + * Returns the grant type + * + * @return string type of the grant + */ + public function getGrantKey() { + return "video"; + } + + /** + * Returns the grant data + * + * @return array data of the grant + */ + public function getPayload() { + $payload = array(); + if ($this->configurationProfileSid) { + $payload['configuration_profile_sid'] = $this->configurationProfileSid; + } + return $payload; + } + +}
\ No newline at end of file diff --git a/Twilio/Tests/Unit/Jwt/AccessTokenTest.php b/Twilio/Tests/Unit/Jwt/AccessTokenTest.php index 53554ff..205c3ca 100644 --- a/Twilio/Tests/Unit/Jwt/AccessTokenTest.php +++ b/Twilio/Tests/Unit/Jwt/AccessTokenTest.php @@ -4,6 +4,7 @@ namespace Twilio\Tests\Unit\Jwt; use Twilio\Jwt\Grants\ConversationsGrant; use Twilio\Jwt\Grants\IpMessagingGrant; +use Twilio\Jwt\Grants\VideoGrant; use Twilio\Jwt\Grants\VoiceGrant; use Twilio\Jwt\Grants\SyncGrant; use Twilio\Jwt\JWT; @@ -111,11 +112,30 @@ class AccessTokenTest extends UnitTest { $this->assertEquals("IS123", $grants['data_sync']['service_sid']); } + function testVideoGrant() + { + $scat = new AccessToken(self::ACCOUNT_SID, self::SIGNING_KEY_SID, 'secret'); + $grant = new VideoGrant(); + $grant->setConfigurationProfileSid("CP123"); + $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("video", $grants); + $this->assertEquals("CP123", $grants['video']['configuration_profile_sid']); + } + function testGrants() { $scat = new AccessToken(self::ACCOUNT_SID, self::SIGNING_KEY_SID, 'secret'); $scat->setIdentity('test identity'); $scat->addGrant(new ConversationsGrant()); $scat->addGrant(new IpMessagingGrant()); + $scat->addGrant(new VideoGrant()); $token = $scat->toJWT(); @@ -124,10 +144,11 @@ class AccessTokenTest extends UnitTest { $this->validateClaims($payload); $grants = json_decode(json_encode($payload->grants), true); - $this->assertEquals(3, count($grants)); + $this->assertEquals(4, count($grants)); $this->assertEquals('test identity', $payload->grants->identity); $this->assertEquals('{}', json_encode($payload->grants->rtc)); $this->assertEquals('{}', json_encode($payload->grants->ip_messaging)); + $this->assertEquals('{}', json_encode($payload->grants->video)); } function testVoiceGrant() { |