C# 使用office 365/SharePoint online验证客户端
我有一个使用SharePoint web服务(list.asmx)的客户端应用程序。最近SharePoint已迁移到SharePoint Online。现在身份验证失败了 这可能是因为SharePoint Online中的身份验证机制不同。我参考了这篇文章来进行身份验证。然而,由于某些原因,我现在得到了身份验证错误 请注意,我不想弹出身份验证窗口,因为我的客户端是一个服务 有人能给我一些关于如何使用SharePoint Online进行身份验证的指针/示例工作应用程序吗C# 使用office 365/SharePoint online验证客户端,c#,sharepoint,office365,sharepoint-object-model,sharepoint-online,C#,Sharepoint,Office365,Sharepoint Object Model,Sharepoint Online,我有一个使用SharePoint web服务(list.asmx)的客户端应用程序。最近SharePoint已迁移到SharePoint Online。现在身份验证失败了 这可能是因为SharePoint Online中的身份验证机制不同。我参考了这篇文章来进行身份验证。然而,由于某些原因,我现在得到了身份验证错误 请注意,我不想弹出身份验证窗口,因为我的客户端是一个服务 有人能给我一些关于如何使用SharePoint Online进行身份验证的指针/示例工作应用程序吗 Atul Sureka您
Atul Sureka您可以使用SharePoint客户端对象模型登录SharePoint online。如果使用用户名和密码进行身份验证,而不是OAuth方法,则不会弹出任何身份验证窗口 有关如何执行此操作,请参阅。SharePoint Online(SPO)使用基于声明的身份验证模式。Microsoft发布的包含 可用于SPO中的SharePoint Web Services身份验证 如何在SharePoint Online(SPO)中验证SharePoint Web Services 以下示例演示如何检索身份验证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);
}
工具书类