How to set up Hangfire authentication in Production

Asked

Viewed 124 times

0

I’m using Hangfire to manage background tasks, it works normally when I’m on localhost, but in the production environment I’m not being able to set up the authentication needed to open Dashboard

I tried it this way, but I didn’t get good results

Classe Startup

 //Politica de autenticação das controllers
            services.AddMvc(options =>
            {
                var policy = new AuthorizationPolicyBuilder()
                    .RequireAuthenticatedUser()
                    .Build();
                options.Filters.Add(new AuthorizeFilter(policy));
            })
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
            .AddJsonOptions(opt => opt.SerializerSettings.ReferenceLoopHandling =
            Newtonsoft.Json.ReferenceLoopHandling.Ignore);

Classe AuthorizationFilterHangfire que eu criei

 public class AuthorizationFilterHangfire : IDashboardAuthorizationFilter
    {

        public bool Authorize([NotNull]DashboardContext context)
        {
            var httpContext = context.GetHttpContext();            

            return httpContext.User.Identity.IsAuthenticated;

        }

    }
}

I am using Identity for authentication with the concepts of Claims. But Identity is always false, someone would know how to solve it?

  • How are you receiving the information from the logged in user? Cookie or header? You can share the method Configure startup-class?

  • 1

    I’ve got it, thank you!

  • Great. How do you feel about answering your question with the solution you found? This will help other people who might have the same problem.

  • 1

    Direct url blocked on the server, with VPN-only access ;)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.