Get AuthenticationProperties in ASP.NET 5

前端 未结 1 1609
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-14 19:05

In ASP.NET 5 MVC 6 RC1 how do I retrieve AuthenticationProperties from within a controller or from a filter? HttpContext.Authentication does\'t seem to

1条回答
  •  暖寄归人
    2021-02-14 20:06

    In ASP.NET 5, retrieving the authentication properties is a bit cumbersome as it must be done by instantiating an AuthenticateContext:

    var context = new AuthenticateContext("[your authentication scheme]");
    await HttpContext.Authentication.AuthenticateAsync(context);
    
    if (context.Principal == null || context.Properties == null) {
        throw new InvalidOperationException("The request is not authenticated.");
    }
    
    var properties = new AuthenticationProperties(context.Properties);
    

    0 讨论(0)
提交回复
热议问题