【问题标题】:ICustomAuthorizeRequestValidator isn't being called?没有调用 ICustomAuthorizeRequestValidator?
【发布时间】:2018-02-07 20:32:00
【问题描述】:

我正在尝试使用AddCustomAuthorizeRequestValidator 方法来提供自定义声明验证。我什至无法在ICustomAuthorizeRequestValidator 实现中设置断点。我错过了什么吗? My breakpoint

ConfigureServices 方法代码:

services.AddMvc();

services.AddOptions();

services.AddTransient<ICustomAuthorizeRequestValidator, Saml2BearerValidator>();

services.AddIdentityServer()
    .AddTestUsers(Config.GetUsers())
    .AddConfigurationStore(builder =>
        builder.UseSqlServer(_settings.Value.ConnectionString, options =>
                options.MigrationsAssembly(migrationsAssembly)))
    .AddOperationalStore(builder =>
        builder.UseSqlServer(_settings.Value.ConnectionString, options =>
                options.MigrationsAssembly(migrationsAssembly)))
    .AddCustomAuthorizeRequestValidator<Saml2BearerValidator>()
    .AddSigningCredential(CertificateManager.GetFromStorage(
                _settings.Value.ServerCertificateThumb, _settings.Value.ServerCertificatePass));

    return services.ConfigureAutofacServicesProvider(_settings.Value.Abc_xacml_n3_diagnostic);

【问题讨论】:

    标签: c# oauth .net-core identityserver4


    【解决方案1】:

    根据 IdentityServer 构建事物的方式,这是否可能是由于 where 您正在添加该调用?

    如果 IdentityServer 直接从您添加的内容构建中间件管道,则它可能会在它到达管道中的那个点之前被处理。

    很好奇你是否有幸解决了这个问题。

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题。我改为创建自定义授权。

      创建一个类 CustomValidationGrant 实现:IExtensionGrantValidator where TUser : IdentityUser, new(),有一个参数 GrantType,对于这个例子我可以称之为“自定义”

      在 startUp.cs 添加services.AddIdentityServer() .AddExtensionGrantValidator&lt;CustomValidationGrant &gt;()

      不要忘记为您的客户允许一个grantType。

      在控制台应用程序中,您可以使用如下内容:

      var discoveryClient = new DiscoveryClient("http://localhost:5000");
      discoveryClient.Policy.RequireHttps = false;
      
      var doc = await discoveryClient.GetAsync();
      
      var parameters = new Dictionary<string, string>();
      
      parameters.Add("scope", "MyScope");
      
      parameters.Add("client_secret", "SomeSecret");
      
      parameters.Add("UserName", "UserName");
      
      parameters.Add("Password", "Password");
      
      
      var tokenResponse = await client.RequestTokenAsync(new TokenRequest
      {
             Address = tokenEndpoint,
             ClientId = "your client",
             GrantType = "custom",
             Parameters = parameters
      });
      

      【讨论】:

        【解决方案3】:

        在您的 startup.cs 中使用以下代码

        services.RemoveAll<IdentityServer4.Validation.ICustomAuthorizeRequestValidator>();
                services.AddTransient<IdentityServer4.Validation.ICustomAuthorizeRequestValidator, UserManagementApiCustomAuthorizeRequestValidator>();
        

        为我工作

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-12-09
          • 2013-11-06
          • 2014-11-28
          • 2013-08-11
          • 2017-08-19
          • 2015-04-10
          相关资源
          最近更新 更多