All Projects → ritterim → Stuntman

ritterim / Stuntman

Licence: mit
Library for impersonating users during development leveraging ASP.NET Identity.

Projects that are alternatives of or similar to Stuntman

Grant
OAuth Proxy
Stars: ✭ 3,509 (+1131.23%)
Mutual labels:  middleware, authentication, authorization
Negroni Authz
negroni-authz is an authorization middleware for Negroni
Stars: ✭ 152 (-46.67%)
Mutual labels:  middleware, authorization
Owaspheaders.core
A .NET Core middleware for injecting the Owasp recommended HTTP Headers for increased security
Stars: ✭ 138 (-51.58%)
Mutual labels:  middleware, nuget
Caddy Authz
Caddy-authz is a middleware for Caddy that blocks or allows requests based on access control policies.
Stars: ✭ 221 (-22.46%)
Mutual labels:  middleware, authorization
Dashport
Local and OAuth authentication middleware for Deno
Stars: ✭ 131 (-54.04%)
Mutual labels:  middleware, authentication
Laravel Authz
An authorization library that supports access control models like ACL, RBAC, ABAC in Laravel.
Stars: ✭ 136 (-52.28%)
Mutual labels:  middleware, authorization
React Redux Firebase Authentication
🔥Boilerplate Project for Authentication with Firebase in React and Redux
Stars: ✭ 265 (-7.02%)
Mutual labels:  authentication, authorization
Egg Authz
egg-authz is an authorization middleware for Egg.js based on Casbin
Stars: ✭ 50 (-82.46%)
Mutual labels:  middleware, authorization
Gatekeeper
Lightweight library in C# for implementing roles-based access control (RBAC). With Gatekeeper, you can define users, roles, resources, and permissions, and authorize requests.
Stars: ✭ 25 (-91.23%)
Mutual labels:  nuget, authorization
aarbac
An Automated Role Based Access Control .NET framework with T-SQL Query Parser which automatically parse select, insert, update, delete queries based on the logged in user role
Stars: ✭ 18 (-93.68%)
Mutual labels:  nuget, authorization
dictator
Dictates what your users see. Plug-based authorization.
Stars: ✭ 77 (-72.98%)
Mutual labels:  middleware, authorization
Auth
Authenticator via oauth2
Stars: ✭ 118 (-58.6%)
Mutual labels:  middleware, authentication
Django Channels React Multiplayer
turn based strategy game using django channels, redux, and react hooks
Stars: ✭ 52 (-81.75%)
Mutual labels:  middleware, authentication
Advanced Http4s
🌈 Code samples of advanced features of Http4s in combination with some features of Fs2 not often seen.
Stars: ✭ 136 (-52.28%)
Mutual labels:  middleware, authentication
Authorization
PSR7 Middleware for authorization
Stars: ✭ 50 (-82.46%)
Mutual labels:  middleware, authorization
Laravel Authorize
A middleware to check authorization
Stars: ✭ 179 (-37.19%)
Mutual labels:  middleware, authorization
AspNetCore.Identity.RavenDb
RavenDB user/role persistent store for ASP.NET Core identity provider
Stars: ✭ 17 (-94.04%)
Mutual labels:  nuget, asp
Asp.net Core Graphql Middleware
ASP.Net Core GraphQL Middleware
Stars: ✭ 38 (-86.67%)
Mutual labels:  middleware, asp
Znetcs.aspnetcore.authentication.basic
A simple basic authentication middleware.
Stars: ✭ 40 (-85.96%)
Mutual labels:  middleware, authentication
Imagesharp.web
🌐 High Performance Image Processing Middleware for ASP.NET- Core.
Stars: ✭ 250 (-12.28%)
Mutual labels:  middleware, asp

Stuntman logo

"Sometimes you need a Stuntman before you send in real, unsuspecting users!"

Package Version
RimDev.Stuntman RimDev.Stuntman NuGet Version

Stuntman is a library for impersonating users during development leveraging .NET Claims Identity. Used primarily in web environments like ASP.NET MVC, ASP.NET Web Forms, and OWIN applications that serve HTML. This allows you to test different user scenarios that exist in your application with minimal friction. It also allows you to share those scenarios with other team members via source control.

Stuntman demo

Installation

Install the RimDev.Stuntman NuGet package.

