【发布时间】:2020-11-18 00:56:31
【问题描述】:
这是我的 Identity Server 项目的 ConfigureServices 方法。
public void ConfigureServices(IServiceCollection services)
{
services.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddOperationalStore(options =>
{
options.EnableTokenCleanup = true;
options.TokenCleanupInterval = 30; // interval in seconds
})
.AddInMemoryApiResources(Config.GetApiResources())
.AddInMemoryClients(Config.GetClients())
.AddTestUsers(Config.GetUsers())
.AddProfileService<DefaultProfileService>();
}
当我按照教程进行操作时,教程使用.AddProfileService<ProfileService>(),但我找不到ProfileService。所以我使用DefaultProfileService。会不会是这个错误?
在我的config.cs
公共类配置 { 公共静态 IEnumerable GetApiResources() { 返回新列表 { new ApiResource("myresourceapi", "我的资源 API") { 范围 = {新范围(“apiscope”)} } }; }
public static IEnumerable<Client> GetClients()
{
return new[]
{
// for public api
new Client
{
ClientId = "secret_client_id",
AllowedGrantTypes = GrantTypes.ClientCredentials,
ClientSecrets =
{
new Secret("secret".Sha256())
},
AllowedScopes = { "apiscope" }
},
new Client
{
ClientId = "secret_user_client_id",
AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
ClientSecrets =
{
new Secret("secret".Sha256())
},
AllowedScopes = { "apiscope" }
}
};
}
public static List<TestUser> GetUsers()
{
return new List<TestUser>
{
new TestUser
{
SubjectId = "1",
Username = "user",
Password = "user",
Claims = new[]
{
new Claim("roleType", "CanReaddata")
}
},
new TestUser
{
SubjectId = "2",
Username = "admin",
Password = "admin",
Claims = new[]
{
new Claim("roleType", "CanUpdatedata")
}
}
};
}
}
当我在 Postman 测试它时,我收到了错误 invalid_request
我已经测试了另一个客户端 ID ClientId = "secret_client_id",它可以工作。
【问题讨论】:
标签: identityserver4