Example #1
0
        public void Decode_IJwsAlgorithm_Override()
        {
            //given
            MockJwsAlgorithm jwsAlg = new MockJwsAlgorithm();

            string token = "eyJhbGciOiJub25lIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.";

            //when
            var test = Jose.JWT.Decode <IDictionary <string, object> >(token, settings: new JwtSettings().RegisterJws(JwsAlgorithm.none, jwsAlg));

            //then
            Assert.Equal(test, new Dictionary <string, object> {
                { "hello", "world" }
            });
            Assert.True(jwsAlg.VerifyCalled);
        }
Example #2
0
        public void Encode_IJwsAlgorithm_Override()
        {
            //given
            MockJwsAlgorithm jwsAlg = new MockJwsAlgorithm();

            var payload = new
            {
                hello = "world"
            };

            //when
            string token = Jose.JWT.Encode(payload, null,
                                           JwsAlgorithm.none, settings: new JwtSettings().RegisterJws(JwsAlgorithm.none, jwsAlg));

            Console.Out.WriteLine("Plaintext:" + token);

            //then
            Assert.Equal(token, "eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJoZWxsbyI6IndvcmxkIn0.");
            Assert.True(jwsAlg.SignCalled);
        }