PM> Install-Package RimDev.Stuntman

Usage

Startup / Middleware registration

Stuntman uses OWIN and is registered as middleware, and allows for programmatically preset user scenarios, in the form of claims identities. These presets can be utilized by you or other team members working on the same code base.

// OWIN Startup class
public class Startup
{
    public static readonly StuntmanOptions StuntmanOptions = new StuntmanOptions();

    public void Configuration(IAppBuilder app)
    {
        StuntmanOptions
            .AddUser(new StuntmanUser("user-1", "User 1")
                .AddClaim("given_name", "John")
                .AddClaim("family_name", "Doe"));

        // Optionally assign a user an access token.
        StuntmanOptions
            .AddUser(new StuntmanUser("user-2", "User 2")
                .SetAccessToken("123")
                .AddClaim("given_name", "Mary")
                .AddClaim("family_name", "Smith"));

        // You can also add users using HTTP/HTTPS or the file system!
        StuntmanOptions
            .AddUsersFromJson("https://example.com/web-test-users.json")
            .AddUsersFromJson(@"C:\local-test-users.json");

        // Optional alignment of user picker
        // Supported options are:
        // - StuntmanAlignment.Left (default)
        // - StuntmanAlignment.Center
        // - StuntmanAlignment.Right
        StuntmanOptions.SetUserPickerAlignment(StuntmanAlignment.Right);

        // Only show when debug is true in Web.config.
        if (System.Web.HttpContext.Current.IsDebuggingEnabled)
        {
            app.UseStuntman(StuntmanOptions);
        }
    }
}
// ASP.NET Core
public class Startup
{
    public static readonly StuntmanOptions StuntmanOptions = new StuntmanOptions();

    public Startup(IConfiguration configuration)
    {
        StuntmanOptions
            .AddUser(new StuntmanUser("user-1", "User 1")
                .AddClaim("given_name", "John")
                .AddClaim("family_name", "Doe"));

        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddStuntman(StuntmanOptions);
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        app.UseStuntman(StuntmanOptions);
    }
}

View

Here's how to use Stuntman in a Razor view to show the user picker (assuming the application Startup class has StuntmanOptions that can be used).

@* Only show when debug is true in Web.config. *@
@if (System.Web.HttpContext.Current.IsDebuggingEnabled)
{
    @Html.Raw(YourApplicationNamespace.Startup.StuntmanOptions.UserPicker(User));
}

Bearer-token

Stuntman supports bearer-tokens based on a user's access-token (StuntmanUser.SetAccessToken). There is nothing special about the value and no additional encoding/decoding is necessary. Upon successful authentication, the value is added as a claim. Leveraging the previous Startup code, you could construct an HTTP-request to utilize User 2's access-token:

> curl -i -H "Authorization: Bearer 123" http://localhost:54917/secure
HTTP/1.1 200 OK

Basic format-checking is done on the value:

> curl -i -H "Authorization: Bearer not-real" http://localhost:54917/secure
HTTP/1.1 403 options provided does not include the requested 'not-real' user.
> curl -i -H "Authorization: Bearer abc 123" http://localhost:54917/secure
HTTP/1.1 400 Authorization header is not in correct format.

Remote users

Users can be populated from remote locations using one or more of the following:

  • From the file system
StuntmanOptions.AddUsersFromJson("C:\\path\\to\\users.json");
  • From a web url to a JSON file
StuntmanOptions.AddUsersFromJson("https://example.com/users.json");
  • From a web url to a Stuntman instance with a running server
//
// On the server
//
StuntmanOptions.EnableServer();

//
// On the client
//
StuntmanOptions.AddConfigurationFromServer("https://some-stuntman-enabled-app.example.com/");
// or, if you prefer to not throw an exception
// and have the users silently not added
// if the server is unavailable:
StuntmanOptions.TryAddConfigurationFromServer("https://some-stuntman-enabled-app.example.com/");

Example users JSON

Here's an example users JSON that can be consumed by StuntmanOptions.AddUsersFromJson(string pathOrUrl):

{
  "Users": [
    {
      "Id": "user-1",
      "Name": "User 1"
    },
    {
      "Id": "user-2",
      "Name": "User 2"
    }
  ]
}

Contributing

Have an idea? Let's talk about it in an issue!

Find a bug? Open an issue or submit a pull request!

License

MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].