C# ICustomAuthorizerRequestValidator isn';有人打电话吗?
我正在尝试使用C# ICustomAuthorizerRequestValidator isn';有人打电话吗?,c#,oauth,.net-core,identityserver4,C#,Oauth,.net Core,Identityserver4,我正在尝试使用addCustomAuthorizationRequestValidator方法来提供自定义声明验证。我甚至无法在ICustomAuthorizeRequestValidator实现中获得要命中的断点。我错过什么了吗? 配置服务方法代码: services.AddMvc(); services.AddOptions(); services.AddTransient<ICustomAuthorizeRequestValidator, Saml2BearerValidato
addCustomAuthorizationRequestValidator
方法来提供自定义声明验证。我甚至无法在ICustomAuthorizeRequestValidator
实现中获得要命中的断点。我错过什么了吗?
配置服务方法代码:
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);
services.AddMvc();
services.AddOptions();
services.AddTransient();
services.AddIdentityServer()
.AddTestUsers(Config.GetUsers())
.AddConfigurationStore(生成器=>
builder.UseSqlServer(_settings.Value.ConnectionString,options=>
选项。MigrationAssembly(MigrationAssembly)))
.AddStore(生成器=>
builder.UseSqlServer(_settings.Value.ConnectionString,options=>
选项。MigrationAssembly(MigrationAssembly)))
.addCustomAuthorizationRequestValidator()
.AddSigningCredential(CertificateManager.GetFromStorage(
_settings.Value.ServerCertificateThumb,_settings.Value.ServerCertificatePass));
return services.ConfigureAutofacServicesProvider(_settings.Value.Abc_xacml_n3_diagnostic);
取决于IdentityServer构建内容的方式,这是否可能是由于添加调用的位置造成的
如果IdentityServer直接从您正在添加的内容构建中间件管道,那么它可能在到达管道中的该点之前被处理
我很好奇你是否有幸解决了这个问题。我也有同样的问题。我创建了自定义授权 创建一个类CustomValidationGrant,它实现:
IExtensionGrantValidator,其中TUser:IdentityUser,new()
,有一个参数GrantType,对于这个实例,我可以称它为“custom”
在startUp.cs中添加services.AddIdentityServer().AddExtensionGrantValidator()
不要忘记为您的客户允许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
});
var discoveryClient=新的discoveryClient(“http://localhost:5000");
discoveryClient.Policy.RequireHttps=false;
var doc=await discoveryClient.GetAsync();
var参数=新字典();
添加(“范围”、“MyScope”);
参数。添加(“客户机密”、“某些机密”);
参数。添加(“用户名”、“用户名”);
参数。添加(“密码”、“密码”);
var tokenResponse=await client.RequestTokenAsync(新TokenRequest
{
地址=令牌端点,
ClientId=“您的客户”,
GrantType=“自定义”,
参数=参数
});
在startup.cs中使用以下代码
services.RemoveAll<IdentityServer4.Validation.ICustomAuthorizeRequestValidator>();
services.AddTransient<IdentityServer4.Validation.ICustomAuthorizeRequestValidator, UserManagementApiCustomAuthorizeRequestValidator>();
services.RemoveAll();
services.AddTransient();
为我工作这对我不起作用