我需要编写业务逻辑,需要ConfigureServices
完全执行。
OnTokenValidated
位于ConfigureServices
内部位置不佳。
有没有
AddOpenIdConnect
中间件的替代方案,以便我在Success
调用时具有使用注入服务的完全灵活性?
services.AddAuthentication(options =>
{
options.DefaultScheme = "cookie";
//...
})
.AddOpenIdConnect("oidc", options =>
{
options.Authority = "https://localhost:5001";
/....
options.Scope.Add("offline_access");
options.Events.OnTokenValidated = async n =>
{
//Need other services which will only
//get injected once ConfigureServices method has fully executed.
};
}
参考资料:为什么使用依赖注入 https://learn.microsoft.com/zh-cn/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-5.0#ASP0000