예제 #1
0
 function testGrants()
 {
     $scat = new Services_Twilio_AccessToken(self::ACCOUNT_SID, self::SIGNING_KEY_SID, 'secret');
     $scat->addGrant(new Services_Twilio_Auth_ConversationsGrant());
     $scat->addGrant(new Services_Twilio_Auth_IpMessagingGrant());
     $token = $scat->toJWT();
     $this->assertNotNull($token);
     $payload = JWT::decode($token, 'secret');
     $this->validateClaims($payload);
     $grants = json_decode(json_encode($payload->grants), true);
     $this->assertEquals(2, count($grants));
     $this->assertArrayHasKey("rtc", $grants);
     $this->assertArrayHasKey("ip_messaging", $grants);
 }
 function testGrants()
 {
     $scat = new Services_Twilio_AccessToken(self::ACCOUNT_SID, self::SIGNING_KEY_SID, 'secret');
     $scat->setIdentity('test identity');
     $scat->addGrant(new Services_Twilio_Auth_ConversationsGrant());
     $scat->addGrant(new Services_Twilio_Auth_IpMessagingGrant());
     $token = $scat->toJWT();
     $this->assertNotNull($token);
     $payload = JWT::decode($token, 'secret');
     $this->validateClaims($payload);
     $grants = json_decode(json_encode($payload->grants), true);
     $this->assertEquals(3, count($grants));
     $this->assertEquals('test identity', $payload->grants->identity);
     $this->assertEquals('{}', json_encode($payload->grants->rtc));
     $this->assertEquals('{}', json_encode($payload->grants->ip_messaging));
 }
예제 #3
0
 public function get(Request $request, Application $app)
 {
     /** @var MyBBUser $identity */
     $identity = $app['security']->getToken()->getUser();
     $deviceId = $request->get('fingerprint');
     $appName = $app['config']['app']['name'];
     $token = new \Services_Twilio_AccessToken($app['config']['twilio']['accountSid'], $app['config']['twilio']['apiKey'], $app['config']['twilio']['apiSecret'], self::$ttl, $identity->getUsername());
     $impGrant = new \Services_Twilio_Auth_IpMessagingGrant();
     $impGrant->setServiceSid($app['config']['twilio']['IPMServiceSid']);
     $impGrant->setEndpointId(sprintf('%s:%s:%s', $appName, $identity->getUsername(), $deviceId));
     $token->addGrant($impGrant);
     return new JsonResponse(['identity' => $identity->getUsername(), 'token' => $token->toJWT()]);
 }
<?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 Video
$grant = new Services_Twilio_Auth_VideoGrant();
$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()));
예제 #5
0
<?php

require_once './twilio-php/Services/Twilio.php';
require_once './randos.php';
require_once './config.php';
// An identifier for your app - can be anything you'd like
$appName = 'TwilioChatDemo';
// choose a random username for the connecting user
$identity = randomUsername();
// A device ID is passed as a query string parameter to this script
$deviceId = $_GET['device'];
// The endpoint ID is a combination of the above
$endpointId = $appName . ':' . $identity . ':' . $deviceId;
// 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);
// Create IP Messaging grant
$ipmGrant = new Services_Twilio_Auth_IpMessagingGrant();
$ipmGrant->setServiceSid($TWILIO_IPM_SERVICE_SID);
$ipmGrant->setEndpointId($endpointId);
// Add grant to token
$token->addGrant($ipmGrant);
// return serialized token and the user's randomly generated ID
echo json_encode(array('identity' => $identity, 'token' => $token->toJWT()));
예제 #6
0
 function testProgrammableVoiceGrant()
 {
     $scat = new Services_Twilio_AccessToken(self::ACCOUNT_SID, self::SIGNING_KEY_SID, 'secret');
     $scat->setIdentity('test identity');
     $pvg = new Services_Twilio_Auth_VoiceGrant();
     $pvg->setOutgoingApplication('AP123', array('foo' => 'bar'));
     $scat->addGrant($pvg);
     $token = $scat->toJWT();
     $this->assertNotNull($token);
     $payload = JWT::decode($token, 'secret');
     $this->validateClaims($payload);
     $grants = json_decode(json_encode($payload->grants), true);
     $this->assertEquals(2, count($grants));
     $this->assertEquals('test identity', $payload->grants->identity);
     $decodedGrant = $grants['voice'];
     $outgoing = $decodedGrant['outgoing'];
     $this->assertEquals('AP123', $outgoing['application_sid']);
     $params = $outgoing['params'];
     $this->assertEquals('bar', $params['foo']);
 }