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));
 }
Пример #2
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']);
 }