diff --git a/src/IdentitySvc/Data/Migrations/20240123193529_Users.Designer.cs b/src/IdentitySvc/Data/Migrations/20250525164319_InitialCreate.Designer.cs similarity index 75% rename from src/IdentitySvc/Data/Migrations/20240123193529_Users.Designer.cs rename to src/IdentitySvc/Data/Migrations/20250525164319_InitialCreate.Designer.cs index 2188b5a..c3773e2 100644 --- a/src/IdentitySvc/Data/Migrations/20240123193529_Users.Designer.cs +++ b/src/IdentitySvc/Data/Migrations/20250525164319_InitialCreate.Designer.cs @@ -5,72 +5,77 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace IdentitySvc.Data.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20240123193529_Users")] - partial class Users + [Migration("20250525164319_InitialCreate")] + partial class InitialCreate { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "8.0.0"); + modelBuilder + .HasAnnotation("ProductVersion", "8.0.11") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); modelBuilder.Entity("IdentitySvc.Models.ApplicationUser", b => { b.Property("Id") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("AccessFailedCount") - .HasColumnType("INTEGER"); + .HasColumnType("integer"); b.Property("ConcurrencyStamp") .IsConcurrencyToken() - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Email") .HasMaxLength(256) - .HasColumnType("TEXT"); + .HasColumnType("character varying(256)"); b.Property("EmailConfirmed") - .HasColumnType("INTEGER"); + .HasColumnType("boolean"); b.Property("LockoutEnabled") - .HasColumnType("INTEGER"); + .HasColumnType("boolean"); b.Property("LockoutEnd") - .HasColumnType("TEXT"); + .HasColumnType("timestamp with time zone"); b.Property("NormalizedEmail") .HasMaxLength(256) - .HasColumnType("TEXT"); + .HasColumnType("character varying(256)"); b.Property("NormalizedUserName") .HasMaxLength(256) - .HasColumnType("TEXT"); + .HasColumnType("character varying(256)"); b.Property("PasswordHash") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("PhoneNumber") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("PhoneNumberConfirmed") - .HasColumnType("INTEGER"); + .HasColumnType("boolean"); b.Property("SecurityStamp") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("TwoFactorEnabled") - .HasColumnType("INTEGER"); + .HasColumnType("boolean"); b.Property("UserName") .HasMaxLength(256) - .HasColumnType("TEXT"); + .HasColumnType("character varying(256)"); b.HasKey("Id"); @@ -87,19 +92,19 @@ namespace IdentitySvc.Data.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => { b.Property("Id") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("ConcurrencyStamp") .IsConcurrencyToken() - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Name") .HasMaxLength(256) - .HasColumnType("TEXT"); + .HasColumnType("character varying(256)"); b.Property("NormalizedName") .HasMaxLength(256) - .HasColumnType("TEXT"); + .HasColumnType("character varying(256)"); b.HasKey("Id"); @@ -114,17 +119,19 @@ namespace IdentitySvc.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("ClaimType") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("ClaimValue") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("RoleId") .IsRequired() - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("Id"); @@ -137,17 +144,19 @@ namespace IdentitySvc.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("ClaimType") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("ClaimValue") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("UserId") .IsRequired() - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("Id"); @@ -159,17 +168,17 @@ namespace IdentitySvc.Data.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.Property("LoginProvider") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("ProviderKey") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("ProviderDisplayName") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("UserId") .IsRequired() - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("LoginProvider", "ProviderKey"); @@ -181,10 +190,10 @@ namespace IdentitySvc.Data.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => { b.Property("UserId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("RoleId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("UserId", "RoleId"); @@ -196,16 +205,16 @@ namespace IdentitySvc.Data.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => { b.Property("UserId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("LoginProvider") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Name") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Value") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("UserId", "LoginProvider", "Name"); diff --git a/src/IdentitySvc/Data/Migrations/20240123193529_Users.cs b/src/IdentitySvc/Data/Migrations/20250525164319_InitialCreate.cs similarity index 73% rename from src/IdentitySvc/Data/Migrations/20240123193529_Users.cs rename to src/IdentitySvc/Data/Migrations/20250525164319_InitialCreate.cs index 2c117d9..c798a2b 100644 --- a/src/IdentitySvc/Data/Migrations/20240123193529_Users.cs +++ b/src/IdentitySvc/Data/Migrations/20250525164319_InitialCreate.cs @@ -1,12 +1,13 @@ using System; using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace IdentitySvc.Data.Migrations { /// - public partial class Users : Migration + public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -15,10 +16,10 @@ namespace IdentitySvc.Data.Migrations name: "AspNetRoles", columns: table => new { - Id = table.Column(type: "TEXT", nullable: false), - Name = table.Column(type: "TEXT", maxLength: 256, nullable: true), - NormalizedName = table.Column(type: "TEXT", maxLength: 256, nullable: true), - ConcurrencyStamp = table.Column(type: "TEXT", nullable: true) + Id = table.Column(type: "text", nullable: false), + Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + NormalizedName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + ConcurrencyStamp = table.Column(type: "text", nullable: true) }, constraints: table => { @@ -29,21 +30,21 @@ namespace IdentitySvc.Data.Migrations name: "AspNetUsers", columns: table => new { - Id = table.Column(type: "TEXT", nullable: false), - UserName = table.Column(type: "TEXT", maxLength: 256, nullable: true), - NormalizedUserName = table.Column(type: "TEXT", maxLength: 256, nullable: true), - Email = table.Column(type: "TEXT", maxLength: 256, nullable: true), - NormalizedEmail = table.Column(type: "TEXT", maxLength: 256, nullable: true), - EmailConfirmed = table.Column(type: "INTEGER", nullable: false), - PasswordHash = table.Column(type: "TEXT", nullable: true), - SecurityStamp = table.Column(type: "TEXT", nullable: true), - ConcurrencyStamp = table.Column(type: "TEXT", nullable: true), - PhoneNumber = table.Column(type: "TEXT", nullable: true), - PhoneNumberConfirmed = table.Column(type: "INTEGER", nullable: false), - TwoFactorEnabled = table.Column(type: "INTEGER", nullable: false), - LockoutEnd = table.Column(type: "TEXT", nullable: true), - LockoutEnabled = table.Column(type: "INTEGER", nullable: false), - AccessFailedCount = table.Column(type: "INTEGER", nullable: false) + Id = table.Column(type: "text", nullable: false), + UserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + NormalizedUserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + Email = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + NormalizedEmail = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + EmailConfirmed = table.Column(type: "boolean", nullable: false), + PasswordHash = table.Column(type: "text", nullable: true), + SecurityStamp = table.Column(type: "text", nullable: true), + ConcurrencyStamp = table.Column(type: "text", nullable: true), + PhoneNumber = table.Column(type: "text", nullable: true), + PhoneNumberConfirmed = table.Column(type: "boolean", nullable: false), + TwoFactorEnabled = table.Column(type: "boolean", nullable: false), + LockoutEnd = table.Column(type: "timestamp with time zone", nullable: true), + LockoutEnabled = table.Column(type: "boolean", nullable: false), + AccessFailedCount = table.Column(type: "integer", nullable: false) }, constraints: table => { @@ -54,11 +55,11 @@ namespace IdentitySvc.Data.Migrations name: "AspNetRoleClaims", columns: table => new { - Id = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - RoleId = table.Column(type: "TEXT", nullable: false), - ClaimType = table.Column(type: "TEXT", nullable: true), - ClaimValue = table.Column(type: "TEXT", nullable: true) + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + RoleId = table.Column(type: "text", nullable: false), + ClaimType = table.Column(type: "text", nullable: true), + ClaimValue = table.Column(type: "text", nullable: true) }, constraints: table => { @@ -75,11 +76,11 @@ namespace IdentitySvc.Data.Migrations name: "AspNetUserClaims", columns: table => new { - Id = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - UserId = table.Column(type: "TEXT", nullable: false), - ClaimType = table.Column(type: "TEXT", nullable: true), - ClaimValue = table.Column(type: "TEXT", nullable: true) + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + UserId = table.Column(type: "text", nullable: false), + ClaimType = table.Column(type: "text", nullable: true), + ClaimValue = table.Column(type: "text", nullable: true) }, constraints: table => { @@ -96,10 +97,10 @@ namespace IdentitySvc.Data.Migrations name: "AspNetUserLogins", columns: table => new { - LoginProvider = table.Column(type: "TEXT", nullable: false), - ProviderKey = table.Column(type: "TEXT", nullable: false), - ProviderDisplayName = table.Column(type: "TEXT", nullable: true), - UserId = table.Column(type: "TEXT", nullable: false) + LoginProvider = table.Column(type: "text", nullable: false), + ProviderKey = table.Column(type: "text", nullable: false), + ProviderDisplayName = table.Column(type: "text", nullable: true), + UserId = table.Column(type: "text", nullable: false) }, constraints: table => { @@ -116,8 +117,8 @@ namespace IdentitySvc.Data.Migrations name: "AspNetUserRoles", columns: table => new { - UserId = table.Column(type: "TEXT", nullable: false), - RoleId = table.Column(type: "TEXT", nullable: false) + UserId = table.Column(type: "text", nullable: false), + RoleId = table.Column(type: "text", nullable: false) }, constraints: table => { @@ -140,10 +141,10 @@ namespace IdentitySvc.Data.Migrations name: "AspNetUserTokens", columns: table => new { - UserId = table.Column(type: "TEXT", nullable: false), - LoginProvider = table.Column(type: "TEXT", nullable: false), - Name = table.Column(type: "TEXT", nullable: false), - Value = table.Column(type: "TEXT", nullable: true) + UserId = table.Column(type: "text", nullable: false), + LoginProvider = table.Column(type: "text", nullable: false), + Name = table.Column(type: "text", nullable: false), + Value = table.Column(type: "text", nullable: true) }, constraints: table => { diff --git a/src/IdentitySvc/Data/Migrations/ApplicationDbContextModelSnapshot.cs b/src/IdentitySvc/Data/Migrations/ApplicationDbContextModelSnapshot.cs index 295f312..36b150c 100644 --- a/src/IdentitySvc/Data/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/src/IdentitySvc/Data/Migrations/ApplicationDbContextModelSnapshot.cs @@ -4,6 +4,7 @@ using IdentitySvc.Data; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable @@ -15,59 +16,63 @@ namespace IdentitySvc.Data.Migrations protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "8.0.0"); + modelBuilder + .HasAnnotation("ProductVersion", "8.0.11") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); modelBuilder.Entity("IdentitySvc.Models.ApplicationUser", b => { b.Property("Id") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("AccessFailedCount") - .HasColumnType("INTEGER"); + .HasColumnType("integer"); b.Property("ConcurrencyStamp") .IsConcurrencyToken() - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Email") .HasMaxLength(256) - .HasColumnType("TEXT"); + .HasColumnType("character varying(256)"); b.Property("EmailConfirmed") - .HasColumnType("INTEGER"); + .HasColumnType("boolean"); b.Property("LockoutEnabled") - .HasColumnType("INTEGER"); + .HasColumnType("boolean"); b.Property("LockoutEnd") - .HasColumnType("TEXT"); + .HasColumnType("timestamp with time zone"); b.Property("NormalizedEmail") .HasMaxLength(256) - .HasColumnType("TEXT"); + .HasColumnType("character varying(256)"); b.Property("NormalizedUserName") .HasMaxLength(256) - .HasColumnType("TEXT"); + .HasColumnType("character varying(256)"); b.Property("PasswordHash") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("PhoneNumber") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("PhoneNumberConfirmed") - .HasColumnType("INTEGER"); + .HasColumnType("boolean"); b.Property("SecurityStamp") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("TwoFactorEnabled") - .HasColumnType("INTEGER"); + .HasColumnType("boolean"); b.Property("UserName") .HasMaxLength(256) - .HasColumnType("TEXT"); + .HasColumnType("character varying(256)"); b.HasKey("Id"); @@ -84,19 +89,19 @@ namespace IdentitySvc.Data.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => { b.Property("Id") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("ConcurrencyStamp") .IsConcurrencyToken() - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Name") .HasMaxLength(256) - .HasColumnType("TEXT"); + .HasColumnType("character varying(256)"); b.Property("NormalizedName") .HasMaxLength(256) - .HasColumnType("TEXT"); + .HasColumnType("character varying(256)"); b.HasKey("Id"); @@ -111,17 +116,19 @@ namespace IdentitySvc.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("ClaimType") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("ClaimValue") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("RoleId") .IsRequired() - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("Id"); @@ -134,17 +141,19 @@ namespace IdentitySvc.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("ClaimType") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("ClaimValue") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("UserId") .IsRequired() - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("Id"); @@ -156,17 +165,17 @@ namespace IdentitySvc.Data.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.Property("LoginProvider") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("ProviderKey") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("ProviderDisplayName") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("UserId") .IsRequired() - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("LoginProvider", "ProviderKey"); @@ -178,10 +187,10 @@ namespace IdentitySvc.Data.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => { b.Property("UserId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("RoleId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("UserId", "RoleId"); @@ -193,16 +202,16 @@ namespace IdentitySvc.Data.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => { b.Property("UserId") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("LoginProvider") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Name") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.Property("Value") - .HasColumnType("TEXT"); + .HasColumnType("text"); b.HasKey("UserId", "LoginProvider", "Name"); diff --git a/src/IdentitySvc/HostingExtensions.cs b/src/IdentitySvc/HostingExtensions.cs index 881e0e2..b197ca4 100644 --- a/src/IdentitySvc/HostingExtensions.cs +++ b/src/IdentitySvc/HostingExtensions.cs @@ -14,7 +14,7 @@ internal static class HostingExtensions builder.Services.AddRazorPages(); builder.Services.AddDbContext(options => - options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection"))); + options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"))); builder.Services.AddIdentity() .AddEntityFrameworkStores() @@ -29,24 +29,19 @@ internal static class HostingExtensions options.Events.RaiseSuccessEvents = true; // see https://docs.duendesoftware.com/identityserver/v6/fundamentals/resources/ - options.EmitStaticAudienceClaim = true; + // options.EmitStaticAudienceClaim = true; }) .AddInMemoryIdentityResources(Config.IdentityResources) .AddInMemoryApiScopes(Config.ApiScopes) .AddInMemoryClients(Config.Clients) .AddAspNetIdentity(); - - builder.Services.AddAuthentication() - .AddGoogle(options => - { - options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme; - // register your IdentityServer with Google at https://console.developers.google.com - // enable the Google+ API - // set the redirect URI to https://localhost:5001/signin-google - options.ClientId = "copy client ID from Google here"; - options.ClientSecret = "copy client secret from Google here"; - }); + builder.Services.ConfigureApplicationCookie(options => + { + options.Cookie.SameSite = SameSiteMode.Lax; + }); + + builder.Services.AddAuthentication(); return builder.Build(); } diff --git a/src/IdentitySvc/IdentitySvc.csproj b/src/IdentitySvc/IdentitySvc.csproj index 1b7d3dd..1473669 100644 --- a/src/IdentitySvc/IdentitySvc.csproj +++ b/src/IdentitySvc/IdentitySvc.csproj @@ -10,12 +10,13 @@ + + - \ No newline at end of file diff --git a/src/IdentitySvc/Program.cs b/src/IdentitySvc/Program.cs index f7e259c..e71c64e 100644 --- a/src/IdentitySvc/Program.cs +++ b/src/IdentitySvc/Program.cs @@ -22,13 +22,7 @@ try // this seeding is only for the template to bootstrap the DB and users. // in production you will likely want a different approach. - if (args.Contains("/seed")) - { - Log.Information("Seeding database..."); - SeedData.EnsureSeedData(app); - Log.Information("Done seeding database. Exiting."); - return; - } + SeedData.EnsureSeedData(app); app.Run(); } diff --git a/src/IdentitySvc/Properties/launchSettings.json b/src/IdentitySvc/Properties/launchSettings.json index 6f874f1..bc14166 100644 --- a/src/IdentitySvc/Properties/launchSettings.json +++ b/src/IdentitySvc/Properties/launchSettings.json @@ -6,7 +6,7 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, - "applicationUrl": "https://localhost:5001" + "applicationUrl": "http://localhost:5001" } } } \ No newline at end of file diff --git a/src/IdentitySvc/SeedData.cs b/src/IdentitySvc/SeedData.cs index f9a24b2..a4a9403 100644 --- a/src/IdentitySvc/SeedData.cs +++ b/src/IdentitySvc/SeedData.cs @@ -12,76 +12,70 @@ public class SeedData { public static void EnsureSeedData(WebApplication app) { - using (var scope = app.Services.GetRequiredService().CreateScope()) - { - var context = scope.ServiceProvider.GetRequiredService(); - context.Database.Migrate(); + using var scope = app.Services.GetRequiredService().CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + context.Database.Migrate(); - var userMgr = scope.ServiceProvider.GetRequiredService>(); - var alice = userMgr.FindByNameAsync("alice").Result; - if (alice == null) - { - alice = new ApplicationUser - { - UserName = "alice", - Email = "AliceSmith@email.com", - EmailConfirmed = true, - }; - var result = userMgr.CreateAsync(alice, "Pass123$").Result; - if (!result.Succeeded) - { - throw new Exception(result.Errors.First().Description); - } + var userMgr = scope.ServiceProvider.GetRequiredService>(); - 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.com"), - }).Result; - if (!result.Succeeded) - { - throw new Exception(result.Errors.First().Description); - } - Log.Debug("alice created"); - } - else + if (userMgr.Users.Any()) return; + + var alice = userMgr.FindByNameAsync("alice").Result; + if (alice == null) + { + alice = new ApplicationUser { - Log.Debug("alice already exists"); + UserName = "alice", + Email = "AliceSmith@email.com", + EmailConfirmed = true, + }; + var result = userMgr.CreateAsync(alice, "Pass123$").Result; + if (!result.Succeeded) + { + throw new Exception(result.Errors.First().Description); } - var bob = userMgr.FindByNameAsync("bob").Result; - if (bob == null) + result = userMgr.AddClaimsAsync(alice, new Claim[]{ + new Claim(JwtClaimTypes.Name, "Alice Smith"), + }).Result; + if (!result.Succeeded) { - bob = new ApplicationUser - { - UserName = "bob", - Email = "BobSmith@email.com", - EmailConfirmed = true - }; - var result = userMgr.CreateAsync(bob, "Pass123$").Result; - if (!result.Succeeded) - { - throw new Exception(result.Errors.First().Description); - } + throw new Exception(result.Errors.First().Description); + } + Log.Debug("alice created"); + } + else + { + Log.Debug("alice already exists"); + } - 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.com"), - new Claim("location", "somewhere") - }).Result; - if (!result.Succeeded) - { - throw new Exception(result.Errors.First().Description); - } - Log.Debug("bob created"); + var bob = userMgr.FindByNameAsync("bob").Result; + if (bob == null) + { + bob = new ApplicationUser + { + UserName = "bob", + Email = "BobSmith@email.com", + EmailConfirmed = true + }; + var result = userMgr.CreateAsync(bob, "Pass123$").Result; + if (!result.Succeeded) + { + throw new Exception(result.Errors.First().Description); } - else + + result = userMgr.AddClaimsAsync(bob, new Claim[]{ + new Claim(JwtClaimTypes.Name, "Bob Smith"), + }).Result; + if (!result.Succeeded) { - Log.Debug("bob already exists"); + throw new Exception(result.Errors.First().Description); } + Log.Debug("bob created"); + } + else + { + Log.Debug("bob already exists"); } } } diff --git a/src/IdentitySvc/keys/is-signing-key-77EB8A5360F8A1CEBDE8A5C6954780A5.json b/src/IdentitySvc/keys/is-signing-key-77EB8A5360F8A1CEBDE8A5C6954780A5.json new file mode 100644 index 0000000..672d431 --- /dev/null +++ b/src/IdentitySvc/keys/is-signing-key-77EB8A5360F8A1CEBDE8A5C6954780A5.json @@ -0,0 +1 @@ +{"Version":1,"Id":"77EB8A5360F8A1CEBDE8A5C6954780A5","Created":"2025-05-25T15:12:00.8996178Z","Algorithm":"RS256","IsX509Certificate":false,"Data":"CfDJ8BIJalz9mTlNqljDUzwnDk0ARrMXC6Z0QHpR_RqrdI-s1X8AxnD86UJmmJrnZRBXC0-q1fGrU2GMD1bEaR0_EnEw4GU5_fX9B1EVWs5OgQNXazOxkkCj5rnCcJmu779FXuoKbCn95KHCljQFxcAClWlRL4-7ufG5YYn3ka_3He3cHZDEt8Kh2inMFZq2jWjoxi3F668ApZQty2RmEDulv512LYH0NlKXSYgGlb6GtAHzngGjiUTIjwhKtcZ8BhgMzurm-9AZ4zLOcnnrrkA4yPgyL9omiHrkrjgbttmq107N_RsIhV9xfe5g3NqckIhRvWCPbqfzvmtiKWrkgzQJSFr73I5bYH_-9Lf10k7Jd-XMrAuf2Yts8WUNxUVw9Bv_0uSOAgMdAH0gExBKw2WxXBzc71gFUly4_THC8Od5J6CoyQIGdsS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