Skip to content

mma1979/TwentyTwenty.IdentityServer4.EntityFrameworkCore

 
 

Repository files navigation

#20|20 IdentityServer4.EntityFrameworkCore

###Entity Framework Core persistence layer for IdentityServer v4 Build status NuGet

Usage

The primary key type can be configured for ClientStore and ScopeStore. To facilitate this, subclass the ClientConfigurationContext<TKey> and ScopeConfigurationContext<TKey> with the desired key type.

public class ClientConfigurationContext : ClientConfigurationContext<Guid>
{
	public ClientConfigurationContext(DbContextOptions options)
		: base(options)
	{ }
}

public class ScopeConfigurationContext : ScopeConfigurationContext<Guid>
{
	public ScopeConfigurationContext(DbContextOptions options)
		: base(options)
	{ }
}

In the Startup.cs, register your DbContexts with Entity Framework

public void ConfigureServices(IServiceCollection services)
{
	...
	services.AddEntityFrameworkSqlServer()
		.AddDbContext<ClientConfigurationContext>(o => o
			.UseSqlServer(connectionString, b =>
			b.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name)))
		.AddDbContext<ScopeConfigurationContext>(o => o
			.UseSqlServer((connectionString, , b =>
			b.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name)))
		.AddDbContext<OperationalContextEx>(o => o
			.UseSqlServer((connectionString, , b =>
			b.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name)));
	...
}

Register the EFCore Contexts

public void ConfigureServices(IServiceCollection services)
{
	...
	var builder = services.AddIdentityServer(options =>
	{
		options.RequireSsl = false;
	});

	builder.ConfigureEntityFramework()
		.RegisterOperationalStores()
		.RegisterClientStore<Guid, ClientConfigurationContext>()
		.RegisterScopeStore<Guid, ScopeConfigurationContext<>();
	...
}

Contributing

To get started, sign the Contributor License Agreement.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 93.7%
  • PowerShell 2.6%
  • Shell 1.7%
  • JavaScript 1.6%
  • Batchfile 0.4%