Open Closed

I added Hangfire and HealthCheckUI in HostAPI , but it doesn't work because Authorizationfilter faild, i need to know how to authenticate the user to access hangfire and healthCheckUI #3251


User avatar
0
mostafa_ibrahem22@hotmail.com created

ABP Framework version: commercial v 5.1.3 UI type: Angular DB provider: EF Core Tiered (MVC) or Identity Server Separated (Angular): yes

I added Hangfire and HealthCheckUI in HostAPI

app.UseAuthentication();
app.UseHangfireDashboard("/hangfire", new DashboardOptions
{
    AsyncAuthorization = new[] { new AbpHangfireAuthorizationFilter(requiredPermissionName: MainCorePermissions.HangfireDashboard.Default) }
});


services.Configure<AbpEndpointRouterOptions>(routerOptions =>
{
    routerOptions.EndpointConfigureActions.Add(endpointContext =>
    {
        endpointContext.Endpoints.MapHealthChecksUI(setupOption)
        .RequireAuthorization(MainCorePermissions.HangfireDashboard.Default);
    });
});

but it doesn't work because Authorizationfilter faild, i need to know how to authenticate the user to access hangfire and healthCheckUI


6 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    HTTP.API uses **JwtBearer ** for authentication by default.

    You can set Hangfire and HealthCheckUI in the Identity Server project.

    Or add a Cookies as second authentication scheme. Do not set it as the default authentication scheme.

    builder.Services.AddAuthentication()
        .AddCookie(options =>
        {
            options.ExpireTimeSpan = TimeSpan.FromMinutes(20);
            options.SlidingExpiration = true;
            options.AccessDeniedPath = "/Forbidden/";
        });
    

    https://docs.microsoft.com/en-us/aspnet/core/security/authentication/cookie?view=aspnetcore-6.0

  • User Avatar
    0
    mostafa_ibrahem22@hotmail.com created

    ABP default template has HealthCheckUI project in HTTP.API why I transfer to the Identity Server project?

    and How can I add Cookies as a second authentication scheme depending on the Identity Server project?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    You can add Cookies as a second authentication scheme to the HTTP.API project.

    https://docs.microsoft.com/en-us/aspnet/core/security/authentication/cookie?view=aspnetcore-6.0

  • User Avatar
    0
    mostafa_ibrahem22@hotmail.com created

    You can add Cookies as a second authentication scheme to the HTTP.API project.

    https://docs.microsoft.com/en-us/aspnet/core/security/authentication/cookie?view=aspnetcore-6.0

    Kindly, How can I add Cookies as a second authentication scheme depending on the Identity Server project?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Create an MVC tiered project, and then refer to .AddCookie and .AddOpenIdConnect in Web project.

    Do not set it as the default authentication scheme in HTTP.API project. add a middleware to call the cookie authentication

    app.UseAuthentication();
    app.Use(async (ctx, next) =>
    {
        if (ctx.User.Identity?.IsAuthenticated != true)
        {
            var result = await ctx.AuthenticateAsync("YourCookieAuthenticationScheme); //default is Cookies
            if (result.Succeeded && result.Principal != null)
            {
                ctx.User = result.Principal;
            }
        }
    
        await next();
    });
            
    app.UseHangfireDashboard("/hangfire", new DashboardOptions
    {
        AsyncAuthorization = new[] { new AbpHangfireAuthorizationFilter(requiredPermissionName: MainCorePermissions.HangfireDashboard.Default) }
    });
    
  • User Avatar
    0
    mostafa_ibrahem22@hotmail.com created

    thanks @maliming

Made with ❤️ on ABP v9.1.0-preview. Updated on December 05, 2024, 12:19