コード例 #1
0
        public static TestClaimsProvider WithUserClaims()
        {
            var provider = new TestClaimsProvider();
            provider.Claims.Add(new Claim(ClaimTypes.NameIdentifier, Guid.NewGuid().ToString()));
            provider.Claims.Add(new Claim(ClaimTypes.Name, "7"));

            return provider;
        }
コード例 #2
0
        public static HttpClient CreateClientWithTestAuth <T>(this WebApplicationFactory <T> factory, TestClaimsProvider claimsProvider) where T : class
        {
            var client = factory.WithAuthentication(claimsProvider).CreateClient(new WebApplicationFactoryClientOptions
            {
                AllowAutoRedirect = false
            });

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

            return(client);
        }
コード例 #3
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 <TestClaimsProvider>(_ => claimsProvider);
                });
            }));
        }
コード例 #4
0
 public TestAuthHandler(IOptionsMonitor <AuthenticationSchemeOptions> options, ILoggerFactory logger,
                        UrlEncoder encoder, ISystemClock clock, TestClaimsProvider claimsProvider) : base(options, logger, encoder, clock)
 {
     _claims = claimsProvider.Claims;
 }