Use Authorization middleware instead of AuthorizationAttribute ASPNET Core

后端 未结 1 1746
清酒与你
清酒与你 2021-01-01 02:07

I have a dedicated IdServer running that has the login page that other applications will boot unauthenticated users to.

My current pipeline is:

app.U         


        
相关标签:
1条回答
  • 2021-01-01 02:42

    Just needed to add the AuthenticationManager Challenge:

    app.Use(async (context, next) =>
    {
        var authService = context.RequestServices.GetRequiredService<IAuthorizationService>();
    
    
        if (!await authService.AuthorizeAsync(context.User, context, "Api"))
        {
            await context.Authentication.ChallengeAsync("oidc");
        }
        else
        {
            await next();
        }
    });
    
    0 讨论(0)
提交回复
热议问题