asp.net - 使用动态机器 key 生成身份验证 token

标签 asp.net authentication asp.net-identity owin

使用动态机器 key 生成身份验证 token

我正在使用 OWIN 安全上下文和 CookieAuthenticationProvider 生成身份验证 cookie:

public partial class Startup {
    public void ConfigureAuth(IAppBuilder app) {
        app.UseCookieAuthentication(new CookieAuthenticationOptions() {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Authentication/Login"),
            Provider = new CookieAuthenticationProvider()
        });
    }
}

但是,我想在 Multi-Tenancy 环境中实现它。我已经建立了一个具有相关机器 key 属性的租户上下文;我只需要一种方法来根据租户特定的机器 key (而不是 web.config 文件中的机器 key )生成 token 。

理想情况下,我想继承和扩充现有的 OWIN 类(也许 CookieAuthenticationProvider) 而不是实现我自己的。

有谁知道如何从给定的机器/私钥生成身份验证 token ?

比尔


更新

由于无法编辑机器 key ;与其尝试调整机器 key ,不如实现 IDataProtectionProvider 或扩充 DataProtectionProvider 以使用 System.Security.Cryptography.DpapiDataProtector 和将租户特定的私钥作为 specificPurpose 参数传递?

如果所有租户共享机器 key 但每个租户都有自己的私钥,他们将无法解密彼此的身份验证 token ,对吗?

最佳答案

我不建议在网络场中使用 DPAPI。它是为单个主机设计的。人们已经让它发挥作用,但它很脆弱。

您可以用每个租户的 key 包装机器 key 、encryptedKey。 KeyInfo 将允许您确定租户。

关于asp.net - 使用动态机器 key 生成身份验证 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31257697/

相关文章:

.net - 在 web.config 中加密连接字符串

c# - ASP.NET 的 WMI 提供程序

java - android 如何处理url中的空格

php - Web API 身份验证

c# - 我们可以扩展 HttpContext.User.Identity 以在 asp.net 中存储更多数据吗?

asp.net - 将 VS2015 中的 ASP.NET Identity 中的 User Id 类型更改为 int

asp.net - 如何知道用户是否登录?

javascript - jquery Draggable 禁用包含内容的点击功能

c# - 使用 .NET Core 的 Firebase 身份验证 (JWT)

asp.net-identity - 如何在 Multi-Tenancy 环境中使用 Asp.Net Core Identity