Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在.net核心WEB API中为每个请求动态分配身份验证选项_C#_.net_Asp.net Core_Authentication_Azure Ad B2c - Fatal编程技术网

C# 在.net核心WEB API中为每个请求动态分配身份验证选项

C# 在.net核心WEB API中为每个请求动态分配身份验证选项,c#,.net,asp.net-core,authentication,azure-ad-b2c,C#,.net,Asp.net Core,Authentication,Azure Ad B2c,我希望通过Azure AD B2C保护我的web API。我使用appsettings保留选项,并按以下代码注册它们 public void ConfigureServices(IServiceCollection services) { services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddMicrosoftIdentityWebApi(options => {

我希望通过Azure AD B2C保护我的web API。我使用appsettings保留选项,并按以下代码注册它们

public void ConfigureServices(IServiceCollection services)
{
    services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
    .AddMicrosoftIdentityWebApi(options =>
    {
        Configuration.Bind("AzureAdB2C", options);

        options.TokenValidationParameters.NameClaimType = "name";
    },
        options => { Configuration.Bind("AzureAdB2C", options); });
}
我想做的是:

  • 请求A来到我的API时,从其令牌中获取一些声明,使用该声明调用其他微服务,并获取AzureAdB2C选项
  • 分配收到的选项(仅针对请求A,因此当其他请求出现时,不应使用相同的AzureAdB2C选项)
  • 验证来自请求A的令牌,如果没有问题,则将此请求发送给控制器。(这里我想使用默认的中间件,如useAuthentication()、useAuthorization()
  • 我的主要问题是第二点,如何动态地分配AzureAdB2C选项,并且只分配每个请求范围