Skip to content
Merged
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
47 changes: 47 additions & 0 deletions IdentityServer/v7/AspNetIdentity/AspNetIdentity.AppHost/AppHost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var builder = DistributedApplication.CreateBuilder(args);

var idp = builder.AddProject<Projects.IdentityServerAspNetIdentity>("identityserver");

idp.WithCommand(
name: "seed",
displayName: "Seed Database",
executeCommand: async (context) =>
{
var projectMetadata = idp.Resource.GetProjectMetadata();
var projectPath = projectMetadata.ProjectPath;
var process = new System.Diagnostics.Process
{
StartInfo = new System.Diagnostics.ProcessStartInfo
{
FileName = "dotnet",
Arguments = $"run --project \"{projectPath}\" --no-build -- /seed",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
}
};

process.Start();
await process.WaitForExitAsync(context.CancellationToken);

if (process.ExitCode == 0)
{
return CommandResults.Success();
}
else
{
var error = await process.StandardError.ReadToEndAsync();
return CommandResults.Failure(error);
}
},
commandOptions: new CommandOptions
{
IconName = "DatabaseArrowUp",
IsHighlighted = true
});

builder.AddProject<Projects.Client>("client")
.WaitFor(idp);

builder.Build().Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Aspire.AppHost.Sdk/13.2.2">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\IdentityServerAspNetIdentity\IdentityServerAspNetIdentity.csproj" />
<ProjectReference Include="..\Client\Client.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15237",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:21137",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:22137"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17237;http://localhost:15237",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21137",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22137"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.DistributedApplication": "Information"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.DistributedApplication": "Information"
}
}
}
48 changes: 48 additions & 0 deletions IdentityServer/v7/AspNetIdentity/AspNetIdentitySample.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,68 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityServerAspNetIdentit
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Client", "Client\Client.csproj", "{88433EF3-2866-4164-8CEC-A0D2E6A24A27}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNetIdentity.AppHost", "AspNetIdentity.AppHost\AspNetIdentity.AppHost.csproj", "{4A545547-D8E5-430B-A5F2-D2922C15476C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.ServiceDefaults", "..\Aspire.ServiceDefaults\Aspire.ServiceDefaults.csproj", "{A5501B80-5236-4589-8BB3-F6EB87FB2A18}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{63958B15-1C5B-4A95-90F9-D23B30D7225D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{63958B15-1C5B-4A95-90F9-D23B30D7225D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{63958B15-1C5B-4A95-90F9-D23B30D7225D}.Debug|x64.ActiveCfg = Debug|Any CPU
{63958B15-1C5B-4A95-90F9-D23B30D7225D}.Debug|x64.Build.0 = Debug|Any CPU
{63958B15-1C5B-4A95-90F9-D23B30D7225D}.Debug|x86.ActiveCfg = Debug|Any CPU
{63958B15-1C5B-4A95-90F9-D23B30D7225D}.Debug|x86.Build.0 = Debug|Any CPU
{63958B15-1C5B-4A95-90F9-D23B30D7225D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{63958B15-1C5B-4A95-90F9-D23B30D7225D}.Release|Any CPU.Build.0 = Release|Any CPU
{63958B15-1C5B-4A95-90F9-D23B30D7225D}.Release|x64.ActiveCfg = Release|Any CPU
{63958B15-1C5B-4A95-90F9-D23B30D7225D}.Release|x64.Build.0 = Release|Any CPU
{63958B15-1C5B-4A95-90F9-D23B30D7225D}.Release|x86.ActiveCfg = Release|Any CPU
{63958B15-1C5B-4A95-90F9-D23B30D7225D}.Release|x86.Build.0 = Release|Any CPU
{88433EF3-2866-4164-8CEC-A0D2E6A24A27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{88433EF3-2866-4164-8CEC-A0D2E6A24A27}.Debug|Any CPU.Build.0 = Debug|Any CPU
{88433EF3-2866-4164-8CEC-A0D2E6A24A27}.Debug|x64.ActiveCfg = Debug|Any CPU
{88433EF3-2866-4164-8CEC-A0D2E6A24A27}.Debug|x64.Build.0 = Debug|Any CPU
{88433EF3-2866-4164-8CEC-A0D2E6A24A27}.Debug|x86.ActiveCfg = Debug|Any CPU
{88433EF3-2866-4164-8CEC-A0D2E6A24A27}.Debug|x86.Build.0 = Debug|Any CPU
{88433EF3-2866-4164-8CEC-A0D2E6A24A27}.Release|Any CPU.ActiveCfg = Release|Any CPU
{88433EF3-2866-4164-8CEC-A0D2E6A24A27}.Release|Any CPU.Build.0 = Release|Any CPU
{88433EF3-2866-4164-8CEC-A0D2E6A24A27}.Release|x64.ActiveCfg = Release|Any CPU
{88433EF3-2866-4164-8CEC-A0D2E6A24A27}.Release|x64.Build.0 = Release|Any CPU
{88433EF3-2866-4164-8CEC-A0D2E6A24A27}.Release|x86.ActiveCfg = Release|Any CPU
{88433EF3-2866-4164-8CEC-A0D2E6A24A27}.Release|x86.Build.0 = Release|Any CPU
{4A545547-D8E5-430B-A5F2-D2922C15476C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4A545547-D8E5-430B-A5F2-D2922C15476C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4A545547-D8E5-430B-A5F2-D2922C15476C}.Debug|x64.ActiveCfg = Debug|Any CPU
{4A545547-D8E5-430B-A5F2-D2922C15476C}.Debug|x64.Build.0 = Debug|Any CPU
{4A545547-D8E5-430B-A5F2-D2922C15476C}.Debug|x86.ActiveCfg = Debug|Any CPU
{4A545547-D8E5-430B-A5F2-D2922C15476C}.Debug|x86.Build.0 = Debug|Any CPU
{4A545547-D8E5-430B-A5F2-D2922C15476C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4A545547-D8E5-430B-A5F2-D2922C15476C}.Release|Any CPU.Build.0 = Release|Any CPU
{4A545547-D8E5-430B-A5F2-D2922C15476C}.Release|x64.ActiveCfg = Release|Any CPU
{4A545547-D8E5-430B-A5F2-D2922C15476C}.Release|x64.Build.0 = Release|Any CPU
{4A545547-D8E5-430B-A5F2-D2922C15476C}.Release|x86.ActiveCfg = Release|Any CPU
{4A545547-D8E5-430B-A5F2-D2922C15476C}.Release|x86.Build.0 = Release|Any CPU
{A5501B80-5236-4589-8BB3-F6EB87FB2A18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A5501B80-5236-4589-8BB3-F6EB87FB2A18}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A5501B80-5236-4589-8BB3-F6EB87FB2A18}.Debug|x64.ActiveCfg = Debug|Any CPU
{A5501B80-5236-4589-8BB3-F6EB87FB2A18}.Debug|x64.Build.0 = Debug|Any CPU
{A5501B80-5236-4589-8BB3-F6EB87FB2A18}.Debug|x86.ActiveCfg = Debug|Any CPU
{A5501B80-5236-4589-8BB3-F6EB87FB2A18}.Debug|x86.Build.0 = Debug|Any CPU
{A5501B80-5236-4589-8BB3-F6EB87FB2A18}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A5501B80-5236-4589-8BB3-F6EB87FB2A18}.Release|Any CPU.Build.0 = Release|Any CPU
{A5501B80-5236-4589-8BB3-F6EB87FB2A18}.Release|x64.ActiveCfg = Release|Any CPU
{A5501B80-5236-4589-8BB3-F6EB87FB2A18}.Release|x64.Build.0 = Release|Any CPU
{A5501B80-5236-4589-8BB3-F6EB87FB2A18}.Release|x86.ActiveCfg = Release|Any CPU
{A5501B80-5236-4589-8BB3-F6EB87FB2A18}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 4 additions & 0 deletions IdentityServer/v7/AspNetIdentity/Client/Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<ImplicitUsings>true</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Aspire.ServiceDefaults\Aspire.ServiceDefaults.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" />
</ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions IdentityServer/v7/AspNetIdentity/Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

var builder = WebApplication.CreateBuilder(args);

builder.AddServiceDefaults();

builder.Services.AddRazorPages();

builder.Services.AddAuthentication(options =>
Expand All @@ -22,6 +24,8 @@

var app = builder.Build();

app.MapDefaultEndpoints();

if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
Expand Down
23 changes: 12 additions & 11 deletions IdentityServer/v7/AspNetIdentity/Client/Properties/launchSettings.json
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"profiles": {
"Client": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": "true",
"applicationUrl": "https://localhost:5002"
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"Client": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:5002"
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<ImplicitUsings>true</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Aspire.ServiceDefaults\Aspire.ServiceDefaults.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Duende.IdentityServer.AspNetIdentity" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Duende.IdentityServer.Models;
using IdentityServerAspNetIdentity;
using IdentityServerAspNetIdentity.Data;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);

builder.AddServiceDefaults();

builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(
builder.Configuration.GetConnectionString("DefaultConnection")));
Expand Down Expand Up @@ -36,13 +39,18 @@
])
.AddAspNetIdentity<IdentityUser>();

builder.Services.AddLogging(options =>

if (args.Contains("/seed"))
{
options.AddFilter("Duende", LogLevel.Debug);
});
var seedApp = builder.Build();
SeedData.EnsureSeedData(seedApp);
return;
}

