Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用office 365/SharePoint online验证客户端_C#_Sharepoint_Office365_Sharepoint Object Model_Sharepoint Online - Fatal编程技术网

C# 使用office 365/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您

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

这可能是因为SharePoint Online中的身份验证机制不同。我参考了这篇文章来进行身份验证。然而,由于某些原因,我现在得到了身份验证错误

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

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


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);
 }
工具书类

@Matt我有点被卡住了,我正在尝试使用office365进行身份验证,并尝试获取他/她的sharepoint站点的地址以及其中的整个目录。我能成功吗?@KhawajaAsim,你的意思是你有用户名和密码,你想获得根目录下的所有网站集吗?@Matt从popup(login.microsoftonline.com)成功登录后,我只有office365 api的身份验证令牌。如何获取用户sharepoint主机URL?@KhawajaAsim,据我所知,您只能使用powershell命令来实现此目的: