小编Teo*_*vov的帖子

将身份验证从dotnet核心1.1迁移到dotnet核心2.0

我们只是将我们的身份验证中间件从.net核心1.1迁移到.net核心2.0,遵循答案中的示例.然而,当我尝试发出请求时(即使在尝试访问Swagger UI时),所有内容都会构建和运行.我在我的自定义AuthenticationHandler调用上得到以下异常UserAuthHandler : System.InvalidOperationException: A suitable constructor for type 'BrokerAPI.AuthMiddleware.UserAuthHandler' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.
代码来自UserAuthHandler:

public class UserAuthHandler : AuthenticationHandler<UserAuthAuthenticationOptions>    
{
    protected UserAuthHandler(IOptionsMonitor<UserAuthAuthenticationOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) : base(options, logger, encoder, clock)
    {
    }

    protected override Task<AuthenticateResult> HandleAuthenticateAsync()
    {
        //handle authentication
        var ticket = new AuthenticationTicket(new ClaimsPrincipal(identity),
           new AuthenticationProperties(), "UserAuth");

        return Task.FromResult(AuthenticateResult.Success(ticket));
    }
} …
Run Code Online (Sandbox Code Playgroud)

dependency-injection asp.net-authentication asp.net-core

3
推荐指数
1
解决办法
310
查看次数