Dmitri
Dmitri

Reputation: 776

Does .NET CORE 3.0 with windows authentication in docker on linux work?

I am trying to enable windows authentication using .NET CORE 3.0 application solution in Visual Studio 2019 in docker linux container using mcr.microsoft.com/dotnet/core/aspnet:3.0 image. I can do this setup in IIS windows container without a problem using gMSA account but when it comes to linux container and aspnet:3.0 I am unable to get a prompt for credentials if I use [Authorize] attribute and User.Identity.Name is not populating. I am getting mixed signals from the internet if this is even possible and so far unable to find a concise answer. Just trying different things with registering services JWT/IISDefaults/HttpSysDefaults/Oauth, app.UseAuthentication, Modifying launch settings and app settings.json with no luck. Any help would be appreciated.

Upvotes: 2

Views: 1816

Answers (1)

Nebeski
Nebeski

Reputation: 610

I had this problem in a project, and I managed to get the prompt for credentials in ASP.NET like this: Above the controller you need to authorize access to, put Authorize attribute like this:

[Authorize(Policy = "SomeExampleGroup")]
[Route("/some-example")]
public class SomeExampleController : Controller {...}

In the ConfigureServices method in Startup.cs:

services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate();
services.AddAuthentication(o => o.DefaultAuthenticateScheme = NegotiateDefaults.AuthenticationScheme);

services.AddAuthorization(options =>
{
    options.AddPolicy("SomeExampleGroup",
                        policy => policy.RequireAssertion(/*some assertion here for example*/));
});

And in the Configure method make sure to put

app.UseRouting();
app.UseAuthorization();
app.UseAuthentication();

in this order. Anyway, I managed to get the credentials prompt on Docker in a linux container like this, but the credentials still won't work, so I hope this helps.

Upvotes: 2

Related Questions