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()]); }
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)); }
<?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()));
<?php require_once './twilio-php/Services/Twilio.php'; // Required for all Twilio access tokens $twilioAccountSid = 'ACxxxxxxxxxxxx'; $twilioApiKey = 'SKxxxxxxxxxxxx'; $twilioApiSecret = 'xxxxxxxxxxxxxx'; // Required for IP messaging grant $ipmServiceSid = 'ISxxxxxxxxxxxx'; $appName = 'HipFlowSlackDockRC'; $identity = '*****@*****.**'; $deviceId = 'someiosdevice'; $endpointId = $appName . ':' . $identity . ':' . $deviceId; // Create access token $token = new Services_Twilio_AccessToken($twilioAccountSid, $twilioApiKey, $twilioApiSecret, 3600, $identity); // Create IP Messaging grant $ipmGrant = new Services_Twilio_Auth_IpMessagingGrant(); $ipmGrant->setServiceSid($ipmServiceSid); $ipmGrant->setEndpointId($endpointId); // Add grant to token $token->addGrant($ipmGrant); // render token to string echo $token->toJWT();
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']); }