Skip to content

Commit bc3e729

Browse files
authored
Merge pull request #1 from IdentityManager/master
* Updated test host to .NET Core 2.2 * Initial removal of OAuth code * Removed API side OAuth code * Basic first approach using samesite cookie * Updated npm dependencies * Fixed lodash security warning * Cleanup * Updated constants class. Minor refactor of DI registrations * Added missing call to AddAuthentication * Switched index to razor view * Disabling hardcoded cookie auth (preparation to use more complicated authentication/authorization ways), make PageController route path to be fully configurable in order to serve IdentityManager2 from different configurable routes, library and deps bumps * Renaming Bootstrap.min.css to bootstrap.min.css - docker build fail to serve not existing file (case sensitivity) * Refactorization of route and authorization config to be fully configurable * clientside libs bump: lodash, gulp-less, server-side dependencies: Automapper 9.* * Initial .NET Core 3 hack * Added newtonsoft JSON * Updated to latest patch version of angularjs 1.3 🤢 * Cleaned up csproj * More auth updates * Initial cookie refresh * Cleaned up test hosts * Re-introduced UseIdentityManager extension method * Added test host with IdentityServer4 * Removed custom base64url encoding * Removed use of AutoMapper * Folder typo * Updated readme * Cleaned up accessor usage * Updated bootstrap and fixed navbar responsiveness * Updated jQuery version
2 parents 31e5ce7 + 449d067 commit bc3e729

87 files changed

Lines changed: 3800 additions & 3970 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

