Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 68 additions & 61 deletions IdentityManager2.sln
Original file line number Diff line number Diff line change
@@ -1,61 +1,68 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29519.181
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{21035206-B373-4994-901B-2C9E882B5852}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityManager2", "src\IdentityManager2\IdentityManager2.csproj", "{E4718661-6384-4378-82C3-56D66F6E060F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hosts.LosthostAuthentication", "src\Hosts\Hosts.LosthostAuthentication\Hosts.LosthostAuthentication.csproj", "{D024CAF4-4371-45C5-9728-D06B462CD4B3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hosts.CookieAuthentication", "src\Hosts\Hosts.CookieAuthentication\Hosts.CookieAuthentication.csproj", "{20FEF10D-D003-48A7-A931-4DEB80796E08}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hosts.Shared", "src\Hosts\Hosts.Shared\Hosts.Shared.csproj", "{BE7A2243-B7D0-4D32-92F6-0DD4C8DA8208}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Hosts", "Hosts", "{59FA21EB-3472-4E3D-BDF0-AD32DCFA6035}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hosts.IdentityServerAuthentication", "src\Hosts\Hosts.IdentityServerAuthentication\Hosts.IdentityServerAuthentication.csproj", "{BAACD397-A69F-4F9B-A178-39D734CA78CC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E4718661-6384-4378-82C3-56D66F6E060F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E4718661-6384-4378-82C3-56D66F6E060F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E4718661-6384-4378-82C3-56D66F6E060F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E4718661-6384-4378-82C3-56D66F6E060F}.Release|Any CPU.Build.0 = Release|Any CPU
{D024CAF4-4371-45C5-9728-D06B462CD4B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D024CAF4-4371-45C5-9728-D06B462CD4B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D024CAF4-4371-45C5-9728-D06B462CD4B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D024CAF4-4371-45C5-9728-D06B462CD4B3}.Release|Any CPU.Build.0 = Release|Any CPU
{20FEF10D-D003-48A7-A931-4DEB80796E08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{20FEF10D-D003-48A7-A931-4DEB80796E08}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20FEF10D-D003-48A7-A931-4DEB80796E08}.Release|Any CPU.ActiveCfg = Release|Any CPU
{20FEF10D-D003-48A7-A931-4DEB80796E08}.Release|Any CPU.Build.0 = Release|Any CPU
{BE7A2243-B7D0-4D32-92F6-0DD4C8DA8208}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BE7A2243-B7D0-4D32-92F6-0DD4C8DA8208}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BE7A2243-B7D0-4D32-92F6-0DD4C8DA8208}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BE7A2243-B7D0-4D32-92F6-0DD4C8DA8208}.Release|Any CPU.Build.0 = Release|Any CPU
{BAACD397-A69F-4F9B-A178-39D734CA78CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BAACD397-A69F-4F9B-A178-39D734CA78CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BAACD397-A69F-4F9B-A178-39D734CA78CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BAACD397-A69F-4F9B-A178-39D734CA78CC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{E4718661-6384-4378-82C3-56D66F6E060F} = {21035206-B373-4994-901B-2C9E882B5852}
{D024CAF4-4371-45C5-9728-D06B462CD4B3} = {59FA21EB-3472-4E3D-BDF0-AD32DCFA6035}
{20FEF10D-D003-48A7-A931-4DEB80796E08} = {59FA21EB-3472-4E3D-BDF0-AD32DCFA6035}
{BE7A2243-B7D0-4D32-92F6-0DD4C8DA8208} = {59FA21EB-3472-4E3D-BDF0-AD32DCFA6035}
{59FA21EB-3472-4E3D-BDF0-AD32DCFA6035} = {21035206-B373-4994-901B-2C9E882B5852}
{BAACD397-A69F-4F9B-A178-39D734CA78CC} = {59FA21EB-3472-4E3D-BDF0-AD32DCFA6035}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {22A3DD5E-832A-4FFC-B0B9-1A3D07313154}
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 18
VisualStudioVersion = 18.0.11111.16 d18.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{21035206-B373-4994-901B-2C9E882B5852}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityManager2", "src\IdentityManager2\IdentityManager2.csproj", "{E4718661-6384-4378-82C3-56D66F6E060F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hosts.LosthostAuthentication", "src\Hosts\Hosts.LosthostAuthentication\Hosts.LosthostAuthentication.csproj", "{D024CAF4-4371-45C5-9728-D06B462CD4B3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hosts.CookieAuthentication", "src\Hosts\Hosts.CookieAuthentication\Hosts.CookieAuthentication.csproj", "{20FEF10D-D003-48A7-A931-4DEB80796E08}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hosts.Shared", "src\Hosts\Hosts.Shared\Hosts.Shared.csproj", "{BE7A2243-B7D0-4D32-92F6-0DD4C8DA8208}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Hosts", "Hosts", "{59FA21EB-3472-4E3D-BDF0-AD32DCFA6035}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hosts.IdentityServerAuthentication", "src\Hosts\Hosts.IdentityServerAuthentication\Hosts.IdentityServerAuthentication.csproj", "{BAACD397-A69F-4F9B-A178-39D734CA78CC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdentityManager2.Apis", "src\IdentityManager2.Apis\IdentityManager2.Apis.csproj", "{A0B9D16D-1969-E880-1A5E-7BC666CB4178}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E4718661-6384-4378-82C3-56D66F6E060F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E4718661-6384-4378-82C3-56D66F6E060F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E4718661-6384-4378-82C3-56D66F6E060F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E4718661-6384-4378-82C3-56D66F6E060F}.Release|Any CPU.Build.0 = Release|Any CPU
{D024CAF4-4371-45C5-9728-D06B462CD4B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D024CAF4-4371-45C5-9728-D06B462CD4B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D024CAF4-4371-45C5-9728-D06B462CD4B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D024CAF4-4371-45C5-9728-D06B462CD4B3}.Release|Any CPU.Build.0 = Release|Any CPU
{20FEF10D-D003-48A7-A931-4DEB80796E08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{20FEF10D-D003-48A7-A931-4DEB80796E08}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20FEF10D-D003-48A7-A931-4DEB80796E08}.Release|Any CPU.ActiveCfg = Release|Any CPU
{20FEF10D-D003-48A7-A931-4DEB80796E08}.Release|Any CPU.Build.0 = Release|Any CPU
{BE7A2243-B7D0-4D32-92F6-0DD4C8DA8208}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BE7A2243-B7D0-4D32-92F6-0DD4C8DA8208}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BE7A2243-B7D0-4D32-92F6-0DD4C8DA8208}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BE7A2243-B7D0-4D32-92F6-0DD4C8DA8208}.Release|Any CPU.Build.0 = Release|Any CPU
{BAACD397-A69F-4F9B-A178-39D734CA78CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BAACD397-A69F-4F9B-A178-39D734CA78CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BAACD397-A69F-4F9B-A178-39D734CA78CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BAACD397-A69F-4F9B-A178-39D734CA78CC}.Release|Any CPU.Build.0 = Release|Any CPU
{A0B9D16D-1969-E880-1A5E-7BC666CB4178}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A0B9D16D-1969-E880-1A5E-7BC666CB4178}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A0B9D16D-1969-E880-1A5E-7BC666CB4178}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A0B9D16D-1969-E880-1A5E-7BC666CB4178}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{E4718661-6384-4378-82C3-56D66F6E060F} = {21035206-B373-4994-901B-2C9E882B5852}
{D024CAF4-4371-45C5-9728-D06B462CD4B3} = {59FA21EB-3472-4E3D-BDF0-AD32DCFA6035}
{20FEF10D-D003-48A7-A931-4DEB80796E08} = {59FA21EB-3472-4E3D-BDF0-AD32DCFA6035}
{BE7A2243-B7D0-4D32-92F6-0DD4C8DA8208} = {59FA21EB-3472-4E3D-BDF0-AD32DCFA6035}
{59FA21EB-3472-4E3D-BDF0-AD32DCFA6035} = {21035206-B373-4994-901B-2C9E882B5852}
{BAACD397-A69F-4F9B-A178-39D734CA78CC} = {59FA21EB-3472-4E3D-BDF0-AD32DCFA6035}
{A0B9D16D-1969-E880-1A5E-7BC666CB4178} = {21035206-B373-4994-901B-2C9E882B5852}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {22A3DD5E-832A-4FFC-B0B9-1A3D07313154}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Hosts.CookieAuthentication
{
[Route("login")]
public class LoginController : Controller
{
private readonly ICollection<InMemoryUser> users;
Expand All @@ -19,13 +20,13 @@ public LoginController(ICollection<InMemoryUser> users)
this.users = users ?? throw new ArgumentNullException(nameof(users));
}

[HttpGet("login")]
[HttpGet(Name = "CookieAuthentication-login")]
public IActionResult Login(string returnUrl)
{
return View(new LoginModel {ReturnUrl = returnUrl});
}

[HttpPost("login")]
[HttpPost("CookieAuthentication-login")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(LoginModel model)
{
Expand Down
34 changes: 18 additions & 16 deletions src/Hosts/Hosts.CookieAuthentication/Program.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

namespace Hosts.CookieAuthentication
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>());
}
}
using Microsoft.AspNetCore.Builder;

