It turns out that there is a slight difference in the HTTP responses returned by the Wave 15 version of SharePoint Online compared with the 2010 version. Some of the URLs returned appear in triplicate, separated by commas. Discarding the multiple copies of the URLs brings the code back into working order.
The MSDN sample code can work in the new version of SharePoint Online, once you edit the ExtraHeadersFromResponse method in the ClaimsWebAuth class like so:
private bool ExtraHeadersFromResponse(WebResponse response, out string loginUrl, out Uri navigationEndUrl) { loginUrl = null; navigationEndUrl = null; try { // For some reason, SharePoint Online Wave 15 Preview seems to return these responses in triplicate, separated by commas // Let's just get the first one string returnUrl = response.Headers[Constants.CLAIM_HEADER_RETURN_URL]; if (returnUrl != null && returnUrl.Contains(",")) { returnUrl = returnUrl.Substring(0, returnUrl.IndexOf(",", StringComparison.InvariantCultureIgnoreCase)); } navigationEndUrl = new Uri(returnUrl); loginUrl = (response.Headers[Constants.CLAIM_HEADER_AUTH_REQUIRED]); if (loginUrl != null && loginUrl.Contains(",")) { loginUrl = loginUrl.Substring(0, loginUrl.IndexOf(",", StringComparison.InvariantCultureIgnoreCase)); } return true; } catch { return false; } }Once this change is made, the code works in both the current and the next versions of SharePoint Online.
Wow, this was troubling me for a while. Thanks for you post! This works flawlessly.
ReplyDelete--Max
Excellent! It's good to know that
Deletea) this is useful info, and
b) it hasn't changed over the last couple of months!
I expect we'll see quite a few tweaks to the 365 Preview as we approach the release.
Hi
ReplyDeleteDid you know if this code also work for actual SP2013 online version ?
Hi Lionel,
DeleteYes it does work against SP 2013 Online, I used this method to create the SharePoint 2013 Explorer tool (http://sharepointrepairjoint.blogspot.com.au/2012/07/sharepoint-2013-explorer.html) which I just used to connect to a Office 365 tenancy.
i used this.
ReplyDeletehttp://vrdmn.blogspot.com/2013/01/authenticating-net-client-object-model.html
Thanks! That blog post you've linked to describes a much better method for SP Online 2013 that will support both attended and unattended scenarios.
DeleteI'm very glad that Microsoft have felt the pain that developers were going through trying to simply connect into Office 365 and have provided a new improved method in the 2013 release!