私は同じ問題を抱えていた、奇妙なことは、私が追加したクレームは、アクセストークンに存在したが、セキュリティで保護されたAPIはそれを拒否しました。あなたのstartup.csで
[Produces("application/json")]
[Authorize("Founder")]
[Route("api/ApiResourceWithPolicy")]
public class ApiResourceWithPolicyController : Controller
{
[HttpGet]
public IActionResult Get()
{
return new JsonResult(new { ResourceType = "With Policy", ResourceName = "Api2" });
}
}
そして、このポリシー設定:
ervices.AddAuthorization(options => options.AddPolicy("Founder", policy => policy.RequireClaim("Employee", "Mosalla")));
今すぐに必要な主張を追加する何をする必要があると私たちは、このAPIがあると、あなたのクライアントにクレームを追加することですあなたのクライアントは、ここで重要な点はClientClaimsPrefix
に空の文字列を設定することです:IdentityServer4は主張をプレフィックスとリソースサーバにそれらを認識できない作るためだ
public static IEnumerable<Client> GetClients()
{
return new List<Client>
{
new Client
{
ClientId = "client1",
// no interactive user, use the clientid/secret for authentication
AllowedGrantTypes = GrantTypes.ClientCredentials,
// secret for authentication
ClientSecrets =
{
new Secret("123654".Sha256())
},
// scopes that client has access to
AllowedScopes = {"Api1"},
Claims = new[]
{
new Claim("Employee", "Mosalla"),
new Claim("website", "http://hamidmosalla.com")
},
ClientClaimsPrefix = ""
}
}
:
あなたはより多くの説明訪問my post about policy-based authorization with IdentityServer4が必要な場合。
「https:// localhost:33132/identity /。well-known/openid-configuration」から設定を取得することができません。このエラーが発生するため、IDサーバ4で証明書を使用する必要がありますか。 –