【发布时间】:2019-12-04 18:18:21
【问题描述】:
我正在尝试设置 IdentityServer 4 asp.net 核心应用程序。 我正在关注本教程:Getting started with IdentityServer4
我在 Startup 类中配置了所有测试集合,我启动了应用程序并以我已配置的测试用户之一登录。
客户:
new Client()
{
ClientId = "teacup.Showroom",
ClientName = "teacup showroom client",
AllowedGrantTypes = GrantTypes.ClientCredentials,
ClientSecrets = new List<Secret>()
{
new Secret(("super.secret.key".Sha256()))
},
AllowedScopes = new List<string>
{
{ "teacup.Authenticate" },
{ "teacup.Register" }
}
}
身份资源:
new List<IdentityResource> {
new IdentityResources.OpenId(),
new IdentityResources.Profile(),
new IdentityResources.Email(),
new IdentityResource {
Name = "customer",
UserClaims = new List<string> {"customer"}
}
};
API 资源:
new ApiResource {
Name = "teacup",
DisplayName = "teacup API",
Description = "teacup API Access",
UserClaims = new List<string> {"customer"},
ApiSecrets = new List<Secret> {new Secret("scopeSecret".Sha256())},
Scopes = new List<Scope> {
new Scope("teacup.Authenticate"),
new Scope("teacup.Register")
}
}
};
这是我登录时使用的测试用户:
new TestUser {
SubjectId = "5BE86359-073C-434B-AD2D-A3932222DABE",
Username = "small",
Password = "th",
Claims = new List<Claim> {
new Claim(JwtClaimTypes.Email, "small@teamhouse.com"),
new Claim(JwtClaimTypes.Role, "customer")
},
}
当我尝试登录时,服务器响应成功。但是告诉我用户对我的任何资源都没有访问权限。你能告诉我为什么吗?
【问题讨论】:
标签: c# asp.net-core asp.net-web-api asp.net-identity identityserver4