我正在尝试设置一个IdentityServer 4 asp.net核心应用程序。我正在学习本教程:开始使用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")
},
}当我尝试登录时,服务器会成功地响应。但是告诉我用户对我的任何资源都没有访问权限。你能告诉我为什么吗?

发布于 2019-07-26 14:31:05
您没有任何使用涉及用户的OAuth流的应用程序(也称为clients)。您唯一的客户端teacup.Showroom是使用专门为用户上下文以外的工作而设计的GrantTypes.ClientCredentials,因此您的用户自然无法授予对任何应用程序的访问权,因为一开始就没有合格的应用程序。
您应该检查Identity Server 4示例,特别是可以从Implicit Flow的示例开始,这将涉及用户登录应用程序(客户端)并同意应用程序(client),因此也会出现在“”视图中。
https://stackoverflow.com/questions/57219430
复制相似问题