コード例 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });
            #region 内存方式
            //services.AddIdentityServer()
            //    .AddDeveloperSigningCredential()
            //    .AddInMemoryApiResources(OAuthMemoryData.GetApiResources())
            //    .AddInMemoryClients(OAuthMemoryData.GetClients())
            //    .AddTestUsers(OAuthMemoryData.GetTestUsers());
            #endregion

            #region 数据库存储方式
            services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddInMemoryApiResources(OAuthMemoryData.GetApiResources())
            //.AddInMemoryClients(OAuthMemoryData.GetClients())
            .AddClientStore <ClientStore>()
            //.AddResourceOwnerValidator<ResourceOwnerPasswordValidator>()
            .AddResourceOwnerValidator <RoleTestResourceOwnerPasswordValidator>()
            .AddExtensionGrantValidator <ApiOpenGrantValidator>()
            .AddProfileService <UserProfileService>();   //添加微信端自定义方式的验证
            #endregion

            #region 单点登录方式 Demo

            #endregion
        }
コード例 #2
0
        public async Task <Client> FindClientByIdAsync(string clientId)
        {
            #region 用户名密码
            var memoryClients = OAuthMemoryData.GetClients();
            if (memoryClients.Any(oo => oo.ClientId == clientId))
            {
                return(memoryClients.FirstOrDefault(oo => oo.ClientId == clientId));
            }
            #endregion

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

            #endregion
        }