简体   繁体   English

如何将Windows Identity从Angle App传递到Linux服务器上托管的ASP.NET Core 2.0 WebAPI

[英]How to pass windows Identity from angular app to asp.net core 2.0 webapi hosted on Linux server

I have an asp.net core web api running on Linux server (using PCF cloud). 我有一个运行在Linux服务器上(使用PCF云)的asp.net核心Web API。 I want to pass user credential from angular app to this web api. 我想将用户凭据从angular应用程序传递到此网络api。 I tried with angular option withCredentials = true but it is not passing user windows login id. 我尝试使用角度选项withCredentials = true,但未传递用户Windows登录ID。

on Asp.net Core web api, I tried multiple options like 在Asp.net Core Web API上,我尝试了多个选项,例如

Context.User.Identity.Name
Environment.Username
_httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value

but nothing seems to be working. 但似乎没有任何效果。 I tried finding it out on google but no luck. 我尝试在Google上找到它,但是没有运气。 followed this url to setup but it is also not working... 按照此URL进行设置,但也无法正常工作...

https://www.koskila.net/how-to-get-current-user-in-asp-net-core/

If I run services locally on windows machine then everything works fine and I can get userid in my web api. 如果我在Windows计算机上本地运行服务,则一切正常,我可以在Web API中获取用户ID。 I also tried hosting this asp.net core web api on Windows server IIS and it is also working fine. 我还尝试在Windows服务器IIS上托管此asp.net核心Web api,它也可以正常工作。

The only issue comes when I host my service on PCF Linux box. 当我在PCF Linux机器上托管我的服务时,唯一的问题就来了。 I can understand Linux will not support the concept of Windows identity but is there any way I can pass just username with domain to asp.net core on Linux, I don't need full windows identity, just username will do. 我可以理解Linux将不支持Windows身份的概念,但是有什么方法可以将仅带有域的用户名传递给Linux上的asp.net核心,我不需要完整的Windows身份,只需用户名即可。

Yes, and no at the same time. 是的,同时没有。 To support Windows authentication you need to be in the same domain and your OS can be able to pass creds to the web server (it should support this auth type). 要支持Windows身份验证,您需要位于同一域中,并且您的操作系统可以将凭据传递到Web服务器(它应支持此身份验证类型)。

There is nothing related to the UI. 没有与UI相关的内容。 If you will try it locally you will find a lot of requests behind the scene that a really authenticate you. 如果您将在本地尝试,那么您会在幕后发现许多真正使您身份验证的请求。

I know that most of the popular web servers can do this with a lot of configuration, like keys import and you can't do this without changes in AD. 我知道大多数流行的Web服务器都可以通过许多配置来做到这一点,例如密钥导入,而如果没有AD的更改就无法做到这一点。

I think you need something like this https://www.axians-infoma.de/techblog/windows-authentication-in-docker-containers-just-got-a-lot-easier/ 我认为您需要类似以下内容的东西:https://www.axians-infoma.de/techblog/windows-authentication-in-docker-containers-just-got-a-lot-easier/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM