{"id":13429850,"url":"https://github.com/2020IP/TwentyTwenty.IdentityServer4.EntityFrameworkCore","last_synced_at":"2025-03-16T04:31:12.672Z","repository":{"id":144172696,"uuid":"49659280","full_name":"2020IP/TwentyTwenty.IdentityServer4.EntityFrameworkCore","owner":"2020IP","description":null,"archived":true,"fork":false,"pushed_at":"2023-08-01T14:59:54.000Z","size":110,"stargazers_count":41,"open_issues_count":4,"forks_count":13,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-03-06T09:57:23.660Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/2020IP.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-01-14T16:23:22.000Z","updated_at":"2024-04-07T11:36:56.000Z","dependencies_parsed_at":"2024-01-02T22:44:01.974Z","dependency_job_id":"5b754a15-ccf9-4a96-a87b-2c33e016899b","html_url":"https://github.com/2020IP/TwentyTwenty.IdentityServer4.EntityFrameworkCore","commit_stats":null,"previous_names":["2020ip/twentytwenty.identityserver4.entityframework7"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2020IP%2FTwentyTwenty.IdentityServer4.EntityFrameworkCore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2020IP%2FTwentyTwenty.IdentityServer4.EntityFrameworkCore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2020IP%2FTwentyTwenty.IdentityServer4.EntityFrameworkCore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2020IP%2FTwentyTwenty.IdentityServer4.EntityFrameworkCore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2020IP","download_url":"https://codeload.github.com/2020IP/TwentyTwenty.IdentityServer4.EntityFrameworkCore/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243826788,"owners_count":20354220,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T02:00:46.595Z","updated_at":"2025-03-16T04:31:12.262Z","avatar_url":"https://github.com/2020IP.png","language":"C#","funding_links":[],"categories":["Frameworks, Libraries and Tools","框架, 库和工具","Authentication and Authorization"],"sub_categories":["Authentication and Authorization","身份认证和授权"],"readme":"# 20|20 IdentityServer4.EntityFrameworkCore\n\n## 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)\n\n\n### Entity Framework Core persistence layer for [IdentityServer v4](https://github.com/IdentityServer/IdentityServer4)\n[![NuGet](https://img.shields.io/nuget/v/TwentyTwenty.IdentityServer4.EntityFrameworkCore.svg)](https://www.nuget.org/packages/TwentyTwenty.IdentityServer4.EntityFrameworkCore/)\n\n*CI Nuget Feed*\nhttps://ci.appveyor.com/nuget/twentytwenty-identityserver4-e-eghymilgfl2p\n\n### Usage\nThe primary key type can be configured for ClientStore and ScopeStore.\nTo facilitate this, when you Register your contexts make sure you use the correct key.\n\nIf you have set it up like this you can use EntityFramework Migrations against a single context to build your DB\n\n```\npublic class YourDataContext : IClientConfigurationContext\u003cGuid\u003e, IScopeConfigurationContext\u003cGuid\u003e, IOperationalContext\n{\n\tpublic YourDataContext(DbContextOptions\u003cYourDataContext\u003e options)\n\t\t: base(options)\n\t{ }\n\n\tpublic override void OnModelCreating(ModelBuilder modelBuilder)\n\t{\n\t\t...\n\t\tmodelBuilder.ConfigureClientConfigurationContext\u003cGuid\u003e();\n\t\tmodelBuilder.ConfigureScopeConfigurationContext\u003cGuid\u003e();\n\t\tmodelBuilder.ConfigureOperationalContext();\n\t\t...\n\t\tbase.OnModelCreating(modelBuilder);\n\t}\n}\n```\nIn the `Startup.cs`, register your DbContext with Entity Framework as normal\n```\npublic void ConfigureServices(IServiceCollection services)\n{\n\t...\n\tservices.AddEntityFrameworkSqlServer()\n\t\t.AddDbContext\u003cYourDatabaseContext\u003e(o =\u003e o\n\t\t\t.UseSqlServer(connectionString, b =\u003e\n\t\t\tb.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name)))\n\t...\n}\n```\nRegister your datacontext(s) with the EFCore Contexts\n```\npublic void ConfigureServices(IServiceCollection services)\n{\n\t...\n\tvar builder = services.AddIdentityServer(options =\u003e\n\t{\n\t\toptions.RequireSsl = false;\n\t});\n\n\tbuilder.ConfigureEntityFramework()\n\t\t.RegisterOperationalStores\u003cYourDataContext\u003e()\n\t\t.RegisterClientStore\u003cGuid, YourDataContext\u003e()\n\t\t.RegisterScopeStore\u003cGuid, YourDataContext\u003e();\n\t...\n}\n```\n\n#### Old Usage\nThe primary key type can be configured for ClientStore and ScopeStore.  To facilitate this, subclass the `ClientConfigurationContext\u003cTKey\u003e` and `ScopeConfigurationContext\u003cTKey\u003e` with the desired key type.\n```\npublic class ClientConfigurationContext : ClientConfigurationContext\u003cGuid\u003e\n{\n\tpublic ClientConfigurationContext(DbContextOptions\u003cClientConfigurationContext\u003e options)\n\t\t: base(options)\n\t{ }\n}\n\npublic class ScopeConfigurationContext : ScopeConfigurationContext\u003cGuid\u003e\n{\n\tpublic ScopeConfigurationContext(DbContextOptions\u003cScopeConfigurationContext\u003e options)\n\t\t: base(options)\n\t{ }\n}\n```\nIn 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.\n```\npublic class OperationalContextEx : OperationalContext\n{\n\tpublic OperationalContextEx(DbContextOptions\u003cOperationalContextEx\u003e options)\n\t\t: base(options)\n\t{ }\n}\n```\nIn the `Startup.cs`, register your DbContexts with Entity Framework\n```\npublic void ConfigureServices(IServiceCollection services)\n{\n\t...\n\tservices.AddEntityFrameworkSqlServer()\n\t\t.AddDbContext\u003cClientConfigurationContext\u003e(o =\u003e o\n\t\t\t.UseSqlServer(connectionString, b =\u003e\n\t\t\tb.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name)))\n\t\t.AddDbContext\u003cScopeConfigurationContext\u003e(o =\u003e o\n\t\t\t.UseSqlServer(connectionString, b =\u003e\n\t\t\tb.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name)))\n\t\t.AddDbContext\u003cOperationalContext\u003e(o =\u003e o\n\t\t\t.UseSqlServer(connectionString, b =\u003e\n\t\t\tb.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name)));\n\t...\n}\n```\nRegister the EFCore Contexts\n```\npublic void ConfigureServices(IServiceCollection services)\n{\n\t...\n\tvar builder = services.AddIdentityServer(options =\u003e\n\t{\n\t\toptions.RequireSsl = false;\n\t});\n\n\tbuilder.ConfigureEntityFramework()\n\t\t.RegisterOperationalStores()\n\t\t.RegisterClientStore\u003cGuid, ClientConfigurationContext\u003e()\n\t\t.RegisterScopeStore\u003cGuid, ScopeConfigurationContext\u003e();\n\t...\n}\n```\n#### Contributing\nTo get started, [sign the Contributor License Agreement](https://www.clahub.com/agreements/2020IP/TwentyTwenty.IdentityServer4.EntityFrameworkCore).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2020IP%2FTwentyTwenty.IdentityServer4.EntityFrameworkCore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F2020IP%2FTwentyTwenty.IdentityServer4.EntityFrameworkCore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2020IP%2FTwentyTwenty.IdentityServer4.EntityFrameworkCore/lists"}