使用Office 365 / SharePoint在线验证客户端

时间:2014-01-06 13:01:52

标签: c# sharepoint office365 sharepoint-object-model sharepoint-online

我有一个使用SharePoint Web服务(list.asmx)的客户端应用程序。最近,SharePoint已迁移到SharePoint Online。现在身份验证失败了。

这可能是因为SharePoint Online中的身份验证机制不同。我引用了文章http://www.wictorwilen.se/Post/How-to-do-active-authentication-to-Office-365-and-SharePoint-Online.aspx来进行身份验证。但由于某种原因,我现在收到身份验证错误。

请注意我不希望弹出身份验证窗口,因为我的客户端是一项服务。

有人可以给我一些关于如何使用SharePoint Online进行身份验证的指针/示例工作应用程序吗?

Atul Sureka

2 个答案:

答案 0 :(得分:13)

SharePoint Online(SPO)使用基于声明的身份验证模式。微软发布了包含的SharePoint Online Client Components SDK 可以在SPO中用于SharePoint Web服务身份验证的SharePointOnlineCredentials class

如何在SharePoint Online(SPO)中验证SharePoint Web服务

以下示例演示了如何检索身份验证Cookie:

private static CookieContainer GetAuthCookies(Uri webUri, string userName, string password)
{
    var securePassword = new SecureString();
    foreach (var c in password) { securePassword.AppendChar(c); }
    var credentials = new SharePointOnlineCredentials(userName, securePassword);
    var authCookie = credentials.GetAuthenticationCookie(webUri);
    var cookieContainer = new CookieContainer();
    cookieContainer.SetCookies(webUri, authCookie);
    return cookieContainer;
}

示例

string sourceUrl = "https://contoso.sharepoint.com/Documents/SharePoint User Guide.docx";
string destinationUrl = "https://contoso.sharepoint.com/Documents/SharePoint User Guide 2013.docx";
FieldInformation[] fieldInfos;
CopyResult[] result;
byte[] fileContent;
using(var proxyCopy = new Copy())
{
     proxyCopy.Url = webUri + "/_vti_bin/Copy.asmx";
     proxyCopy.CookieContainer = GetAuthCookies(webUri, userName, password);

     proxyCopy.GetItem(sourceUrl,out fieldInfos,out fileContent);
     proxyCopy.CopyIntoItems(sourceUrl,new []{ destinationUrl}, fieldInfos, fileContent, out result);
 }

参考

答案 1 :(得分:10)

您可以使用SharePoint客户端对象模型在线登录S​​harePoint。如果您使用用户名和密码进行身份验证,而不是OAuth方法,则不会弹出身份验证窗口。

如何操作,请参阅此article