【问题标题】:ASP.NET Zero solution for both identityserver and client身份服务器和客户端的 ASP.NET 零解决方案
【发布时间】:2023-03-16 17:05:01
【问题描述】:

在讨论这个问题之前,让我告诉你我想要达到的目标。 我需要在我的所有应用程序中实现某种 SSO。我想使用 ASP.NET Zero 解决方案作为 SSO 提供商和客户。 有可能还是我想多了?

我正在使用 ASP.NET 零模板:ASP.NET Core - MVC & jQuery

我对 IdentityServer 和 OpenId 非常陌生,所以如果我犯了愚蠢的错误,请原谅我。

在一个 ABP 项目中,我向 IdentityServer AppSettings 添加了一个静态客户端,如下所示。

第一个项目的 AppSettings - 托管应用程序

  {
    "ClientId": "localhost",
    "ClientName": "MVC Client Demo",
    "AllowedGrantTypes": [
      "implicit"
    ],
    "RequireConsent": "true",
    "ClientSecrets": [
      {
        "Value": "test"
      }
    ],
    "RedirectUris": [
      "https://localhost:44302/signin-oidc"
    ],
    "PostLogoutRedirectUris": [
      "https://localhost:44302/Account/Login"
    ],
    "AllowedScopes": [
      "openid",
      "profile",
      "email",
      "phone",
      "default-api"
    ],
    "AllowOfflineAccess": "true"
  }

现在从我的第二个 ABP 项目(本地主机)开始,我正在尝试启用 OpenId 以通过上述服务器进行身份验证。

第二个项目的 AppSettings - 在 localhost 上运行

"OpenId": {
  "IsEnabled": "true",
  "Authority": "https://[applicationname].azurewebsites.net/",
  "ClientId": "localhost",
  "ClientSecret": "test",
  "ValidateIssuer": "true",
  "ClaimsMapping": [
    {
      "claim": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier",
      "key": "http://schemas.microsoft.com/identity/claims/objectidentifier"
    }
  ]
}

但是我没有收到任何错误,在日志中我可以看到一条消息说:

AuthenticationScheme: Identity.External signed in.

正在使用密钥“Identity.External”创建一个 cookie,但登录没有成功。 在 AccountController 下面的行中返回 null 并导致登录失败。

    **var externalLoginInfo = await _signInManager.GetExternalLoginInfoAsync();**
    if (externalLoginInfo == null)
    {
        Logger.Warn("Could not get information from external login.");
        return RedirectToAction(nameof(Login));
    }

【问题讨论】:

    标签: identityserver4 openid aspnetboilerplate abp aspnetzero


    【解决方案1】:

    尝试添加

    JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
    JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Add("sub", ClaimTypes.NameIdentifier);
    

    services.AddAuthentication()之前

    这会将 sub 声明映射到 NameIdentifier 声明,因此 GetExternalLoginInfoAsync 不会返回 null。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-17
    • 2021-08-27
    • 2010-12-04
    • 1970-01-01
    • 1970-01-01
    • 2017-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多