public function testKnownGoodGenerateTestTokenJWT() { // Arrange $expectedToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1cm46bWljcm9zb2Z0OmF6dXJlOm1lZGlhc2VydmljZXM6Y29udGVudGtleWlkZW50aWZpZXIiOiIwOTE0NDM1ZC0xNTAwLTgwYzQtNmMyYi1mMWU1MmZkYTQ3YWUiLCJpc3MiOiJodHRwczpcL1wvdHN0LmNvbnRvc28uY29tIiwiYXVkIjoidXJuOmNvbnRvc28iLCJleHAiOjE0NTE2MDY0MDAsIm5iZiI6MTQ1MTYwNjQwMH0.voBCckYtSgVq6Z1Y8gwOBJO8DfH4-dX9ACmvSSHADso'; $knownSymetricKey = '64bytes6RNhi8EsxcYsdYQ9zpFuNR1Ks9milykbxYWGILaK0LKzd5dCtYonsr456'; $knownGuid = '0914435d-1500-80c4-6c2b-f1e52fda47ae'; $knownExpireOn = 1451606400; // 2016-01-01 as Unix Epoch; $knownNotBefore = 1451606400; // 2016-01-01 as Unix Epoch; $knownAudience = 'urn:contoso'; $knownIssuer = 'https://tst.contoso.com'; $template = new TokenRestrictionTemplate(TokenType::JWT); $key = new SymmetricVerificationKey(); $key->setKeyValue($knownSymetricKey); $template->setPrimaryVerificationKey($key); $template->setAudience($knownAudience); $template->setIssuer($knownIssuer); $template->setRequiredClaims(array(new TokenClaim(TokenClaim::CONTENT_KEY_ID_CLAIM_TYPE))); // Act $resultsToken = TokenRestrictionTemplateSerializer::generateTestToken($template, $key, $knownGuid, $knownExpireOn, $knownNotBefore); // Assert $this->assertEquals($expectedToken, $resultsToken); }
function generateTestToken($tokenTemplateString, $contentKey) { $template = TokenRestrictionTemplateSerializer::deserialize($tokenTemplateString); $contentKeyUUID = substr($contentKey->getId(), strlen("nb:kid:UUID:")); $expiration = strtotime("+12 hour"); $token = TokenRestrictionTemplateSerializer::generateTestToken($template, null, $contentKeyUUID, $expiration); echo "Token Type {$template->getTokenType()}\r\nBearer={$token}" . PHP_EOL; }
function generateTestToken($tokenTemplateString, $contentKey) { $template = TokenRestrictionTemplateSerializer::deserialize($tokenTemplateString); $contentKeyUUID = substr($contentKey->getId(), strlen('nb:kid:UUID:')); $expiration = strtotime('+12 hour'); $token = TokenRestrictionTemplateSerializer::generateTestToken($template, null, $contentKeyUUID, $expiration); return $token; }