public async Task <Client> FindClientByIdAsync(string clientId)
        {
            //  return GetClient(clientId);
            #region 用户名密码
            var memoryClients = ID4Config.GetClients();
            if (memoryClients.Any(oo => oo.ClientId == clientId))
            {
                return(memoryClients.FirstOrDefault(oo => oo.ClientId == clientId));
            }
            #endregion

            #region 通过数据库查询Client 信息
            return(GetClient(clientId));

            #endregion
        }
Exemple #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            var migrationsAssembly = "CommonScheme.IdentityAPI";
            //string connectionString = @"Data Source=ZYXTJSTD-WUTJ\MSSQLSERVER12;Initial Catalog=IdentityServerDB;Persist Security Info=True;User ID=sa;Password=wutengjian123";
            var connectionString = Configuration.GetConnectionString("UserCenterConnection");

            services.AddMvc();
            services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            // .AddConfigurationStore(options =>
            // {
            //     options.ConfigureDbContext = builder => builder.UseMySql(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly));
            //     //options.ConfigureDbContext = builder => builder.UseSqlServer(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly));
            // })
            //.AddOperationalStore(options =>
            //{
            //    options.ConfigureDbContext = builder => builder.UseMySql(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly));
            //    //options.ConfigureDbContext = builder => builder.UseSqlServer(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly));
            //    options.EnableTokenCleanup = true;
            //    options.TokenCleanupInterval = 300;
            //})
            #region 内存方式
            .AddInMemoryIdentityResources(ID4Config.GetIdentityResources())
            .AddInMemoryApiResources(ID4Config.GetApis())
            .AddInMemoryClients(ID4Config.GetClients())
            .AddTestUsers(ID4Config.GetUsers())
            #endregion

            #region 数据库存储方式
            //.AddClientStore<ClientStore>()
            //.AddResourceOwnerValidator<ResourceOwnerPasswordValidator>()//账户密码方式验证
            //.AddExtensionGrantValidator<WeiXinOpenGrantValidator>()//添加微信端自定义方式的验证
            ;
            #endregion
            // services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
        }