IdentityManager2.sln

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.27520.0
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29519.181
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{21035206-B373-4994-901B-2C9E882B5852}"
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityManager2", "src\IdentityManager2\IdentityManager2.csproj", "{E4718661-6384-4378-82C3-56D66F6E060F}"
99
EndProject
10-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Host", "src\Host\Host.csproj", "{D024CAF4-4371-45C5-9728-D06B462CD4B3}"
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hosts.LosthostAuthentication", "src\Hosts\Hosts.LosthostAuthentication\Hosts.LosthostAuthentication.csproj", "{D024CAF4-4371-45C5-9728-D06B462CD4B3}"
11+
EndProject
12+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hosts.CookieAuthentication", "src\Hosts\Hosts.CookieAuthentication\Hosts.CookieAuthentication.csproj", "{20FEF10D-D003-48A7-A931-4DEB80796E08}"
13+
EndProject
14+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hosts.Shared", "src\Hosts\Hosts.Shared\Hosts.Shared.csproj", "{BE7A2243-B7D0-4D32-92F6-0DD4C8DA8208}"
15+
EndProject
16+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Hosts", "Hosts", "{59FA21EB-3472-4E3D-BDF0-AD32DCFA6035}"
17+
EndProject
18+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hosts.IdentityServerAuthentication", "src\Hosts\Hosts.IdentityServerAuthentication\Hosts.IdentityServerAuthentication.csproj", "{BAACD397-A69F-4F9B-A178-39D734CA78CC}"
1119
EndProject
1220
Global
1321
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -23,13 +31,29 @@ Global
2331
{D024CAF4-4371-45C5-9728-D06B462CD4B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
2432
{D024CAF4-4371-45C5-9728-D06B462CD4B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
2533
{D024CAF4-4371-45C5-9728-D06B462CD4B3}.Release|Any CPU.Build.0 = Release|Any CPU
34+
{20FEF10D-D003-48A7-A931-4DEB80796E08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35+
{20FEF10D-D003-48A7-A931-4DEB80796E08}.Debug|Any CPU.Build.0 = Debug|Any CPU
36+
{20FEF10D-D003-48A7-A931-4DEB80796E08}.Release|Any CPU.ActiveCfg = Release|Any CPU
37+
{20FEF10D-D003-48A7-A931-4DEB80796E08}.Release|Any CPU.Build.0 = Release|Any CPU
38+
{BE7A2243-B7D0-4D32-92F6-0DD4C8DA8208}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39+
{BE7A2243-B7D0-4D32-92F6-0DD4C8DA8208}.Debug|Any CPU.Build.0 = Debug|Any CPU
40+
{BE7A2243-B7D0-4D32-92F6-0DD4C8DA8208}.Release|Any CPU.ActiveCfg = Release|Any CPU
41+
{BE7A2243-B7D0-4D32-92F6-0DD4C8DA8208}.Release|Any CPU.Build.0 = Release|Any CPU
42+
{BAACD397-A69F-4F9B-A178-39D734CA78CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
43+
{BAACD397-A69F-4F9B-A178-39D734CA78CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
44+
{BAACD397-A69F-4F9B-A178-39D734CA78CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
45+
{BAACD397-A69F-4F9B-A178-39D734CA78CC}.Release|Any CPU.Build.0 = Release|Any CPU
2646
EndGlobalSection
2747
GlobalSection(SolutionProperties) = preSolution
2848
HideSolutionNode = FALSE
2949
EndGlobalSection
3050
GlobalSection(NestedProjects) = preSolution
3151
{E4718661-6384-4378-82C3-56D66F6E060F} = {21035206-B373-4994-901B-2C9E882B5852}
32-
{D024CAF4-4371-45C5-9728-D06B462CD4B3} = {21035206-B373-4994-901B-2C9E882B5852}
52+
{D024CAF4-4371-45C5-9728-D06B462CD4B3} = {59FA21EB-3472-4E3D-BDF0-AD32DCFA6035}
53+
{20FEF10D-D003-48A7-A931-4DEB80796E08} = {59FA21EB-3472-4E3D-BDF0-AD32DCFA6035}
54+
{BE7A2243-B7D0-4D32-92F6-0DD4C8DA8208} = {59FA21EB-3472-4E3D-BDF0-AD32DCFA6035}
55+
{59FA21EB-3472-4E3D-BDF0-AD32DCFA6035} = {21035206-B373-4994-901B-2C9E882B5852}
56+
{BAACD397-A69F-4F9B-A178-39D734CA78CC} = {59FA21EB-3472-4E3D-BDF0-AD32DCFA6035}
3357
EndGlobalSection
3458
GlobalSection(ExtensibilityGlobals) = postSolution
3559
SolutionGuid = {22A3DD5E-832A-4FFC-B0B9-1A3D07313154}

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@
44

55
IdentityManager2 is a tool for developers and/or administrators to manage the identity information for users of their applications in ASP.NET Core. This includes creating users, editing user information (passwords, email, claims, etc.) and deleting users. It provides a modern replacement for the ASP.NET WebSite Administration tool that used to be built into Visual Studio.
66

7+
In theory, IdentityManager2 can work with any user store, it just requires an implementation of `IIdentityManagerService`. For example ASP.NET Core Identity usage, check out [IdentityManager2.AspNetIdentity](https://github.com/IdentityManager/IdentityManager2.AspNetIdentity).
8+
79
IdentityManager2 is a development tool and is not designed to be used in production. For production identity management see [AdminUI](https://www.identityserver.com/products).
810

9-
For example usage see "[Getting Started with IdentityManager2](https://www.scottbrady91.com/ASPNET-Identity/Getting-Started-with-IdentityManager2)"
11+
## Articles
12+
13+
- [Getting Started with IdentityManager2](https://www.scottbrady91.com/ASPNET-Identity/Getting-Started-with-IdentityManager2)
14+
15+
## Contributing
1016

11-
**Currently this is a port of the original IdentityManager dev tool. If you're interested in helping to drag the code base into 2018, then check out the issue tracker.**
17+
Currently, IdentityManager2 is a port of the original IdentityManager dev tool. If you're interested in helping to update the codebase, then check out the [issue tracker](https://github.com/IdentityManager/IdentityManager2/issues?q=label%3A%22help+wanted%22+is%3Aissue+is%3Aopen).
1218

1319
Developed and maintained by [Rock Solid Knowledge](https://www.identityserver.com).

src/Host/Host.csproj

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/Host/Program.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/Host/Properties/launchSettings.json

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Security.Claims;
5+
using System.Threading.Tasks;
6+
using Hosts.Shared.InMemory;
7+
using IdentityManager2;
8+
using Microsoft.AspNetCore.Authentication;
9+
using Microsoft.AspNetCore.Mvc;
10+
11+
namespace Hosts.CookieAuthentication
12+
{
13+
public class LoginController : Controller
14+
{
15+
private readonly ICollection<InMemoryUser> users;
16+
17+
public LoginController(ICollection<InMemoryUser> users)
18+
{
19+
this.users = users ?? throw new ArgumentNullException(nameof(users));
20+
}
21+
22+
[HttpGet("login")]
23+
public IActionResult Login(string returnUrl)
24+
{
25+
return View(new LoginModel {ReturnUrl = returnUrl});
26+
}
27+
28+
[HttpPost("login")]
29+
[ValidateAntiForgeryToken]
30+
public async Task<IActionResult> Login(LoginModel model)
31+
{
32+
var user = users.FirstOrDefault(x => x.Username == model.Username && x.Password == model.Password);
33+
34+
if (user != null)
35+
{
36+
var claims = new List<Claim>
37+
{
38+
new Claim("sub", user.Subject),
39+
new Claim("name", user.Username)
40+
};
41+
42+
foreach (var role in user.Claims.Where(x => x.Type == IdentityManagerConstants.ClaimTypes.Role))
43+
{
44+
claims.Add(new Claim(IdentityManagerConstants.ClaimTypes.Role, role.Value));
45+
}
46+
47+
await HttpContext.SignInAsync("cookie", new ClaimsPrincipal(new ClaimsIdentity(claims, "cookie")));
48+
49+
if (Url.IsLocalUrl(model.ReturnUrl)) return LocalRedirect(model.ReturnUrl);
50+
return LocalRedirect("~/");
51+
}
52+
53+
ModelState.AddModelError("", "Invalid username or password");
54+
return View(model);
55+
}
56+
}
57+
58+
public class LoginModel
59+
{
60+
public string Username { get; set; }
61+
public string Password { get; set; }
62+
public string ReturnUrl { get; set; }
63+
}
64+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<ProjectReference Include="..\Hosts.Shared\Hosts.Shared.csproj" />
9+
</ItemGroup>
10+
11+
</Project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.Extensions.Hosting;
3+
4+
namespace Hosts.CookieAuthentication
5+
{
6+
public class Program
7+
{
8+
public static void Main(string[] args)
9+
{
10+
CreateHostBuilder(args).Build().Run();
11+
}
12+
13+
public static IHostBuilder CreateHostBuilder(string[] args) =>
14+
Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>());
15+
}
16+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"profiles": {
3+
"Hosts.CookieAuthentication": {
4+
"commandName": "Project",
5+
"launchBrowser": true,
6+
"applicationUrl": "http://localhost:5000",
7+
"environmentVariables": {
8+
"ASPNETCORE_ENVIRONMENT": "Development"
9+
}
10+
}
11+
}
12+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
using Hosts.Shared.InMemory;
3+
using Microsoft.AspNetCore.Builder;
4+
using Microsoft.Extensions.DependencyInjection;
5+
6+
namespace Hosts.CookieAuthentication
7+
{
8+
public class Startup
9+
{
10+
public void ConfigureServices(IServiceCollection services)
11+
{
12+
// In-memory IdentityManagerService (demo only)
13+
services.AddIdentityManager(options =>
14+
{
15+
options.SecurityConfiguration.HostAuthenticationType = "cookie";
16+
options.SecurityConfiguration.HostChallengeType = "cookie";
17+
})
18+
.AddIdentityMangerService<InMemoryIdentityManagerService>();
19+
20+
var rand = new Random();
21+
services.AddSingleton(x => Users.Get(rand.Next(5000, 20000)));
22+
services.AddSingleton(x => Roles.Get(rand.Next(15)));
23+
24+
services.AddAuthentication("cookie")
25+
.AddCookie("cookie", options =>
26+
{
27+
options.LoginPath = "/login";
28+
});
29+
}
30+
31+
public void Configure(IApplicationBuilder app)
32+
{
33+
app.UseDeveloperExceptionPage();
34+
35+
app.UseRouting();
36+
37+
app.UseStaticFiles();
38+
39+
app.UseAuthentication();
40+
app.UseAuthorization();
41+
42+
app.UseIdentityManager();
43+
44+
app.UseEndpoints(x =>
45+
{
46+
x.MapDefaultControllerRoute();
47+
});
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)