ITfoxtec.Identity.Saml2 - 具有 Asp.net Core Identity 的多种身份验证方案

时间:2021-05-24 06:18:38

标签: asp.net-core-5.0 itfoxtec-identity-saml2

我知道 here 给出的答案是关于使用表单身份验证和 SAML。就我而言,我在 .Net 5 上使用 Asp.net 核心身份。另外,我使用了两种身份验证方案(Cookie 和 JWT)。

我的身份验证管道如下;

//include identity
services.AddIdentity<ApplicationUser, ApplicationRole>(SetupIdentityOptions)
    .AddEntityFrameworkStores<ApplicationDbContext>()
    .AddDefaultTokenProviders();

//configure cookie and Jwt scheme
services.ConfigureApplicationCookie(...)
services.AddAuthentication(...) //configures default Identity
    .AddJwtBearer(options => {...})

    services.AddAuthorization(options =>
    {
        options.FallbackPolicy = new AuthorizationPolicyBuilder()
        .RequireAuthenticatedUser()
        .Build();
    });

我想知道的是我应该在这个管道中的什么地方添加 SAML2。

一般来说,应用程序应该;

  1. 能够使用 Cookie 身份验证登录(Identity 负责)
  2. Jwt 令牌应该也适用于 Apis(这也适用于 Jwt 方案)
  3. SSO 客户端应从其 IdP 获得身份验证,当重定向到 AssertionConsumer() 时,我将创建其他声明、创建新的 ClaimsIdentity、创建 JWT 令牌(将其传递给客户端)并使用户进入仪表板。

我被困在第三点,即正确添加 SAML 方案而不覆盖 cookie/jwt 方案。

2 个答案:

答案 0 :(得分:1)

您可以使用提供的 example project 中的设置。新添加的中间件不应干扰您已有的。

当 SAML2 IdP 重定向回您的应用程序时,您会得到一个结果来标识经过身份验证的用户,例如电子邮件地址或 SSN(如果它是政府 ID 提供者)。

您可以将该信息与角色(例如,SpecialCustomer、Citizen 或您已有的现有角色)组合到 cookie 或 JWT 令牌中,就像您可能已经为其他用户所做的那样。这始终可以通过角色与其他 cookie 和令牌区分开来。常规的 [Authorize(....)] 属性也可以正常工作。

答案 1 :(得分:1)

错误No sign-in authentication handler is registered for the scheme 'saml2'可能会发生,因为您需要添加services.AddSaml2()app.UseSaml2()