I'm trying to develop a Windows Phone app using Windows Phone 8.1 SDK and Microsoft SharePoint SDK for Windows Phone 8. I was able to successfully authenticate against a normal SharePoint Online site that uses no ADFS:
ClientContext context = new ClientContext(siteUrl);
Authenticator at = new Authenticator();
at.UserName = Login;
at.Password = password;
at.AuthenticationMode = ClientAuthenticationMode.MicrosoftOnline;
at.CookieCachingEnabled = true;
SetAdfsSettings(at);
//at.FederationPassiveAuthUri = "urn:oasis:names:tc:SAML:2.0:ac:classes:Password";
context.Credentials = at;
List photos= context.Web.Lists.GetByTitle("Photos");
However, when I'm trying to authenticate against our corporate SharePoint online site that uses ADFS for SSO, I fail to do so. The problem occurs when I am asked to enter Microsoft credentials. As soon as I enter myLogin@company.com I'm redirected to the page that shows 401 error:
I have a suspicion that I end up at our corporate ADFS site. I thought I could check the URL with Fiddler and WinPhone Emulator, but during the redirect I'm just stuck at this screen:
The code I use when trying to connect to the site that used ADFS:
ClientContext context = new ClientContext(siteUrl);
Authenticator at = new Authenticator();
at.UserName = Login;
at.Password = password;
at.AuthenticationMode = ClientAuthenticationMode.MicrosoftOnline;
at.CookieCachingEnabled = true;
// SetAdfsSettings(at);
at.FederationPassiveAuthUri = "urn:oasis:names:tc:SAML:2.0:ac:classes:Password";
at.NavigateBackAfterAuthentication = true;
at.AllowSmartRouting = true;
at.PromptOnFailure = true;
//at.UagServerUrl = new Uri("https://adfs.mycompany.com/adfs/ls/");
context.Credentials = at;
List photos= context.Web.Lists.GetByTitle("Photos");
UploadDocument(photos, siteUrl, "Photos/", "photo.jpg", photo);
I've captured authentication requests/responses when using CSOM and Console application. So I know pretty well where the requests should go. But I have no idea how to force Authenticator class to work correctly.
Here are all requests that happen when I succcessfully authenticate via a Console application:
- POST https://login.microsoftonline.com/GetUserRealm.srf HTTP/1.1
- POST https://adfs.mycompany.com/adfs/services/trust/2005/usernamemixed HTTP/1.1
- POST https://login.microsoftonline.com/rst2.srf HTTP/1.1
- GET https://myCompany.sharepoint.com/_vti_bin/idcrl.svc/ HTTP/1.1
So the question is this: How do I use Microsoft.SharePoint.Client.Authenticator class (Microsoft.SharePoint.Client.Phone.Auth.Ui.dll) to work with our corporate ADFS?
Any help will be greatly appreciated!