public void Verify_None_Algorithm_Serialization()
        {
            var token = new JsonWebToken { Issuer = "joe", ExpirationTime = 1300819380 };
            token.AddClaim("http://example.com/is_root", true);

            var serializer = new JWSCompactSerializer();
            var strToken = serializer.Serialize(token.ToJson());
            var deserializedToken = serializer.Deserialize(strToken);
            
            Assert.AreEqual(token.ToJson(), deserializedToken.ToJson());
        }
Beispiel #2
0
        public void Should_Token_Not_Yet_Valid()
        {
            var token = new JsonWebToken { Issuer = "joe", NotBefore = DateTimeOffset.UtcNow.AddMinutes(5).ToUnixTimeSeconds() };
            token.AddClaim("http://example.com/is_root", true);

            Assert.IsFalse(token.IsValid);

            var serializer = new JWSCompactSerializer(new HS256Algorithm("1To680X8yGFe8wEFu5Ye8bW735CF9j6D"));
            var deserializedToken = serializer.Deserialize(serializer.Serialize(token.ToJson()));

            Assert.IsFalse(deserializedToken.IsValid);
        }
        public async Task Verify_HS256_Algorithm_Serialization()
        {
            var keySet = await JWKSet.GetAsync(this.keySetUri);
            var key = keySet["hs-256"];

            var token = new JsonWebToken { Issuer = "joe", ExpirationTime = 1300819380 };
            token.AddClaim("http://example.com/is_root", true);

            var serializer = new JWSCompactSerializer(new HS256Algorithm(key));
            var strToken = serializer.Serialize(token.ToJson());
            var deserializedToken = serializer.Deserialize(strToken);

            Assert.AreEqual(token.ToJson(), deserializedToken.ToJson());
        }
        public async Task Verify_RS512_Algorithm_Serialization()
        {
            var keySet = await JWKSet.GetAsync(this.keySetUri);
            var key = keySet["rsa-512"];

            var token = new JsonWebToken { Issuer = "joe", ExpirationTime = 1300819380 };
            token.AddClaim("http://example.com/is_root", true);
            var header = new JoseHeader() { JwkSetUrl = this.keySetUri, KeyId = "rsa-512" };

            var serializer = new JWSCompactSerializer(new RS512Algorithm(privateKey: key));
            var strToken = serializer.Serialize(token.ToJson(), header);
            var deserializedToken = await serializer.DeserializeAsync(strToken);

            Assert.AreEqual(token.ToJson(), deserializedToken.ToJson());
        }