1

我按照此处的指示指定了用户和密码http://jaydata.org/blog/jaydata-1.0.5-is-here-with-authentication-support-and-more 但我不断收到 401。有什么想法吗?

4

3 回答 3

0

你能用 fiddler 或 wireshark 捕获流量吗?基本身份验证确实有效....

于 2012-12-14T07:02:20.240 回答
0

好的,

I found a solution for my issue above. The problem was a misconfiguration on server side using CORS. In the recorded request (see http://i.stack.imgur.com/F228l.png) Chrome sends a "preflighted request" (HTTP request has the method OPTIONS).

Unlike simple requests (discussed above), "preflighted" requests first send an HTTP request by the OPTIONS method to the resource on the other domain, in order to determine whether the actual request is safe to send.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Preflighted_requests

我没有验证服务器上的 HTTP 属性“方法”,所以我的 BasicAuth 模块为每个传入的 HTTP 请求启动了授权过程,但由于没有设置授权标头,所以在执行第一个请求(“预检请求”)时立即失败。

在修改了 HTTP 方法的验证后,一切正常。

我还不得不调整 web.conf

<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
  <add name="BasicAuthModule" type="NutritionDataService.Auth.BasicAuthModule"/>
</modules>
<httpProtocol>
  <customHeaders>
    <add name="Access-Control-Allow-Origin" value="*" />
    <add name="Access-Control-Max-Age" value="3600" />
    <add name="Access-Control-Allow-Headers" value="Origin, Content-Type, Accept, MaxDataServiceVersion, Authorization, Access-Control-Allow-Origin, DataServiceVersion" />
    <add name="Access-Control-Allow-Methods" value="PUT, POST, GET, DELETE, MERGE, OPTIONS" />
  </customHeaders>
</httpProtocol>

Access-Control-Allow-Headers 必须获取每个请求的标头,否则您将收到 501 响应。(在上面的屏幕截图中是“接受,最大数据服务版本。数据服务版本,授权”)

于 2015-01-07T14:36:07.690 回答
0

我有同样的问题。我关注了博客文章(http://jaydata.org/blog/jaydata-1.0.5-is-here-with-authentication-support-and-more)并将基础身份验证的凭据应用于上下文初始化。

var ctx = new NutritionDataService.NutritionDbEntities({
        name: 'oData',
        oDataServiceHost: 'https://localhost:44300/Data.svc',
        user: "usr1", 
        password: "test" 
 });

但似乎没有设置授权标头。

http://i.stack.imgur.com/F228l.png

我也尝试过这篇文章中的方法jaydata 基本身份验证的问题,结果相同 - 没有发送授权标头。

有人知道如何触发 jaydata 发送授权标头吗?

于 2015-01-07T12:59:23.043 回答