Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/2020IP/TwentyTwenty.IdentityServer4.EntityFrameworkCore
https://github.com/2020IP/TwentyTwenty.IdentityServer4.EntityFrameworkCore
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/2020IP/TwentyTwenty.IdentityServer4.EntityFrameworkCore
- Owner: 2020IP
- License: other
- Archived: true
- Created: 2016-01-14T16:23:22.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-08-01T14:59:54.000Z (over 1 year ago)
- Last Synced: 2024-10-04T21:16:46.034Z (2 months ago)
- Language: C#
- Size: 107 KB
- Stars: 41
- Watchers: 16
- Forks: 12
- Open Issues: 4
-
Metadata Files:
- Readme: readme.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-dotnet-core - IdentityServer4.EntityFrameworkCore - Entity Framework Core persistence layer (Frameworks, Libraries and Tools / Authentication and Authorization)
- fucking-awesome-dotnet-core - IdentityServer4.EntityFrameworkCore - Entity Framework Core persistence layer (Frameworks, Libraries and Tools / Authentication and Authorization)
- awesome-dotnet-core - IdentityServer4.EntityFrameworkCore - Entity Framework Core persistence layer (Frameworks, Libraries and Tools / Authentication and Authorization)
- awesome-dotnet-core - IdentityServer4.EntityFrameworkCore - EF Core 的IdentityServer4库。 (框架, 库和工具 / 身份认证和授权)
README
# 20|20 IdentityServer4.EntityFrameworkCore
## Deprecated: This repository is no longer in active development or maintenance. Use the official library instead: [IdentityServer4.EntityFramework.Storage](https://github.com/IdentityServer/IdentityServer4.EntityFramework.Storage)
### Entity Framework Core persistence layer for [IdentityServer v4](https://github.com/IdentityServer/IdentityServer4)
[![NuGet](https://img.shields.io/nuget/v/TwentyTwenty.IdentityServer4.EntityFrameworkCore.svg)](https://www.nuget.org/packages/TwentyTwenty.IdentityServer4.EntityFrameworkCore/)*CI Nuget Feed*
https://ci.appveyor.com/nuget/twentytwenty-identityserver4-e-eghymilgfl2p### Usage
The primary key type can be configured for ClientStore and ScopeStore.
To facilitate this, when you Register your contexts make sure you use the correct key.If you have set it up like this you can use EntityFramework Migrations against a single context to build your DB
```
public class YourDataContext : IClientConfigurationContext, IScopeConfigurationContext, IOperationalContext
{
public YourDataContext(DbContextOptions options)
: base(options)
{ }public override void OnModelCreating(ModelBuilder modelBuilder)
{
...
modelBuilder.ConfigureClientConfigurationContext();
modelBuilder.ConfigureScopeConfigurationContext();
modelBuilder.ConfigureOperationalContext();
...
base.OnModelCreating(modelBuilder);
}
}
```
In the `Startup.cs`, register your DbContext with Entity Framework as normal
```
public void ConfigureServices(IServiceCollection services)
{
...
services.AddEntityFrameworkSqlServer()
.AddDbContext(o => o
.UseSqlServer(connectionString, b =>
b.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name)))
...
}
```
Register your datacontext(s) with the EFCore Contexts
```
public void ConfigureServices(IServiceCollection services)
{
...
var builder = services.AddIdentityServer(options =>
{
options.RequireSsl = false;
});builder.ConfigureEntityFramework()
.RegisterOperationalStores()
.RegisterClientStore()
.RegisterScopeStore();
...
}
```#### Old Usage
The primary key type can be configured for ClientStore and ScopeStore. To facilitate this, subclass the `ClientConfigurationContext` and `ScopeConfigurationContext` with the desired key type.
```
public class ClientConfigurationContext : ClientConfigurationContext
{
public ClientConfigurationContext(DbContextOptions options)
: base(options)
{ }
}public class ScopeConfigurationContext : ScopeConfigurationContext
{
public ScopeConfigurationContext(DbContextOptions options)
: base(options)
{ }
}
```
In order to enable extensibility of the `OperationalContext`, it must be subclassed. The main reason behind this is EFCore requires the `DbContextOptions` constructor to supply a type, which we cannot set to `OperationalContext` as it will not allow this class to be extensible.
```
public class OperationalContextEx : OperationalContext
{
public OperationalContextEx(DbContextOptions options)
: base(options)
{ }
}
```
In the `Startup.cs`, register your DbContexts with Entity Framework
```
public void ConfigureServices(IServiceCollection services)
{
...
services.AddEntityFrameworkSqlServer()
.AddDbContext(o => o
.UseSqlServer(connectionString, b =>
b.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name)))
.AddDbContext(o => o
.UseSqlServer(connectionString, b =>
b.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name)))
.AddDbContext(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()
.RegisterScopeStore();
...
}
```
#### Contributing
To get started, [sign the Contributor License Agreement](https://www.clahub.com/agreements/2020IP/TwentyTwenty.IdentityServer4.EntityFrameworkCore).