domainB.contoso.com にある Web アプリケーションから、domainA.contoso.com にある listdata.svc (共有ポイント サービス) にアクセスしたいのですが、認証に問題があるようです。
CORS が有効な状態で、JQuery Ajax 呼び出しを介して ListData.svc にアクセスしようとすると、サーバーは 401 を返します。SharePoint 内から実行する .htm ページから同じクエリを実行すると、ドメインが同じ。
SharePoint は匿名認証をオフにして NTLM を使用しています - 401 は Windows 資格情報が SharePoint サーバーに渡されなかった結果であると推測します - しかし、これらの資格情報をヘッダーに適切に追加する方法がわかりません。 xhrFields: { withCredentials: true } を設定しましたが、認証の問題は解決していないようです。
CORS を有効にするために、IIS の SharePoint で次の HTTP 応答ヘッダーを設定しました。
- Access-Control-Allow-Credentials: true
- Access-Control-Allow-Headers:Origin、Content-Type、Accept
- Access-Control-Allow-Origin: *
- Access-Control-Request-Methods: POST、GET、HEAD、OPTIONS
Web アプリケーションの IIS で Windows 認証が有効になっていますが、IIS で "OPTIONSVerbHandler" HTTP ハンドラーを設定していません。それを読んでも違いはないようです。
JQuery Ajax 呼び出し (subdomainB.contoso.com 上のアプリケーションから):
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: listUrl,
xhrFields: { withCredentials: true },
crossDomain:true,
processData: false,
async: true,
dataType: "json",
converters: {
// WCF Data Service .NET 3.5 incorrectly escapes singles quotes, which is clearly
// not required (and incorrect) in JSON specs.
// http://bugs.jquery.com/ticket/8320?cversion=0&cnum_hist=1
"text json": function (textValue) {
return jQuery.parseJSON(textValue.replace(/(^|[^\\])\\'/g, "$1'"));
}
},
success: function (data, status, xhr) {
//successFunc(data.d.results);
alert("working!");
},
error: function (xhr, status, error) {
alert("failure!");
}
});
HTTP ヘッダーと 401 応答:
Key Value
Request OPTIONS /_vti_bin/ListData.svc/Contacts HTTP/1.1
Accept */*
Origin http://domainB.contoso.com
Access-Control-Request-Method GET
Access-Control-Request-Headers content-type, accept
Accept-Encoding gzip, deflate
User-Agent Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)
Host domainA.contoso.com
Content-Length 0
DNT 1
Connection Keep-Alive
Cache-Control no-cache
Key Value
Response HTTP/1.1 401 Unauthorized
Server Microsoft-IIS/7.5
SPRequestGuid 1e33061c-f555-451b-9d69-0d83eff5f5ea
WWW-Authenticate NTLM
X-Powered-By ASP.NET
MicrosoftSharePointTeamServices 14.0.0.4762
Access-Control-Allow-Headers Origin, Content-Type, Accept
Access-Control-Allow-Origin *
Access-Control-Request-Methods POST, GET, HEAD, OPTIONS
Access-Control-Allow-Credentials true
Date Wed, 15 May 2013 15:04:51 GMT
Content-Length 0