在讨论这个问题之前,让我告诉你我想要达到的目标。我需要在我的所有应用程序中实现某种 SSO。为此,我想使用ASP.NET 零解决方案作为 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));
}