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
16 changes: 15 additions & 1 deletion Rsk.Samples.OpenIddict.AdminUI/Data/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
#nullable enable
using Microsoft.EntityFrameworkCore;

namespace Rsk.Samples.OpenIddict.AdminUiIntegration.Data;

public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : DbContext(options);
public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options, string? schema = null) : DbContext(options)
{
private string Schema { get; } = schema ?? string.Empty;

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
if (!string.IsNullOrEmpty(Schema))
{
modelBuilder.HasDefaultSchema(Schema);
}

base.OnModelCreating(modelBuilder);
}
}
6 changes: 4 additions & 2 deletions Rsk.Samples.OpenIddict.AdminUI/Data/IdentityDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#nullable enable
using System;
using IdentityExpress.Identity;
using Microsoft.EntityFrameworkCore;

namespace Rsk.Samples.OpenIddict.AdminUiIntegration.Data;

public class IdentityDbContext(DbContextOptions<IdentityDbContext> options)
: IdentityExpressDbContext<ApplicationUser>(options);
public class IdentityDbContext(DbContextOptions<IdentityDbContext> options, string? schema = null)
: IdentityExpressDbContext<ApplicationUser>(options, schema ?? String.Empty);
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<PackageReference Include="OpenIddict.Quartz" Version="6.1.1" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0-preview.3.efcore.9.0.0" />
<PackageReference Include="Quartz.Extensions.Hosting" Version="3.14.0" />
<PackageReference Include="IdentityExpress.Identity" Version="6.0.1" />
<PackageReference Include="IdentityExpress.Identity" Version="7.0.0" />
<PackageReference Include="Rsk.OpenIddict.Utils" Version="2.0.0" />
<PackageReference Include="Rsk.Saml.OpenIddict" Version="9.2.0" />
<PackageReference Include="Rsk.Saml.OpenIddict.AspNetCore.Identity" Version="9.2.0" />
Expand Down
27 changes: 23 additions & 4 deletions Rsk.Samples.OpenIddict.AdminUI/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@ public void ConfigureServices(IServiceCollection services)
services.AddControllersWithViews();
services.AddRazorPages();

var identitySchema = Configuration.GetValue<string>("IdentityStoreSchemaName");
services.AddDbContext<IdentityDbContext>(GetDbConnection);
services.AddScoped<IdentityDbContext>(serviceProvider =>
{
var options = serviceProvider
.GetRequiredService<DbContextOptions<IdentityDbContext>>();

return new IdentityDbContext(options, identitySchema);
});

var openIddictSchema = Configuration.GetValue<string>("OpenIddictStoreSchemaName");
services.AddDbContext<ApplicationDbContext>(options =>
{
GetDbConnection(options);
Expand All @@ -41,11 +51,20 @@ public void ConfigureServices(IServiceCollection services)
// to replace the default OpenIddict entities.
options.UseOpenIddict();
});
services.AddScoped<ApplicationDbContext>(serviceProvider =>
{
var options = serviceProvider
.GetRequiredService<DbContextOptions<ApplicationDbContext>>();

return new ApplicationDbContext(options, openIddictSchema);
});

services.AddDatabaseDeveloperPageExceptionFilter();


// Register the Identity services.
services.AddIdentity<ApplicationUser, IdentityExpressRole>()
services
.AddIdentity<ApplicationUser, IdentityExpressRole>()
.AddEntityFrameworkStores<IdentityDbContext>()
.AddDefaultTokenProviders();

Expand Down Expand Up @@ -117,9 +136,9 @@ public void ConfigureServices(IServiceCollection services)
options.AddSamlPlugin(builder =>
{
builder.UseSamlEntityFrameworkCore()
.AddSamlArtifactDbContext(GetDbConnection)
.AddSamlConfigurationDbContext(GetDbConnection)
.AddSamlMessageDbContext(GetDbConnection);
.AddSamlArtifactDbContext(GetDbConnection, openIddictSchema)
.AddSamlConfigurationDbContext(GetDbConnection, openIddictSchema)
.AddSamlMessageDbContext(GetDbConnection, openIddictSchema);

builder.ConfigureSamlOpenIddictServerOptions(serverOptions =>
{
Expand Down
4 changes: 3 additions & 1 deletion Rsk.Samples.OpenIddict.AdminUI/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"AllowedHosts": "*",
"DbProvider": "SqlServer",
"OpenIddictConnectionString": "Server=localhost;User Id=IISConnect;Password=Password123!;Database=OpenIddictDb;Encrypt=False",
"IdentityStoreSchemaName": "",
"OpenIddictStoreSchemaName": "",
"SAML2PLicensee": "DEMO",
"SAML2PLicense": "***YOUR LICENSE KEY***"
"SAML2PLicense": ""
}