gpt4 book ai didi

c# - Web Api/ASP.NET Windows 身份验证如何工作?

转载 作者:太空狗 更新时间:2023-10-29 23:49:46 37 4
gpt4 key购买 nike

根据官方 asp.net 网站

Integrated Windows authentication enables users to log in with their Windows credentials, using Kerberos or NTLM. The client sends credentials in the Authorization header

但它在同一页面上使用这种方法的优点

Built into IIS. Does not send the user credentials in the request.

这有点令人困惑。那么 Windows 身份验证如何在对 Web Api/ASP.NET 的 http 请求中真正起作用?

最佳答案

ASP.NET Windows 身份验证利用一些技术使其实现相对透明和无缝。使用的基本身份验证模式是 Kerberos 和/或 NTLM,如下所述。基本身份验证过程完成后,IIS 将结果传递给 ASP.NET。结果是经过身份验证的用户或匿名用户。然后 ASP.NET 开始构建您的应用程序使用的 IPrinciple 对象。

Kerberos

--------------             --------------
- - ----(1)---> - -
- Client - <---(2)---- - Domain -
- - ----(3)---> - Controller -
- - <---(4)---- - -
-------------- --------------
\ /\
(5) \
\ (6)
\/ \
--------------
- -
- Web -
- Server -
- -
--------------

(1) - 客户端从 KDC 请求 TGT
(2) - KDC向客户端发送TGT
(3) - 客户端使用TGT向TGS请求资源访问
(4) - TGS 向客户端发送 session key 和票据
(5) - 客户端向网络服务器发送票据
(6) - Web 服务器向客户端发送响应

NTLM

--------------             --------------
- - ----(1)---> - -
- Client - <---(2)---- - Web -
- - ----(3)---> - Server -
- - <---(6)---- - -
-------------- --------------
\ /\
(4) \
\ (5)
\/ \
--------------
- -
- Domain -
- Controller -
- -
--------------

(1) - 客户端使用用户名从网络服务器请求访问
(2) - Web 服务器向客户端发送质询消息
(3) - 客户端使用密码哈希(NTLM 响应)加密质询并发送到 Web 服务器
(4) - Web 服务器向域 Controller 发送用户名、质询和 NTLM 响应
(5) - 域 Controller 检查 NTLM 响应
(6) - Web 服务器向客户端发送响应

引用资料:
https://learn.microsoft.com/en-us/windows/desktop/secauthn/microsoft-kerberos
https://learn.microsoft.com/en-us/windows/desktop/secauthn/microsoft-ntlm

关于c# - Web Api/ASP.NET Windows 身份验证如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40337918/

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