我对此有点疯狂..我声称身份验证适用于 Windows Store 应用程序中的共享点在线站点。但是 Windows Phone 8 应用程序中完全相同的代码不起作用。一个区别是 System.Net.Http-namespace 仅作为 Windows Phone 的 Nuget 包提供。
身份验证过程是首先向 microsoft 发送 HttpRequest 以检索 STS Saml 令牌。然后将此令牌与第二个 HttpRequest 一起发送到 sharepoint 在线站点以获取身份验证 cookie (FedAuth / rtFA)。
在 Windows Store App STA Saml 令牌中:
HttpRequestMessage {Method: POST, RequestUri: https://login.microsoftonline.com/extSTS.srf', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Accept: application/soap+xml; charset=utf-8
Content-Type: application/soap+xml; charset=utf-8
Content-Length: 1335
}} System.Net.Http.HttpRequestMessage
HttpResponse {StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Pragma: no-cache
X-XSS-Protection: 0
PPServer: PPV: 30 H: CO1IDOALGN08 V: 0
Connection: close
Cache-Control: no-cache
Date: Tue, 29 Oct 2013 07:52:18 GMT
P3P: CP="DSP CUR OTPi IND OTRi ONL FIN"
Server: Microsoft-IIS/7.5
Content-Length: 3661
Content-Type: application/soap+xml; charset=utf-8
Expires: Tue, 29 Oct 2013 07:51:18 GMT
}} System.Net.Http.HttpResponseMessage
HttpResponse.Content {byte[3661]} byte[]
在 Windows 应用商店应用 SPOAuthToken 中:
HttpRequestMessage {Method: POST, RequestUri: 'https://xxx.sharepoint.com/SitePages/Startsida.aspx', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Accept: application/x-www-form-urlencoded
Content-Type: application/x-www-form-urlencoded
Content-Length: 893
}} System.Net.Http.HttpRequestMessage
HttpResponse {StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
X-SharePointHealthScore: 0
SPRequestGuid: 0556519c-19a2-20e0-a937-44fc861d2ddc
request-id: 0556519c-19a2-20e0-a937-44fc861d2ddc
X-FRAME-OPTIONS: SAMEORIGIN
SPRequestDuration: 742
SPIisLatency: 1
MicrosoftSharePointTeamServices: 16.0.0.2120
X-Content-Type-Options: nosniff
X-MS-InvokeApp: 1; RequireReadOnly
Cache-Control: max-age=0, private
Date: Tue, 29 Oct 2013 07:52:57 GMT
P3P: CP="ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI"
Set-Cookie: 8167acc39dff40bf855ec089c80b8fbc2ca28f1fc09f48f5ad16ab2bd0e6ee02i%3A0%23%2Ef%7Cmembership%7Crobert%40portalplus%2Ese=0; expires=Wed, 30-Oct-2013 07:52:57 GMT; path=/; HttpOnly
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Content-Length: 107958
Content-Type: text/html; charset=utf-8
Expires: Mon, 14 Oct 2013 07:52:56 GMT
Last-Modified: Tue, 29 Oct 2013 07:52:56 GMT
}} System.Net.Http.HttpResponseMessage
HttpResponse.Content {byte[107958]} byte[]
在 Windows Phone App STA Saml 令牌中:
HttpRequestMessage {Method: POST, RequestUri: 'https://login.microsoftonline.com/extSTS.srf', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Accept: application/soap+xml; charset=utf-8
Content-Type: application/soap+xml; charset=utf-8
Content-Length: 1335
}} System.Net.Http.HttpRequestMessage
HttpResponse {StatusCode: 200, ReasonPhrase: 'OK', Version: 0.0, Content: System.Net.Http.StreamContent, Headers:
{
Cache-Control: no-cache
Pragma: no-cache
Server: Microsoft-IIS/7.5
P3P: CP="DSP CUR OTPi IND OTRi ONL FIN"
X-XSS-Protection: 0
PPServer: PPV: 30 H: CO1IDOLGN56 V: 0
Date: Tue, 29 Oct 2013 07:50:25 GMT
Connection: close
Content-Length: 3661
Content-Type: application/soap+xml; charset=utf-8
Expires: Tue, 29 Oct 2013 07:49:26 GMT
}} System.Net.Http.HttpResponseMessage
HttpResponse.Content {byte[3661]} byte[]
在 Windows Phone 应用程序 SPOAuthToken 中:
HttpRequestMessage {Method: POST, RequestUri: 'https://xxx.sharepoint.com/SitePages/Startsida.aspx', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Accept: application/x-www-form-urlencoded
Content-Type: application/x-www-form-urlencoded
Content-Length: 893
}} System.Net.Http.HttpRequestMessage
HttpResponse {StatusCode: 200, ReasonPhrase: 'OK', Version: 0.0, Content: System.Net.Http.StreamContent, Headers:
{
Cache-Control: max-age=0, private
Server: Microsoft-IIS/7.5
X-SharePointHealthScore: 0
X-AspNet-Version: 4.0.30319
SPRequestGuid: ef55519c-0917-20e0-6056-033a05a409d8
request-id: ef55519c-0917-20e0-6056-033a05a409d8
X-FRAME-OPTIONS: SAMEORIGIN
SPRequestDuration: 1289
SPIisLatency: 0
X-Powered-By: ASP.NET
MicrosoftSharePointTeamServices: 16.0.0.2120
X-Content-Type-Options: nosniff
X-MS-InvokeApp: 1; RequireReadOnly
P3P: CP="ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI"
Date: Tue, 29 Oct 2013 07:51:25 GMT
Content-Length: 107956
Content-Type: text/html; charset=utf-8
Expires: Mon, 14 Oct 2013 07:51:24 GMT
Last-Modified: Tue, 29 Oct 2013 07:51:24 GMT
}} System.Net.Http.HttpResponseMessage
HttpResponse.Content {byte[107956]} byte[]
我看到的差异是
- 响应: WP 中的 0.0 版而不是 WS 中的 1.1 版
- 没有响应 WP8 的 Set-Cookie(根本错误)
- SPO-cookies WS 的 ResponseContent 比 WP8 大 2 个字节
WP8 中是否有某些东西在他们“离开电话”之前以某种方式使 http 请求无效?非常感谢任何和所有想法。
编辑:我现在相当肯定 WP8 OS 是罪魁祸首。我已将身份验证代码移动到可移植库中,因此我可以在两个平台上运行完全相同的代码。不过,只有商店应用程序有效!奇怪的事情还在继续:当在实际手机而不是模拟器上以调试模式运行时,我确实得到了 cookie。
但是,在 WP 中执行的可移植代码中,cookie 以不同的方式存储在 CookieContainer 中,所以我还不能真正使用 cookie 从 Sharepoint 检索任何数据......我的头很痛。
结论:Windows Phone OS 对数据做了一些奇怪的事情,可能是在接收端,因为我实际上是从 Microsoft/SP 获得原始 cookie 数据。当它进入可移植代码时,它看起来与 Windows 8 中的不同。
EDIT2:经过进一步检查,我发现用于将 cookie 放入客户端的 cookiecontainer 行为不同。
将 cookie 添加到容器后,有一个私有字符串“m_fqdnMyDomain”在 WP8 中为空,但在从 W8 运行时包含我的域。GetCookies(uri) 在 WP8 中不返回任何内容(即使我只是使用 Add(uri, cookie) 添加它们)但在 W8 中正确返回它们。所有这些都发生在两个环境中运行的相同可移植代码中。