Ejemplo n.º 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>()
            .AddExtensionGrantValidator <WeiXinOpenGrantValidator>();   //添加微信端自定义方式的验证
            #endregion

            #region 单点登录方式 Demo

            #endregion
        }
Ejemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            #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>();
            #endregion

            #region 单点登录方式 Demo

            #endregion
        }
Ejemplo n.º 3
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
        }
Ejemplo n.º 4
0
#pragma warning disable CS1998 // 此异步方法缺少 "await" 运算符,将以同步方式运行。请考虑使用 "await" 运算符等待非阻止的 API 调用,或者使用 "await Task.Run(...)" 在后台线程上执行占用大量 CPU 的工作。
        public async Task <Client> FindClientByIdAsync(string clientId)
#pragma warning restore CS1998 // 此异步方法缺少 "await" 运算符,将以同步方式运行。请考虑使用 "await" 运算符等待非阻止的 API 调用,或者使用 "await Task.Run(...)" 在后台线程上执行占用大量 CPU 的工作。
        {
            #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
        }