• Stars
    star
    143
  • Rank 257,007 (Top 6 %)
  • Language
    C#
  • License
    MIT License
  • Created over 10 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Some authorization filters for Hangfire's Dashboard

Hangfire.Dashboard.Authorization

Some authorization filters for Hangfire's Dashboard for .NET Framework-based ASP.NET Applications.

Installation

This library is available as a NuGet Package:

Install-Package Hangfire.Dashboard.Authorization

Usage

All the available classes implement both IAuthorizationFilter and IDashboardAuthorizationFilter interfaces, and compatible with Hangfire.Core 1.6 and later.

OWIN-based authentication

using Hangfire.Dashboard;

public void Configure(IAppBuilder app)
{
    var options = new DashboardOptions
    {
        Authorization = new [] 
        {
            new AuthorizationFilter { Users = "admin, superuser", Roles = "advanced" },
            new ClaimsBasedAuthorizationFilter("name", "value")
        }
    };
    app.UseHangfireDashboard("/hangfire", options);
}

Basic authentication

Note: If you are using basic authentication together with OWIN security, configure Hangfire BEFORE OWIN security configuration.

Please, keep in mind, if you have no SSL-based instance for your web application you have to disable SslRedirect and RequireSsl options (it's enabled by default for security reasons). Otherwise you will have dead redirect.

var filter = new BasicAuthAuthorizationFilter(
    new BasicAuthAuthorizationFilterOptions
    {
        // Require secure connection for dashboard
        RequireSsl = true,
        // Case sensitive login checking
        LoginCaseSensitive = true,
        // Users
        Users = new[]
        {
            new BasicAuthAuthorizationUser
            {
                Login = "Administrator-1",
                // Password as plain text, SHA1 will be used
                PasswordClear = "test"
            },
            new BasicAuthAuthorizationUser
            {
                Login = "Administrator-2",
                // Password as SHA1 hash
                Password = new byte[]{0xa9,
                    0x4a, 0x8f, 0xe5, 0xcc, 0xb1, 0x9b,
                    0xa6, 0x1c, 0x4c, 0x08, 0x73, 0xd3,
                    0x91, 0xe9, 0x87, 0x98, 0x2f, 0xbb,
                    0xd3}
            }
        }
});

It is also possible to use other than SHA1 crypto provider by specifying it when creating a user:

var user = new BasicAuthAuthorizationUser(HMAC.Create)
{
    Login = "Admin",
    PasswordClear = "Password" // HMAC will be used instead
}

How to generate password hash

Just run this code:

string password = "<your password here>";
using (var cryptoProvider = System.Security.Cryptography.SHA1.Create())
{
    byte[] passwordHash = cryptoProvider.ComputeHash(Encoding.UTF8.GetBytes(password));
    string result = "new byte[] { " + 
        String.Join(",", passwordHash.Select(x => "0x" + x.ToString("x2")).ToArray())
         + " } ";
}

The result variable will contain byte array definition with your password.

More Repositories

1

Hangfire

An easy way to perform background job processing in .NET and .NET Core applications. No Windows Service or separate process required
C#
9,290
star
2

Cronos

A fully-featured .NET library for working with Cron expressions. Built with time zones in mind and intuitively handles daylight saving time transitions
C#
991
star
3

Hangfire.Samples

Sample projects for Hangfire
JavaScript
104
star
4

Hangfire.AspNet

Recommended way to install Hangfire for ASP.NET applications hosted in IIS to make transition to always-running mode simpler
C#
86
star
5

Hangfire.Autofac

Hangfire job activator based on Autofac IoC container
C#
63
star
6

Hangfire.Azure.ServiceBusQueue

ServiceBus Queue support for SQL Server job storage implementation
C#
58
star
7

Hangfire.Documentation

Sphinx-based documentation for Hangfire
HTML
56
star
8

Hangfire.Highlighter

Sample project for Hangfire.Highlighter tutorial
JavaScript
46
star
9

Hangfire.InMemory

In-memory job storage for Hangfire with transactional implementation
C#
41
star
10

Hangfire.SqlServer.RabbitMq

Hangfire RabbitMQ Queues for SQL Server Storage
C#
36
star
11

stdump

Explore stack trace of a running managed process or from a minidump file
C#
20
star
12

Hangfire.io

Source code for the Hangfire official site built with Jekyll, including pages and blog posts
HTML
20
star
13

Hangfire.Ninject

Hangfire job activator based on Ninject IoC Container
C#
18
star
14

Hangfire.Redis

Unsupported version of Hangfire.Redis library
C#
11
star
15

Hangfire.Mailer

Sample project for HangFire.Mailer tutorial
JavaScript
9
star
16

Hangfire.Azure.QueueStorage

Azure Queue Storage support for SQL Server job storage implementation
C#
9
star
17

Hangfire.Build

Psake tasks and functions for building Hangfire projects
PowerShell
5
star
18

Hangfire.DynamicJobs

Dynamic recurring jobs for Hangfire to support multiple code bases with single storage
C#
5
star
19

Hangfire.Api

API Reference documentation for Hangfire based on Sandcastle output
Visual Basic .NET
2
star
20

Hangfire.Harness

JavaScript
2
star