如何在dotnet7中使用windows身份验证进行curl请求?

How to do curl request with windows authentication in dotnet7?

提问人:Jon 提问时间:9/22/2023 最后编辑:Jon 更新时间:9/22/2023 访问量:47

问:

我使用 dotnet7 应用程序创建一个 webapi。

我用来支持 Windows 身份验证:AddAuthentication

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate();
builder.Services.AddHttpContextAccessor();

当我打开 chrome 浏览器时,chrome 会检测到我的 Windows 凭据,它工作正常。

但是如何提出 curl 请求呢?因为我尝试这样做,但它失败了:

curl https://localhost:7166/api/user -u admin:pass -v
curl https://localhost:7166/api/user --ntlm -u admin:pass -v

有域名,没有域名,我得到了 401:

curl https://localhost:7166/user --ntlm -v -u admin:pass
*   Trying 127.0.0.1:7166...
* Connected to localhost (127.0.0.1) port 7166 (#0)
* schannel: disabled automatic use of client certificate
* ALPN: offers http/1.1
* ALPN: server accepted http/1.1
* using HTTP/1.1
* Server auth using NTLM with user '....'
> GET /user HTTP/1.1
> Host: localhost:7166
> Authorization: NTLM TlRMTVNTUAABAAAAB4IIogAAAAAAAAAAAAAAAAAAAAA....==
> User-Agent: curl/8.0.1
> Accept: */*
>
< HTTP/1.1 401 Unauthorized
< Content-Length: 0
< Date: Fri, 22 Sep 2023 10:29:30 GMT
< Server: Kestrel
< WWW-Authenticate: Negotiate
<
* Connection #0 to host localhost left intact
.NET Windows 身份验证 WebAPI

评论

0赞 phuzi 9/22/2023
在超级用户 superuser.com/questions/250053/ 上看到这个问题...
1赞 Jon 9/22/2023
使用 --ntlm 也不起作用。我更新了我的问题。

答: 暂无答案