Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication scheme #6

Open
grosch opened this issue Jan 8, 2021 · 0 comments
Open

Authentication scheme #6

grosch opened this issue Jan 8, 2021 · 0 comments

Comments

@grosch
Copy link

grosch commented Jan 8, 2021

Trying to get started with your library and I hit the below issue.

System.InvalidOperationException: No authenticationScheme was specified, and there was no DefaultChallengeScheme found. The default schemes can be set using either AddAuthentication(string defaultScheme) or AddAuthentication(Action configureOptions).
at Microsoft.AspNetCore.Authentication.AuthenticationService.ChallengeAsync(HttpContext context, String scheme, AuthenticationProperties properties)
at Microsoft.AspNetCore.Authorization.Policy.AuthorizationMiddlewareResultHandler.HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

I've got this as my test

[UserFact("MySecretId")]
public async Task GetLabManagerEmailsAsync_SendsPlainText()
{
    var request = "/api/report/emails";

    var response = await Client.GetAsync(request);

    response.EnsureSuccessStatusCode();
    Assert.Equal("text/foo", response.Content.Headers.ContentType.MediaType);
}

and the Client is setup like so:

protected TestFixture(string relativeTargetProjectParentDir)
{
    var startupAssembly = typeof(TStartup).GetTypeInfo().Assembly;
    var contentRoot = GetProjectPath(relativeTargetProjectParentDir, startupAssembly);

    var configurationBuilder = new ConfigurationBuilder()
        .SetBasePath(contentRoot)
        .AddJsonFile("appsettings.json");

    var webHostBuilder = new WebHostBuilder()
        .UseContentRoot(contentRoot)
        .ConfigureServices(InitializeServices)
        .UseConfiguration(configurationBuilder.Build())
        .UseEnvironment("Development")
        .UseStartup(typeof(TStartup));

    // Create instance of test server
    Server = new TestServer(webHostBuilder);

    // Add configuration for client
    Client = Server.CreateClient();
    Client.DefaultRequestHeaders.Accept.Clear();
    Client.DefaultRequestHeaders.Accept.Add(new("application/json"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant