コード例 #1
0
 /**
  * Deserialize a TokenRestrictionTemplate xml into a TokenRestrictionTemplate object.
  *
  * @param string $options Array containing values for object properties
  *
  * @return TokenRestrictionTemplate
  */
 public static function deserialize($template)
 {
     $xml = simplexml_load_string($template);
     $result = new TokenRestrictionTemplate();
     // Validation
     if ($xml->getName() !== 'TokenRestrictionTemplate') {
         throw new \RuntimeException("This is not a TokenRestrictionTemplate, it is a '{$xml->getName()}'");
     }
     if (!isset($xml->Issuer)) {
         throw new \RuntimeException("The TokenRestrictionTemplate must contains an 'Issuer' element");
     }
     if (!isset($xml->Audience)) {
         throw new \RuntimeException("The TokenRestrictionTemplate must contains an 'Audience' element");
     }
     if (!isset($xml->PrimaryVerificationKey) && !isset($xml->OpenIdConnectDiscoveryDocument)) {
         throw new \RuntimeException("Both PrimaryVerificationKey and OpenIdConnectDiscoveryDocument are undefined");
     }
     // decoding
     if (isset($xml->AlternateVerificationKeys)) {
         $result->setAlternateVerificationKeys(TokenRestrictionTemplateSerializer::deserializeAlternateVerificationKeys($xml->AlternateVerificationKeys));
     }
     $result->setAudience((string) $xml->Audience);
     $result->setIssuer((string) $xml->Issuer);
     if (isset($xml->PrimaryVerificationKey)) {
         $result->setPrimaryVerificationKey(TokenRestrictionTemplateSerializer::deserializeTokenVerificationKey($xml->PrimaryVerificationKey));
     }
     if (isset($xml->RequiredClaims)) {
         $result->setRequiredClaims(TokenRestrictionTemplateSerializer::deserializeRequiredClaims($xml->RequiredClaims));
     }
     if (isset($xml->TokenType)) {
         $result->setTokenType((string) $xml->TokenType);
     }
     if (isset($xml->OpenIdConnectDiscoveryDocument)) {
         $result->setOpenIdConnectDiscoveryDocument(TokenRestrictionTemplateSerializer::deserializeOpenIdConnectDiscoveryDocument($xml->OpenIdConnectDiscoveryDocument));
     }
     return $result;
 }
コード例 #2
0
 /**
  * @covers WindowsAzure\MediaServices\Templates\TokenRestrictionTemplate::getTokenType
  * @covers WindowsAzure\MediaServices\Templates\TokenRestrictionTemplate::setTokenType
  */
 public function testGetSetTokenType()
 {
     // Setup
     $entity = new TokenRestrictionTemplate();
     $payload = TokenType::JWT;
     // Test
     $entity->setTokenType($payload);
     $result = $entity->getTokenType();
     // Assert
     $this->assertEquals($payload, $result);
 }
 /**
  * @covers \WindowsAzure\MediaServices\Templates\TokenRestrictionTemplateSerializer::serialize
  */
 public function testSerializerSWT()
 {
     // Setup
     $fixture = '<TokenRestrictionTemplate xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/Azure/MediaServices/KeyDelivery/TokenRestrictionTemplate/v1"><Audience>http://sampleaudience/</Audience><Issuer>http://sampleissuerurl/</Issuer><PrimaryVerificationKey i:type="SymmetricVerificationKey"><KeyValue>dGVzdGtleXZhbHVlMQ==</KeyValue></PrimaryVerificationKey><TokenType>JWT</TokenType></TokenRestrictionTemplate>';
     $tokenRestriction = new TokenRestrictionTemplate();
     $tokenRestriction->setTokenType(TokenType::JWT);
     $tokenRestriction->setAudience('http://sampleaudience/');
     $tokenRestriction->setIssuer('http://sampleissuerurl/');
     $key = new SymmetricVerificationKey();
     $key->setKeyValue('testkeyvalue1');
     $tokenRestriction->setPrimaryVerificationKey($key);
     // Test
     $result = TokenRestrictionTemplateSerializer::serialize($tokenRestriction);
     // Assert
     $this->assertEquals($fixture, $result);
 }