如何将 OR 子句添加到 ASP.NET CORE 授权策略?

How can I add an OR clause to a ASP.NET CORE Authorization Policy?

我有一个在系统中执行某些操作所需的声明列表。我有一个政策列表来验证是否存在执行某些操作的声明。一切都按预期工作。

我想做的是,如果另一个声明具有特定价值,则忽略对这些声明的检查。例如,我有这些政策:

            options.AddPolicy("AdjustmentFundAdmin", policy => { 
                policy.RequireClaim("AdjustmentFundAdmin");
            });
            options.AddPolicy("ManifestApprover", policy => {
                policy.RequireClaim("ManifestApprover");
            });
            options.AddPolicy("InvoiceProcessor", policy => {
                policy.RequireClaim("InvoiceProcessor");
            });

但我想做的是,如果有 claim/value: policy.RequireClaim("manna_tms_userlevel", "magician") 然后忽略政策中的这些声明检查。

我尝试添加多个,但这似乎只需要两个而不是一个或另一个。

            options.AddPolicy("AdjustmentFundAdmin", policy => {
                policy.RequireClaim("AdjustmentFundAdmin");
                policy.RequireClaim("manna_tms_userlevel", "magician");
            });

感谢@TonyHopkinson 的帮助!

我能够让它像这样工作:

           options.AddPolicy("AdjustmentFundAdmin", policy => {
                policy.RequireAssertion(context =>
                    context.User.HasClaim(c =>
                    (c.Type == "AdjustmentFundAdmin" || 
                    (c.Type == "manna_tms_userlevel" && 
                     c.Value == "magician"))));
            });