我需要使用CSOM访问SharePoint资源。
我还需要使用从ADFS服务器获得的cookie来验证此类请求。
我可以使用一些第三方图书馆来获取Fedauth和RTFA Cookie,因此我不会被迫自己做肮脏的工作?
要使用CSOM访问SharePoint资源,我们不需要获得cookie,我们可以按照以下代码进行身份验证:
/// <summary>
/// set authentication of SharePoint online
/// </summary>
/// <param name="clientContext"></param>
/// <param name="userName"></param>
/// <param name="password"></param>
public static void setOnlineCredential(ClientContext clientContext,string userName,string password)
{
//set the user name and password
SecureString secureString = new SecureString();
foreach (char c in password.ToCharArray())
{
secureString.AppendChar(c);
}
clientContext.Credentials = new SharePointOnlineCredentials(userName, secureString);
}
/// <summary>
/// set authentication of SharePoint on-premise
/// </summary>
/// <param name="clientContext"></param>
/// <param name="userName"></param>
/// <param name="password"></param>
/// <param name="domain"></param>
public static void setClientCredential(ClientContext clientContext, string userName, string password, string domain)
{
clientContext.Credentials = new NetworkCredential(userName, password, domain);
}
此外,对于SharePoint在线,我们可以使用HTTPCLCLIENT进行身份验证以获取cookie并在C#代码中访问令牌。我们可以参考以下文章:
SharePoint Online在线远程身份验证(和DOC上传(
您可以使用webbrowser进行身份验证,然后可以使用cookie打开您的上下文,例如https://code.msdn.microsoft.com/remote-authentication-authentication-intentication-in-b7b6f43c
Microsoft建议我使用这种方法。现在,我正在对网络核心实施此功能。根据当前的支持,它不支持Windows Form库。你有更好的主意吗?