ASP.身份服务器和客户端的.NET零解决方案



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

我正在使用ASP。. NET零模板:ASP。. NET Core - MVCjQuery

我对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项目(localhost),我正试图使OpenId通过上述服务器进行身份验证。

第二个项目的AppSettings-在本地运行

"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.

正在创建一个cookie,密钥为"Identity.External"但是登录并没有成功。

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

尝试添加

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

之前services.AddAuthentication ()

将映射声明NameIdentifier声明GetExternalLoginInfoAsync不会返回null。

最新更新