2017-02-17 62 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 }) 
相關問題