Users must login to their windows machines where after they can access the web app through a url.
I am trying to retrieve the windows username of the users who launch the app (on the client).
I am trying to avoid carrying out any login where the users have to enter their username and passwords.
The app is running in a corporate network which is controlled by AD groups.
Ultimately I would like to verify the users against an AD group (AD and Azure Ad are both available) then check whether they exist within a users table in sql server.
To do this I need to know the windows-username.
The app is built using ASP.NET Core 3.1 and is an MVC app using Kestrel, running on linux container which is hosted on RHEL 7.
Currently RHEL does not have windows authentication enabled.
I have used the base image mcr.microsoft.com/dotnet/aspnet:3.1 (debian 10) to build my app.
- When I try to use Environment.UserName this works on visual studio but when deploying the container I get the user on the container : root
- When i try to use the httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value I get in Visual Studio System.NullReferenceException: 'Object reference not set to an instance of an object.'
- When i use System.Security.Principal.WindowsIdentity.GetCurrent().Name, i get domain\windows-username on visual studio (this is perfect) but once i deploy the app linux container i get the following error:
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "some id", Request id "some id": An unhandled exception was thrown by the application.
System.PlatformNotSupportedException: Windows Principal functionality is not supported on this platform.
at System.Security.Principal.WindowsIdentity.GetCurrent()
I read the docs
https://learn.microsoft.com/en-us/aspnet/core/security/authentication/windowsauth?view=aspnetcore-3.1&tabs=visual-studio
and installed nugets for Microsoft.AspNetCore.Authentication.Negotiate and Microsoft.AspNetCore.Connections.Abstractions and added following to the startup file:
services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate();
app.UseAuthentication();
This did not help.
I understood from the docs that i need to use windows authentication to get the windows username, however I can not find any where in the docs how to that that on a linux container that is running on RHEL?
I would appreciate help on this.