var app = builder.Build();

app.MapDefaultEndpoints();

if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
Expand Down
23 changes: 12 additions & 11 deletions IdentityServer/v7/AspNetIdentity/IdentityServerAspNetIdentity/Properties/launchSettings.json
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"profiles": {
"IdentityServerAspNetIdentity": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": "true",
"applicationUrl": "https://localhost:5001"
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"IdentityServerAspNetIdentity": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:5001"
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (c) Duende Software. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Security.Claims;
using Duende.IdentityModel;
using IdentityServerAspNetIdentity.Data;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;

namespace IdentityServerAspNetIdentity;

public class SeedData
{
public static void EnsureSeedData(WebApplication app)
{
using (var scope = app.Services.GetRequiredService<IServiceScopeFactory>().CreateScope())
{
var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
context.Database.EnsureDeleted();
context.Database.Migrate();

var userMgr = scope.ServiceProvider.GetRequiredService<UserManager<IdentityUser>>();
var alice = userMgr.FindByNameAsync("AliceSmith@email.example").Result;
if (alice == null)
{
alice = new IdentityUser
{
UserName = "AliceSmith@email.example",
Email = "AliceSmith@email.example",
EmailConfirmed = true,
LockoutEnabled = false
};
var result = userMgr.CreateAsync(alice, "Pass123$").Result;
if (!result.Succeeded)
{
throw new Exception(result.Errors.First().Description);
}

result = userMgr.AddClaimsAsync(alice, new Claim[]{
new Claim(JwtClaimTypes.Name, "Alice Smith"),
new Claim(JwtClaimTypes.GivenName, "Alice"),
new Claim(JwtClaimTypes.FamilyName, "Smith"),
new Claim(JwtClaimTypes.WebSite, "http://alice.example"),
}).Result;
if (!result.Succeeded)
{
throw new Exception(result.Errors.First().Description);
}
}

var bob = userMgr.FindByNameAsync("BobSmith@email.example").Result;
if (bob == null)
{
bob = new IdentityUser
{
UserName = "BobSmith@email.example",
Email = "BobSmith@email.example",
EmailConfirmed = true,
LockoutEnabled = false
};
var result = userMgr.CreateAsync(bob, "Pass123$").Result;
if (!result.Succeeded)
{
throw new Exception(result.Errors.First().Description);
}

result = userMgr.AddClaimsAsync(bob, new Claim[]{
new Claim(JwtClaimTypes.Name, "Bob Smith"),
new Claim(JwtClaimTypes.GivenName, "Bob"),
new Claim(JwtClaimTypes.FamilyName, "Smith"),
new Claim(JwtClaimTypes.WebSite, "http://bob.example"),
new Claim("location", "somewhere")
}).Result;
if (!result.Succeeded)
{
throw new Exception(result.Errors.First().Description);
}
}
}
}
}
Loading
Loading