【发布时间】:2020-04-09 10:31:41
【问题描述】:
我从is4aspid 模板(使用 ASP.NET Identity 进行用户管理的基本 IdentityServer)创建了一个 IdentityServer4 服务器,它带有 2 个示例用户。
之后,我按照IdentityServer4 docs 的说明创建了一个剃须刀页面客户端。
应用程序可以工作,但应用程序从身份服务器未知声明中获取,它们是 (type=value):
s_hash=tFpbakJatWNQIjaChraJAw
sid=Sj6JGUgztjOIK1Cq8E-HoA
sub=a070c8cc-d962-440c-a796-e0c169e87578
auth_time=1586427090
idp=local
amr=pwd
我在 appsettings.json 上将服务器客户端定义为:
{
"ClientId": "mvc",
"Enabled": true,
"ClientName": "Mvc Client",
"AllowedGrantTypes": [ "client_credentials", "authorization_code" ],
"RequirePkce": true,
"ClientSecrets": [ { "Value": "hide_for_privacity" } ],
"RedirectUris": [ "https://localhost:5001/signin-oidc" ],
"FrontChannelLogoutUri": "http://localhost:5001/signout-oidc",
"PostLogoutRedirectUris": [ "http://localhost:5001/signout-callback-oidc" ],
"AllowOfflineAccess": true,
"AllowedScopes": [ "openid", "profile", "offline_access", "api1" ]
}
客户端的认证设置如下:
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme)
.AddOpenIdConnect(options =>
{
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.Authority = "http://localhost:5099";
options.RequireHttpsMetadata = false;
options.ClientId = "mvc";
options.ClientSecret = "hide_for_privacity";
options.ResponseType = "code";
options.UsePkce = true;
options.Scope.Add("openid");
options.Scope.Add("profile");
options.Scope.Add("offline_access");
options.SaveTokens = true;
});
我已经使用 jwt.io 解码了返回的令牌,它是有效负载:
{
"nbf": 1586427096,
"exp": 1586427396,
"iss": "http://localhost:5099",
"aud": "mvc",
"nonce": "637220238868623664.MzdjNjI0NmMtNWNhMy00YTg4LWIzYTUtYjcxMTFmMTNlYjhiYWY0ZmM5NTQtNDY1Mi00ZWVhLTlkNjUtY2UzMzIwMjY5NjA4",
"iat": 1586427096,
"at_hash": "Z_Cwm-4UzmH8v8PyW2d0Rg",
"s_hash": "tFpbakJatWNQIjaChraJAw",
"sid": "Sj6JGUgztjOIK1Cq8E-HoA",
"sub": "a070c8cc-d962-440c-a796-e0c169e87578",
"auth_time": 1586427090,
"idp": "local",
"amr": ["pwd"]
}
为什么我没有收到服务器中定义的用户名和角色??
【问题讨论】:
标签: asp.net-core identityserver4 dotnetopenauth