示例#1
0
        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());
        }
示例#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);
        }
示例#3
0
        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());
        }