1

我正在使用Microsoft.VisualStudio.Services.Client库中的以下代码:

var credential = new VssBasicCredential("", "<PAT>");
var url = "<url>"";
using var vssConnection = new VssConnection(new Uri(url), credential);
await vssConnection.ConnectAsync();

它失败并出现以下异常,我认为这与服务器不允许基本身份验证有关:

System.ComponentModel.Win32Exception (0x80090020): GSSAPI operation failed with error - Unspecified GSS failure.  Minor code may provide more information (SPNEGO cannot find mechanisms to negotiate).
   at System.Net.NTAuthentication.GetOutgoingBlob(Byte[] incomingBlob, Boolean throwOnError, SecurityStatusPal& statusCode)
   at System.Net.NTAuthentication.GetOutgoingBlob(String incomingBlob)
   at System.Net.Http.AuthenticationHelper.SendWithNtAuthAsync(HttpRequestMessage request, Uri authUri, ICredentials credentials, Boolean isProxyAuth, HttpConnection connection, HttpConnectionPool connectionPool, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithNtConnectionAuthAsync(HttpConnection connection, HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.AuthenticationHelper.SendWithAuthAsync(HttpRequestMessage request, Uri authUri, ICredentials credentials, Boolean preAuthenticate, Boolean isProxyAuth, Boolean doRequestAuth, HttpConnectionPool pool, CancellationToken cancellationToken)
   at System.Net.Http.DecompressionHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.DiagnosticsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.Services.Common.VssHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.Services.Common.VssHttpRetryMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
   at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.SendAsync(HttpRequestMessage message, HttpCompletionOption completionOption, Object userState, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.SendAsync[T](HttpRequestMessage message, Object userState, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.Services.Location.Client.LocationHttpClient.GetConnectionDataAsync(ConnectOptions connectOptions, Int64 lastChangeId, CancellationToken cancellationToken, Object userState)
   at Microsoft.VisualStudio.Services.WebApi.Location.VssServerDataProvider.GetConnectionDataAsync(ConnectOptions connectOptions, Int32 lastChangeId, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.Services.WebApi.Location.VssServerDataProvider.ConnectAsync(ConnectOptions connectOptions, CancellationToken cancellationToken)

但是,我设法从命令行成功执行 REST 命令

curl <url>/_apis/projects -u :<PAT>

我正在使用无法修改任何配置的 Azure Devops Server 2019。我正在运行 dotnet-core Alpine docker 映像中的代码。

这是 dotnet 库的限制还是我使用错误?

4

4 回答 4

1

我收到了过期的错误AccessToken

用 验证了这一点curl

创建新令牌后,它起作用了。

于 2021-10-15T11:40:23.493 回答
1

我在 Docker 容器中运行的程序中遇到了同样的错误。原因是 PAT 过期。这在错误消息中不是很清楚(“SPNEGO 找不到协商机制”)。此外,过期的 PAT 在我的开发机器上仍然有效。这就是为什么我什至不认为 PAT 可能已经过期。

新生成的 PAT:一切都在运行。

于 2021-10-15T14:53:45.267 回答
0

如果您想使用 GitHttpClient,正如@Shayki Abramczyk 指出的那样,您应该使用它vssConnection.GetClient<GitHttpClient>()来获取 GitHttpClient 连接。

var credential = new VssBasicCredential("", "<PAT>");
var url = "<url>"";
using var vssConnection = new VssConnection(new Uri(url), credential);
GitHttpClient gitClient = vssConnection.GetClient<GitHttpClient>();

您可以按照Microsoft 文档中的快速入门和示例中的示例进行操作

于 2020-01-23T06:51:37.100 回答
0

问题在于 dotnet Docker 映像的 Alpine 发行版,它尚不支持gss-ntlmssp. 切换到标准映像(基于 Ubuntu - mcr.microsoft.com/dotnet/core/aspnet:3.1)解决了这个问题。

于 2020-01-23T10:26:44.540 回答