使用Windows身份验证的Simple.Odata客户端

时间:2017-07-10 09:37:30

标签: c# asp.net-web-api odata windows-authentication simple.odata.client

可以使用Simple Odata Client来使用Windows authentifaction请求我的Odata服务(由Asp.Net MVC托管)吗?

简单的Odata客户端需要凭证:

public ODataClient(ODataClientSettings settings);
public ODataClientSettings(Uri baseUri, ICredentials credentials = null);

我发现的唯一例子是基于newtworkCredentials: https://github.com/object/Simple.OData.Client/blob/master/Simple.OData.Client.IntegrationTests/WebApiTests.cs

public class WebApiWithAuthenticationTests : WebApiTestsBase
{
    private const string _user = "tester";
    private const string _password = "tester123";

    public WebApiWithAuthenticationTests()
        : base(new ODataClientSettings()
        {
            BaseUri = new Uri("http://va-odata-integration.azurewebsites.net/odata/secure"), 
            Credentials = new NetworkCredential(_user, _password)
        })
    {
    }
}

1 个答案:

答案 0 :(得分:0)

尝试使用此类CredentialCache.DefaultCredentials属性。

public class WebApiWithAuthenticationTests : WebApiTestsBase
{    
    public WebApiWithAuthenticationTests()
        : base(new ODataClientSettings()
        {
            BaseUri = new Uri("http://va-odata-integration.azurewebsites.net/odata/secure"), 
            Credentials = CredentialCache.DefaultCredentials
        })
    {
    }
}