azure - CookieAuthentication 和 WindowsAzureADAuthentication 选项之间的区别

标签 azure authentication azure-active-directory

您好,我正在尝试使用 AzureAD 对 webapi 进行简单的身份验证。当我们使用 Azure AD 添加连接的服务时,Startup.cs 类添加以下代码

app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
Tenant = ConfigurationManager.AppSettings["ida:Tenant"],
TokenValidationParameters = new TokenValidationParameters
{
ValidAudience = ConfigurationManager.AppSettings["ida:Audience"]
},
});

当我完成一些身份验证教程时,我看到人们要求使用如下所示的东西

app.UseCookieAuthentication(new CookieAuthenticationOptions());
        app.UseOpenIdConnectAuthentication(
            new OpenIdConnectAuthenticationOptions{....
}

这两者之间有什么区别,我们不应该使用名称中的 AzureAD 选项吗?因为我们使用 AzureAD 连接服务来进行 webApi 身份验证。有人可以澄清一下吗?

最佳答案

Cookie 身份验证

Cookie 身份验证使用 HTTP cookies验证客户端请求并维护 session 信息。其工作原理如下:

  1. 客户端向服务器发送登录请求。
  2. 成功登录后,服务器响应包含 Set-Cookie 包含 cookie 名称、值、到期时间和一些信息的 header 其他信息
  3. 客户端需要在所有的Cookie header中发送这个cookie 向服务器发出后续请求。
  4. 在注销操作中,服务器发回 Set-Cookie header 这会导致 cookie 过期

Note: Cookie authentication is vulnerable to Cross-Site Request Forgeries (CSRF) attacks, so it should be used together with other security measures, such as CSRF tokens. For more details you could take a look here

Azure Active Directory 身份验证:

如您所知Azure Active Directory是一种基于 token 的现代身份验证,它提供单点登录 (SSO),允许用户使用一个密码(或智能卡)对网络上的多个服务器进行身份验证,而无需重新输入凭据。这对于用户来说是一个明显的便利,他们不必记住多个密码或一遍又一遍地执行身份验证过程来访问不同的资源。

最主要的是AAD使用JSON Web Token(JWT) 。从客户端接收到凭据后,服务器会验证凭据并生成包含用户信息的签名 JWT。

它还支持以下最流行的现代身份验证协议(protocol)。

  1. OAuth 2.0
  2. OpenID Connect
  3. WS-Federation
  4. SAML 2.0

Note: the token will never get stored in server(stateless).

因此,主要区别是基于 cookie 的身份验证通常将您的用户敏感信息存储在服务器上,因为它维护的 session 似乎很容易受到攻击,而基于 token 的身份验证是安全的,并且不要保留敏感信息。

参见 basic difference这些拖曳架构如下: enter image description here

选择正确的身份验证:

在这里,我向您展示了一个流程图,它可以增强您为应用程序选择正确身份验证的想法。请看下面:

enter image description here

您也可以看看here为了更好的清晰度。非常感谢。快乐编码!

关于azure - CookieAuthentication 和 WindowsAzureADAuthentication 选项之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55798472/

相关文章:

azure - Azure Key Vault 是否可以与函数一起使用来存储队列触发器的连接字符串?

asp.net-mvc - 使用同一应用程序但具有多个域的单点登录ASP.NET MVC

java - 使用 Angular 和 Spring 进行 Jwt 身份验证

Azure PHP Web 应用广告集成 请求中指定的回复 URL 不匹配

Azure 内部负载均衡器 - 私有(private) DNS?

azure - 无法在 Azure Function App 中保存应用程序设置(我之前能够成功保存)

powershell - 查询 Azure Active Directory 的 UPN 和主 SMTP 地址,然后导出到 CSV

php - 保护我的 PHP 页面免受未经授权的查询

Azure Active Directory appRoleAssignments "Permission being assigned was not found on application"

authentication - 如何在 Azure AD 身份验证后重定向到 ASP Net Core MVC 中的不同 Controller 操作