IdentityServer4 角色如何表现?
IdentityServer4 How do roles behave?
我正在尝试设置 IdentityServer 4 asp.net 核心应用程序。
我正在学习本教程:Getting started with IdentityServer4
我在 Startup class 中配置了所有测试集合,我启动了应用程序并作为我配置的测试用户之一登录。
客户:
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")
},
}
当我尝试登录时,服务器响应成功。但是告诉我用户对我的任何资源都没有访问权限。你能告诉我为什么吗?
您没有任何使用涉及用户的 OAuth 流程的应用程序(又名 clients
)。您唯一的客户 teacup.Showroom
正在使用 GrantTypes.ClientCredentials
,它专门设计用于在用户上下文之外工作,因此您的用户自然无法授予对任何应用程序的访问权限,因为一开始就没有符合条件的应用程序。
您应该检查 Identity Server 4 Samples,特别是,您可以从 Implicit Flow
的样本开始,这将涉及用户登录并同意应用程序(客户端),因此也会出现在"Client Application Access" 之后的视图。
我正在尝试设置 IdentityServer 4 asp.net 核心应用程序。 我正在学习本教程:Getting started with IdentityServer4
我在 Startup class 中配置了所有测试集合,我启动了应用程序并作为我配置的测试用户之一登录。
客户:
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")
},
}
当我尝试登录时,服务器响应成功。但是告诉我用户对我的任何资源都没有访问权限。你能告诉我为什么吗?
您没有任何使用涉及用户的 OAuth 流程的应用程序(又名 clients
)。您唯一的客户 teacup.Showroom
正在使用 GrantTypes.ClientCredentials
,它专门设计用于在用户上下文之外工作,因此您的用户自然无法授予对任何应用程序的访问权限,因为一开始就没有符合条件的应用程序。
您应该检查 Identity Server 4 Samples,特别是,您可以从 Implicit Flow
的样本开始,这将涉及用户登录并同意应用程序(客户端),因此也会出现在"Client Application Access" 之后的视图。