2017-02-17 63 views
0

我有一个使用Windows身份验证的OWIN/Katana WebAPI。当我在本地运行它时,它可以接收我的Windows凭据。但是,当我将WebAPI部署到服务器/集群时,它会一直提示我输入登录名和密码。使用Windows身份验证的OWIN/Katana WebAPI不断要求输入登录名/密码

我现在有在Startup.cs如下:

//Set up integrated windows authentication. 
    HttpListener listener = (HttpListener)appBuilder.Properties["System.Net.HttpListener"]; 
    listener.AuthenticationSchemes = AuthenticationSchemes.IntegratedWindowsAuthentication; 

我甚至试过这个问题,以及:

HttpListener listener = (HttpListener)appBuilder.Properties["System.Net.HttpListener"]; 
    listener.AuthenticationSchemes = AuthenticationSchemes.Negotiate; 

在提琴手,我可以打我的API(在服务器上)通过启用身份验证。但是如果我从另一个应用程序中使用API​​,它会自动返回401 Unauthorized。为什么即使在我专门使用Windows身份验证时,它仍然会提示手动登录?

我一直在以下这些文章:

http://www.sbrickey.com/Tech/Blog/Post/AllowAnonymous_for_OWIN_Katana_self_hosted_WebAPIs_using_Kerberos

https://blogs.msdn.microsoft.com/chiranth/2013/09/20/ntlm-want-to-know-how-it-works/

https://docs.microsoft.com/en-us/aspnet/aspnet/overview/owin-and-katana/enabling-windows-authentication-in-katana

+0

如果您的呼叫者不通过用户凭证,则提示正常。你必须编写适当的客户端代码。 –

+0

感谢您的回复@LexLi - 为什么这是正常的行为?不应该自动传递客户端计算机的Windows登录凭据吗?为什么当我在调试时本地运行API时,它没有提示我?对不起,这些愚蠢的问题 - 我还不熟悉auths。 – Jacky

+0

用户凭据不会自动传递,尤其是当您通过代码调用时。即使IE会提示你,除非你正确配置它。你学习太多了。 –

回答

0

我发现为什么我的Web客户端失败(感谢@LexLi)。我认为这个问题是在我的API中,但事实证明,我甚至没有从客户端发送我的用户凭证。我将用户凭证添加到HttpHandler中以供我的HttpClient使用。

new HttpClient(new HttpClientHandler() { UseDefaultCredentials = true }) 
相关问题