namespace Hosts.CookieAuthentication;

public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.ConfigureServices();

var app = builder.Build();
app.Configure();

app.Run();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"Hosts.CookieAuthentication": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "http://localhost:5000",
"launchUrl": "",
"applicationUrl": "https://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
102 changes: 52 additions & 50 deletions src/Hosts/Hosts.CookieAuthentication/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,50 +1,52 @@
using System;
using Hosts.Shared.InMemory;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace Hosts.CookieAuthentication
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// In-memory IdentityManagerService (demo only)
services.AddIdentityManager(options =>
{
options.SecurityConfiguration.HostAuthenticationType = "cookie";
options.SecurityConfiguration.HostChallengeType = "cookie";
})
.AddIdentityMangerService<InMemoryIdentityManagerService>();

var rand = new Random();
services.AddSingleton(x => Users.Get(rand.Next(5000, 20000)));
services.AddSingleton(x => Roles.Get(rand.Next(15)));

services.AddAuthentication("cookie")
.AddCookie("cookie", options =>
{
options.LoginPath = "/login";
});
}

public void Configure(IApplicationBuilder app)
{
app.UseDeveloperExceptionPage();

app.UseRouting();

app.UseStaticFiles();

app.UseAuthentication();
app.UseAuthorization();

app.UseIdentityManager();

app.UseEndpoints(x =>
{
x.MapDefaultControllerRoute();
});
}
}
}
using System;
using Hosts.Shared.InMemory;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace Hosts.CookieAuthentication;

