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.



