IdentityServer4-参考


一、Identity Resource

二、API Resource

三、Client

四、GrantValidationResult

五、Profile Service

六、IdentityServer Interaction Service

七、IdentityServer Options

八、Entity Framework Support

九、ASP.NET Identity Support

一、Identity Resourcerepo位于这里,NuGet包在这里。

此库提供的功能分为两个主要区域:配置存储和操作存储支持。 根据托管应用程序的需要,这两个不同的区域可以独立使用或一起使用。

Configuration Store支持客户端,资源和CORS设置

如果希望从EF支持的数据库加载客户端,标识资源,API资源或CORS数据(而不是使用内存配置),则可以使用配置存储。 此支持提供IClientStore,IResourceStore和ICorsPolicyService可扩展性点的实现。 这些实现使用名为ConfigurationDbContext的DbContext派生类来对数据库中的表进行建模。

要使用配置存储支持,请在调用AddIdentityServer后使用AddConfigurationStore扩展方法:

public IServiceProvider ConfigureServices(IServiceCollection services)
{
    const string connectionString = @"Data Source=(LocalDb)\MSSQLLocalDB;database=IdentityServer4.EntityFramework-2.0.0;trusted_connection=yes;";
    var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

    services.AddIdentityServer()
        // this adds the config data from DB (clients, resources, CORS)
        .AddConfigurationStore(options =>
        {
            options.ConfigureDbContext = builder =>
                builder.UseSqlServer(connectionString,
                    sql => sql.MigrationsAssembly(migrationsAssembly));
        });
}

要配置配置存储,请使用传递给配置回调的ConfigurationStoreOptions选项对象。

ConfigurationStoreOptions

此选项类包含用于控制配置存储和ConfigurationDbContext的属性。

ConfigureDbContext

Action 类型的委托用作回调以配置基础ConfigurationDbContext。 如果EF直接与AddDbContext一起使用,则委托可以以相同的方式配置ConfigurationDbContext,这允许使用任何EF支持的数据库。

DefaultSchema

允许为ConfigurationDbContext中的所有表设置默认数据库模式名称。

Operational Store对授权授权,同意和令牌的支持(刷新和引用)

如果希望从EF支持的数据库(而不是默认的内存数据库)加载授权授予,同意和令牌(刷新和引用),则可以使用操作存储。 此支持提供IPersistedGrantStore扩展点的实现。 该实现使用名为PersistedGrantDbContext的DbContext派生类来对数据库中的表进行建模。

要使用操作存储支持,请在调用AddIdentityServer后使用AddOperationalStore扩展方法:

public IServiceProvider ConfigureServices(IServiceCollection services)
{
    const string connectionString = @"Data Source=(LocalDb)\MSSQLLocalDB;database=IdentityServer4.EntityFramework-2.0.0;trusted_connection=yes;";
    var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

    services.AddIdentityServer()
        // this adds the operational data from DB (codes, tokens, consents)
        .AddOperationalStore(options =>
        {
            options.ConfigureDbContext = builder =>
                builder.UseSqlServer(connectionString,
                    sql => sql.MigrationsAssembly(migrationsAssembly));

            // this enables automatic token cleanup. this is optional.
            options.EnableTokenCleanup = true;
            options.TokenCleanupInterval = 30; // interval in seconds
        });
}

要配置操作存储,请使用传递给配置回调的OperationalStoreOptions选项对象。

OperationalStoreOptions

此选项类包含用于控制操作存储和PersistedGrantDbContext的属性。

ConfigureDbContext

Action 类型的委托用作回调以配置基础PersistedGrantDbContext。 如果EF直接与AddDbContext一起使用,则委托可以以相同的方式配置PersistedGrantDbContext,这允许使用任何EF支持的数据库。

DefaultSchema

允许为PersistedGrantDbContext中的所有表设置默认数据库模式名称。

EnableTokenCleanup

指示是否将从数据库中自动清除过时条目。 默认值为false。

TokenCleanupInterval

令牌清理间隔(以秒为单位)。 默认值为3600(1小时)。

跨不同版本的IdentityServer数据库创建和模式更改

跨不同版本的IdentityServer(以及EF支持)很可能会更改数据库架构以适应新的和不断变化的功能。

我们不为创建数据库或将数据从一个版本迁移到另一个版本提供任何支持。 您需要以组织认为合适的任何方式管理数据库创建,架构更改和数据迁移。

使用EF迁移是一种可行的方法。 如果您确实希望使用迁移,请参阅EF快速入门以获取有关如何入门的示例,或参阅有关EF迁移的Microsoft文档。

我们还为当前版本的数据库模式发布了示例SQL脚本。

九、ASP.NET Identity Supporthttps://github.com/IdentityServer/IdentityServer4.AspNetIdentity/

要使用此库,请正常配置ASP.NET标识。 然后在调用AddIdentityServer之后使用AddAspNetIdentity扩展方法:

public void ConfigureServices(IServiceCollection services)
{
    services.AddIdentity()
        .AddEntityFrameworkStores()
        .AddDefaultTokenProviders();

    services.AddIdentityServer()
        .AddAspNetIdentity();
}

AddAspNetIdentity需要将用户建模为ASP.NET标识的类(以及传递给AddIdentity的同一个用于配置ASP.NET标识的类)作为通用参数。 这会将IdentityServer配置为使用IUserClaimsPrincipalFactory,IResourceOwnerPasswordValidator和IProfileService的ASP.NET Identity实现。 它还配置了一些用于IdentityServer的ASP.NET Identity选项(例如要使用的声明类型和身份验证cookie设置)。