public static class Startup
{
public static void ConfigureServices(this IServiceCollection services)
{
// In-memory IdentityManagerService (demo only)
services.AddIdentityManager(options =>
{
options.SecurityConfiguration.HostAuthenticationType = "cookie";
options.SecurityConfiguration.HostChallengeType = "cookie";
})
.AddIdentityMangerService<InMemoryIdentityManagerService>()
.AddIdentityManagerUI();

var rand = new Random();
services.AddSingleton(x => Users.Get(rand.Next(5000, 20000)));
services.AddSingleton(x => Roles.Get(rand.Next(15)));

services
.AddAuthentication("cookie")
.AddCookie("cookie", options =>
{
options.LoginPath = "/login";
});
}

public static void Configure(this WebApplication app)
{
app.UseDeveloperExceptionPage();

app.UseRouting();

app.UseStaticFiles();

app.UseAuthentication();
app.UseAuthorization();

app.UseIdentityManager();

// Map attribute-routed controllers first
app.MapControllers();

app.MapIdentityManagerUI(string.Empty); // set "launchUrl": "", in launchSettings.json

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Hosts.IdentityServerAuthentication
{
[Route("login")]
public class LoginController : Controller
{
private readonly ICollection<InMemoryUser> users;
Expand Down
22 changes: 12 additions & 10 deletions src/Hosts/Hosts.IdentityServerAuthentication/Program.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.AspNetCore.Builder;

namespace Hosts.IdentityServerAuthentication
namespace Hosts.IdentityServerAuthentication;

public class Program
{
public class Program
public static void Main(string[] args)
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
var builder = WebApplication.CreateBuilder(args);

Startup.ConfigureServices(builder.Services);

var app = builder.Build();
app.Configure();

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>());
app.Run();
}
}
Loading