public AnonymousUserTests()
        {
            var startup = new TestServerStartup(o =>
            {
                o.AnonymousRoutes = new List <string> {
                    "/anonymous/route"
                };
                o.AuthenticationScheme = "test_scheme";
                o.ScopeClaimType       = "scope";
                o.ScopeSchemes         = new List <ScopeScheme>
                {
                    new ScopeScheme
                    {
                        PathTemplate  = "/restricted/route",
                        AllowedScopes = new List <Scope>
                        {
                            new Scope
                            {
                                RequestMethod = HttpMethod.Get,
                                AllowedScopes = new List <string> {
                                    "valid.scope"
                                }
                            }
                        }
                    }
                };
            }, null);


            var server = new TestServer(new WebHostBuilder()
                                        .ConfigureServices(startup.ConfigureServices)
                                        .Configure(startup.Configure));

            _client = server.CreateClient();
        }
Beispiel #2
0
        public AuthenticatedUserTests()
        {
            var identity = new ClaimsIdentity(new List <Claim>
            {
                new Claim(ScopeClaimType, "valid_post_scope"),
                new Claim(ScopeClaimType, "invalid_get_scope")
            });


            var startup = new TestServerStartup(o =>
            {
                o.AnonymousRoutes = new List <string> {
                    "/anonymous/route"
                };
                o.AuthenticationScheme = "test_scheme";
                o.ScopeClaimType       = "scope";
                o.ScopeSchemes         = new List <ScopeScheme>
                {
                    new ScopeScheme
                    {
                        PathTemplate  = "/restricted/route",
                        AllowedScopes = new List <Scope>
                        {
                            new Scope
                            {
                                RequestMethod = HttpMethod.Post,
                                AllowedScopes = new List <string> {
                                    "valid_post_scope"
                                }
                            },
                            new Scope
                            {
                                RequestMethod = HttpMethod.Get,
                                AllowedScopes = new List <string> {
                                    "valid_get_scope"
                                }
                            }
                        }
                    }
                };
            }, new ClaimsPrincipal(identity));


            var server = new TestServer(new WebHostBuilder()
                                        .ConfigureServices(startup.ConfigureServices)
                                        .Configure(startup.Configure));

            _client = server.CreateClient();
        }