[英]ASP.NET Core 2.0 Dynamic Authentication
在ConfigureServices
使用.AddOpenIdConnect()
,是否可以根据请求中的主机更改ClientId
和ClientSecret
?
我知道Startup
本身无法访问HttpContext
,但我想知道是否使用中间件可以解决这个问题,它可以访问上下文。
我尝试过以下链接,但是在通过CustomAuthHandler ASP.NET Core 2.0身份验证中间件运行后,我的值始终为null
我相信你可以实现你的目标分配函数RedirectToIdentityProvider
属性。
在重定向到身份提供程序以进行身份验证之前调用。 这可用于设置将通过身份验证过程持久化的ProtocolMessage.State。 ProtocolMessage还可用于添加或自定义发送到身份提供者的参数。
public void ConfigureServices(IServiceCollection services)
{
services
.AddAuthentication()
.AddOpenIdConnect(options =>
{
options.Events.OnRedirectToIdentityProvider = context =>
{
// Retrieve identity from current HttpContext
var identity = context.HttpContext.User.Identity;
// Lookup for your client_id and client_secret
var clientId = "find your client id";
var clientSecret = "find your client secret";
// Assign client_id and client_secret
context.ProtocolMessage.ClientId = clientId;
context.ProtocolMessage.ClientSecret = clientSecret;
return Task.FromResult(0);
};
});
}
相关链接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.