Skip to content

BoyceLyu/IdentityServer3.AspnetCore

Repository files navigation

#20|20 IdentityServer3.EntityFramework7

###Entity Framework 7 persistence layer for IdentityServer v3

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.AddEntityFramework()
		.AddSqlServer()
		.AddDbContext<ClientConfigurationContext>(o => o.UseSqlServer(connectionString))
		.AddDbContext<ScopeConfigurationContext>(o => o.UseSqlServer(connectionString))
		.AddDbContext<OperationalContext>(o => o.UseSqlServer(connectionString));
	...
}

Configure the IdentityServerServiceFactory to use the EF stores.

public void Configure(IApplicationBuilder app)
{
	...
	var factory = new IdentityServerServiceFactory();
	factory.ConfigureEntityFramework(app.ApplicationServices)
		.RegisterOperationalStores()
		.RegisterClientStore<Guid, ClientConfigurationContext>()
		.RegisterScopeStore<Guid, ScopeConfigurationContext>();

	owinAppBuilder.UseIdentityServer(new IdentityServerOptions
	{
		...
		Factory = factory,
		...
	});
	...
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages