function testConversationGrant() { $scat = new Services_Twilio_AccessToken(self::ACCOUNT_SID, self::SIGNING_KEY_SID, 'secret'); $grant = new Services_Twilio_Auth_ConversationsGrant(); $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("rtc", $grants); $this->assertEquals("CP123", $grants['rtc']['configuration_profile_sid']); }
<?php require_once './twilio-php/Services/Twilio.php'; require_once './randos.php'; require_once './config.php'; // choose a random username for the connecting user $identity = randomUsername(); // Create access token, which we will serialize and send to the client $token = new Services_Twilio_AccessToken($TWILIO_ACCOUNT_SID, $TWILIO_API_KEY, $TWILIO_API_SECRET, 3600, $identity); // Grant access to Twilio Video $grant = new Services_Twilio_Auth_ConversationsGrant(); $grant->setConfigurationProfileSid($TWILIO_CONFIGURATION_SID); $token->addGrant($grant); // return serialized token and the user's randomly generated ID echo json_encode(array('identity' => $identity, 'token' => $token->toJWT()));