Exemplo n.º 1
0
        public void Initialize()
        {
            string secretKey = "dotnetifydemo_secretkey_123!";
            var    tokenValidationParameters = new TokenValidationParameters
            {
                IssuerSigningKey         = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(secretKey)),
                ValidAudience            = "DotNetifyDemoApp",
                ValidIssuer              = "DotNetifyDemoServer",
                ValidateIssuerSigningKey = true,
                ValidateAudience         = true,
                ValidateIssuer           = true,
                ValidateLifetime         = true,
                ClockSkew = TimeSpan.FromSeconds(0)
            };

            var types = new Dictionary <Type, object>
            {
                { typeof(FilterTestVM), (_vm = new FilterTestVM()) },
                { typeof(CustomFilter1), (_filter1 = new CustomFilter1()) },
                { typeof(CustomFilter2), (_filter2 = new CustomFilter2()) },
                { typeof(ExtractHeadersMiddleware), new ExtractHeadersMiddleware(_headersCache) },
                { typeof(JwtBearerAuthenticationMiddleware), new JwtBearerAuthenticationMiddleware(tokenValidationParameters) },
                { typeof(AuthorizeFilter), new AuthorizeFilter() }
            };

            VMController.CreateInstance = (type, args) => types.ContainsKey(type) ? types[type] : Activator.CreateInstance(type, args);

            _vmArg = JObject.Parse(@"{
            Property: 'World',
            $headers: {
               Authorization: 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImp0aSI6IjI0YTUwOGJlLWJlMTktNDFhZS1iZmI1LTc5OGU4YmNjNDI3ZCIsImlhdCI6MTUxNDUyODgxNiwiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNS8wNS9pZGVudGl0eS9jbGFpbXMvbmFtZSI6WyJhZG1pbiIsImFkbWluIl0sImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6ImFkbWluIiwibmJmIjoxNTE0NTI4ODE2LCJleHAiOjE4Mjk4ODg4MTYsImlzcyI6IkRvdE5ldGlmeURlbW9TZXJ2ZXIiLCJhdWQiOiJEb3ROZXRpZnlEZW1vQXBwIn0.q2wZyS13FskQ094O9xbz4FLlRPPHf1GfKOUOTHJyLbk'
            }
         }");
        }
Exemplo n.º 2
0
 public void Cleanup()
 {
     CustomFilter1.Cleanup();
     CustomFilter2.Cleanup();
 }