gpt4 book ai didi

azure - GetAuthenticationCookie 返回 "Value cannot be null. Parameter name: cookieHeader"的 SharePoint Online 问题

转载 作者:行者123 更新时间:2023-12-03 02:25:08 25 4
gpt4 key购买 nike

我通过 API 接口(interface)对 SharePoint Online 用户进行身份验证。在过去的几年里,它一直运行良好。但从星期一开始我收到错误

Value cannot be null. Parameter name: cookieHeader

有一个代码可以在 Azure 上托管的 API 中为 SharePoint Online 生成 HTTPClientHandler。

HttpClientHandler result = new HttpClientHandler();
try
{

SecureString securePassword = new SecureString();

foreach (char c in userPassword) { securePassword.AppendChar(c); }

SharePointOnlineCredentials credentials = new SharePointOnlineCredentials(userName, securePassword);

result.Credentials = credentials;

string authCookieValue = credentials.GetAuthenticationCookie(new Uri(hostWebURL));

result.CookieContainer.SetCookies(new Uri(hostWebURL), authCookieValue);

}
catch (Exception ex)
{
throw ex;
}

return result;

在上面的代码行中,我们得到了“authCookieValue”的空值。

我还使用以下命令通过 SharePoint Online Management Shell 检查了“LegacyAuthProtocolsEnabled”的值,它已经是正确的。

$TenantSettings = Get-SPOTenant
$TenantSettings.LegacyAuthProtocolsEnabled

最佳答案

我在某个时候开始遇到同样的错误。这显然是 Sharepoint Online 方面的变化,因为多年来我这边没有任何变化。

我认为为我解决这个问题的关键是:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

见下文:

public async Task<List<SharepointDocumentDetail>> GetFileInfoFromSharepoint(string specificFolderUrl)
{
// Once I added this, the error went away
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

List<SharepointDocumentDetail> ret = new List<SharepointDocumentDetail>();

var restUrl = string.Format("{0}/_api/web/GetFolderByServerRelativeUrl('{1}')/Files?$expand=Files", this.Sharepoint_DocRootUrl, specificFolderUrl);

//Creating Credentials
var passWord = new SecureString();
foreach (var c in this.Sharepoint_Password) passWord.AppendChar(c);

var credential = new SharePointOnlineCredentials(this.Sharepoint_User, passWord);

using (var handler = new HttpClientHandler() { Credentials = credential })
{
Uri uri = new Uri(this.Sharepoint_DocRootUrl);

// I was getting the error on this line
handler.CookieContainer.SetCookies(uri, credential.GetAuthenticationCookie(uri));
...
...
...

关于azure - GetAuthenticationCookie 返回 "Value cannot be null. Parameter name: cookieHeader"的 SharePoint Online 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67299846/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com