{"id":13429874,"url":"https://github.com/ritterim/stuntman","last_synced_at":"2025-09-27T00:30:49.873Z","repository":{"id":30775738,"uuid":"34332518","full_name":"ritterim/stuntman","owner":"ritterim","description":"Library for impersonating users during development leveraging ASP.NET Identity.","archived":true,"fork":false,"pushed_at":"2021-10-19T14:35:19.000Z","size":13336,"stargazers_count":294,"open_issues_count":8,"forks_count":35,"subscribers_count":28,"default_branch":"master","last_synced_at":"2024-09-20T06:02:21.272Z","etag":null,"topics":["asp","authentication","authorization","bearer","c-sharp","middleware","nuget","owin"],"latest_commit_sha":null,"homepage":"https://rimdev.io/stuntman/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ritterim.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-21T14:37:35.000Z","updated_at":"2024-09-16T14:48:04.000Z","dependencies_parsed_at":"2022-08-26T15:42:18.862Z","dependency_job_id":null,"html_url":"https://github.com/ritterim/stuntman","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ritterim%2Fstuntman","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ritterim%2Fstuntman/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ritterim%2Fstuntman/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ritterim%2Fstuntman/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ritterim","download_url":"https://codeload.github.com/ritterim/stuntman/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219871828,"owners_count":16554457,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asp","authentication","authorization","bearer","c-sharp","middleware","nuget","owin"],"created_at":"2024-07-31T02:00:47.048Z","updated_at":"2025-09-27T00:30:48.737Z","avatar_url":"https://github.com/ritterim.png","language":"C#","funding_links":[],"categories":["Frameworks, Libraries and Tools","C#","C# #","C\\#","框架, 库和工具","Authentication and Authorization"],"sub_categories":["Authentication and Authorization","身份认证和授权"],"readme":"![Stuntman logo](https://raw.githubusercontent.com/ritterim/stuntman/master/stuntman-icon-128.png)\n\n\u003e \"Sometimes you need a Stuntman before you send in real, unsuspecting users!\"\n\n| Package                       | Version |\n| ----------------------------- | ------- |\n| [RimDev.Stuntman][NuGet link] | [![RimDev.Stuntman NuGet Version](https://img.shields.io/nuget/v/RimDev.Stuntman.svg)][NuGet link] |\n\n**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.\n\n![Stuntman demo](https://cloud.githubusercontent.com/assets/1012917/10737939/5154bbdc-7beb-11e5-87dd-979c4e8cb3c0.gif)\n\n## Installation\n\nInstall the [RimDev.Stuntman][NuGet link] NuGet package.\n\n```\nPM\u003e Install-Package RimDev.Stuntman\n```\n\n## Usage\n\n### Startup / Middleware registration\n\nStuntman 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.\n\n```csharp\n// OWIN Startup class\npublic class Startup\n{\n    public static readonly StuntmanOptions StuntmanOptions = new StuntmanOptions();\n\n    public void Configuration(IAppBuilder app)\n    {\n        StuntmanOptions\n            .AddUser(new StuntmanUser(\"user-1\", \"User 1\")\n                .AddClaim(\"given_name\", \"John\")\n                .AddClaim(\"family_name\", \"Doe\"));\n\n        // Optionally assign a user an access token.\n        StuntmanOptions\n            .AddUser(new StuntmanUser(\"user-2\", \"User 2\")\n                .SetAccessToken(\"123\")\n                .AddClaim(\"given_name\", \"Mary\")\n                .AddClaim(\"family_name\", \"Smith\"));\n\n        // You can also add users using HTTP/HTTPS or the file system!\n        StuntmanOptions\n            .AddUsersFromJson(\"https://example.com/web-test-users.json\")\n            .AddUsersFromJson(@\"C:\\local-test-users.json\");\n\n        // Optional alignment of user picker\n        // Supported options are:\n        // - StuntmanAlignment.Left (default)\n        // - StuntmanAlignment.Center\n        // - StuntmanAlignment.Right\n        StuntmanOptions.SetUserPickerAlignment(StuntmanAlignment.Right);\n\n        // Only show when debug is true in Web.config.\n        if (System.Web.HttpContext.Current.IsDebuggingEnabled)\n        {\n            app.UseStuntman(StuntmanOptions);\n        }\n    }\n}\n```\n\n```csharp\n// ASP.NET Core\npublic class Startup\n{\n    public static readonly StuntmanOptions StuntmanOptions = new StuntmanOptions();\n\n    public Startup(IConfiguration configuration)\n    {\n        StuntmanOptions\n            .AddUser(new StuntmanUser(\"user-1\", \"User 1\")\n                .AddClaim(\"given_name\", \"John\")\n                .AddClaim(\"family_name\", \"Doe\"));\n\n        Configuration = configuration;\n    }\n\n    public IConfiguration Configuration { get; }\n\n    public void ConfigureServices(IServiceCollection services)\n    {\n        services.AddStuntman(StuntmanOptions);\n    }\n\n    public void Configure(IApplicationBuilder app, IHostingEnvironment env)\n    {\n        app.UseStuntman(StuntmanOptions);\n    }\n}\n```\n\n### View\n\nHere'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)*.\n\n```\n@* Only show when debug is true in Web.config. *@\n@if (System.Web.HttpContext.Current.IsDebuggingEnabled)\n{\n    @Html.Raw(YourApplicationNamespace.Startup.StuntmanOptions.UserPicker(User));\n}\n```\n\n### Bearer-token\n\nStuntman 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:\n\n```shell\n\u003e curl -i -H \"Authorization: Bearer 123\" http://localhost:54917/secure\nHTTP/1.1 200 OK\n```\n\nBasic format-checking is done on the value:\n\n```shell\n\u003e curl -i -H \"Authorization: Bearer not-real\" http://localhost:54917/secure\nHTTP/1.1 403 options provided does not include the requested 'not-real' user.\n```\n\n```shell\n\u003e curl -i -H \"Authorization: Bearer abc 123\" http://localhost:54917/secure\nHTTP/1.1 400 Authorization header is not in correct format.\n```\n\n### Remote users\n\nUsers can be populated from remote locations using one or more of the following:\n\n- From the file system\n\n```csharp\nStuntmanOptions.AddUsersFromJson(\"C:\\\\path\\\\to\\\\users.json\");\n```\n- From a web url to a JSON file\n\n```csharp\nStuntmanOptions.AddUsersFromJson(\"https://example.com/users.json\");\n```\n- From a web url to a Stuntman instance with a running server\n\n```csharp\n//\n// On the server\n//\nStuntmanOptions.EnableServer();\n\n//\n// On the client\n//\nStuntmanOptions.AddConfigurationFromServer(\"https://some-stuntman-enabled-app.example.com/\");\n// or, if you prefer to not throw an exception\n// and have the users silently not added\n// if the server is unavailable:\nStuntmanOptions.TryAddConfigurationFromServer(\"https://some-stuntman-enabled-app.example.com/\");\n```\n\n### Example users JSON\n\nHere's an example users JSON that can be consumed by `StuntmanOptions.AddUsersFromJson(string pathOrUrl)`:\n\n```json\n{\n  \"Users\": [\n    {\n      \"Id\": \"user-1\",\n      \"Name\": \"User 1\"\n    },\n    {\n      \"Id\": \"user-2\",\n      \"Name\": \"User 2\"\n    }\n  ]\n}\n```\n\n## Contributing\n\nHave an idea? Let's talk about it in an issue!\n\nFind a bug? Open an issue or submit a pull request!\n\n## License\n\nMIT License\n\n[NuGet link]: https://www.nuget.org/packages/RimDev.Stuntman\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fritterim%2Fstuntman","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fritterim%2Fstuntman","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fritterim%2Fstuntman/lists"}