Beispiel #1
0
        public static TestClaimsProvider WithLibrarianClaims()
        {
            var provider = new TestClaimsProvider();

            provider.Claims.Add(new Claim(ClaimTypes.Name, "1"));
            provider.Claims.Add(new Claim(ClaimTypes.Role, "Librarian"));

            return(provider);
        }
Beispiel #2
0
        public static TestClaimsProvider WithReaderClaims()
        {
            var provider = new TestClaimsProvider();

            provider.Claims.Add(new Claim(ClaimTypes.Name, "2"));
            provider.Claims.Add(new Claim(ClaimTypes.Role, "Reader"));

            return(provider);
        }
Beispiel #3
0
        public static HttpClient CreateClientWithTestAuth <T>(this WebApplicationFactory <T> factory, TestClaimsProvider claimsProvider) where T : class
        {
            var client = factory.WithAuthentication(claimsProvider).CreateClient(new WebApplicationFactoryClientOptions());

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Test");

            return(client);
        }
Beispiel #4
0
        public static WebApplicationFactory <T> WithAuthentication <T>(this WebApplicationFactory <T> factory, TestClaimsProvider claimsProvider) where T : class
        {
            return(factory.WithWebHostBuilder(builder =>
            {
                builder.ConfigureTestServices(services =>
                {
                    services.AddAuthentication("Test")
                    .AddScheme <AuthenticationSchemeOptions, TestAuthHandler>("Test", op => { });

                    services.AddScoped(_ => claimsProvider);
                });
            }));
        }
Beispiel #5
0
 public TestAuthHandler(IOptionsMonitor <AuthenticationSchemeOptions> options, ILoggerFactory logger,
                        UrlEncoder encoder, ISystemClock clock, TestClaimsProvider claimsProvider) : base(options, logger, encoder, clock)
 {
     _claims = claimsProvider.Claims;
 }