I want to authenticate against sharepoint online site using SharepointOnlineCredentials class. Below code works fine in a console application. But the same code is generating error when written in wcf data service and consumed in a provider hosted app.
ClientContext clientContext = new ClientContext("<Sharepoint online site url>");
SecureString securePassword = new SecureString();
foreach (char c in _password)
{
securePassword.AppendChar(c);
}
//Generates exception on this step. Exception details provided below
SharePointOnlineCredentials creds = new SharePointOnlineCredentials(_username, securePassword);
clientContext.Credentials = creds;
Exception Details:
Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
at Microsoft.SharePoint.Client.Idcrl.ManagedIdcrl.CheckHResult(Int32 hr) at Microsoft.SharePoint.Client.Idcrl.ManagedIdcrl.EnsureInited() at Microsoft.SharePoint.Client.Idcrl.ManagedIdcrl.LogonIdentity(String username, SecureString password) at Microsoft.SharePoint.Client.Idcrl.SharePointOnlineAuthenticationProvider.Logon(String username, SecureString password) at Microsoft.SharePoint.Client.SharePointOnlineCredentials..ctor(String username, SecureString password)