Example #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var appOption = new AppAuthOption()
            {
                AppProvider    = new AppAuthProvider(),
                TenantProvider = new TenantAuthProvider()
            };
            var moduleOption = new ModuleAuthOption()
            {
                ModuleProvider = new ModuleAuthProvider()
            };
            var userOption = new UserAuthOption()
            {
                UserProvider = new UserAuthProvider()
            };

            services.AddControllers(
                opt =>
            {
                opt.Filters.Add(new InitialContextAttribute());
                opt.Filters.Add(new AppAuthAttribute(appOption));
                opt.Filters.Add(new ModuleAuthAttribute(moduleOption));
                opt.Filters.Add(new UserAuthAttribute(userOption));
            })
            .AddJsonOptions(jsonOpt =>
            {
                jsonOpt.JsonSerializerOptions.IgnoreNullValues     = true;
                jsonOpt.JsonSerializerOptions.PropertyNamingPolicy = null;
            });
        }
Example #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var appOption = new AppAuthOption()
            {
                TenantProvider = new TenantAuthProvider()
            };
            var userOption = new UserAuthOption()
            {
                UserProvider = new AdminAuthProvider(),
                FuncProvider = new FuncAuthProvider()
            };

            // 因为需要全站校验是否登录,所以这里是全局处理
            // 否则接口Controller基类处理即可,所有ajax请求统一处理,授权登录跳转,纯页面元素本身无需校验
            services.AddControllers(opt =>
            {
                opt.Filters.Add(new AppAuthAttribute(appOption));
                opt.Filters.Add(new UserAuthAttribute(userOption));
            })
            .AddNewtonsoftJson(jsonOpt =>
            {
                jsonOpt.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
                jsonOpt.SerializerSettings.ContractResolver  = new DefaultContractResolver();
            });

            var builder = services.AddRazorPages();

#if DEBUG
            builder.AddRazorRuntimeCompilation(); //  调试状态下动态编译
#endif

            services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/antd_spa"; });
        }
Example #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHttpClient();

            var appOption = new AppAuthOption()
            {
                AppProvider = new AppAuthProvider(),
            };
            var userOption = new UserAuthOption()
            {
                UserProvider = new UserAuthProvider(),
                FuncProvider = new FuncAuthProvider()
            };

            services.AddControllers(opt =>
            {
                opt.Filters.Add(new AppAuthAttribute(appOption));
                opt.Filters.Add(new UserAuthAttribute(userOption));
            }).AddJsonOptions(jsonOpt =>
            {
                jsonOpt.JsonSerializerOptions.IgnoreNullValues     = true;
                jsonOpt.JsonSerializerOptions.PropertyNamingPolicy = null;
            });
        }
Example #4
0
        public static async Task <Resp> FormatAndCheck(HttpContext context, AppIdentity appInfo, AppAuthOption appOption)
        {
            // 第三方回调接口,直接放过
            if (appInfo.is_partner)
            {
                appInfo.is_partner = true;
                appInfo.app_client = AppClientType.Server;
                appInfo.app_type   = AppType.Outer;
                appInfo.UDID       = "WEB";

                return(new Resp());
            }

            Resp res;

            if (appOption.IsWebSite)
            {
                appInfo.app_ver = AppInfoHelper.AppVersion;
                appInfo.app_id  = AppInfoHelper.AppId;
                appInfo.UDID    = "WEB";

                appInfo.token = context.Request.Cookies[CookieKeys.UserCookieName];
                res           = new Resp();
            }
            else
            {
                string authTicketStr = context.Request.Headers[CookieKeys.AuthorizeTicketName];
                appInfo.FromTicket(authTicketStr);
                res = await CheckAppAuthIdentity(context, appOption.AppProvider, appInfo);
            }

            context.CompleteAppIdentity(appInfo);
            return(res);
        }
        public static async Task <Resp> FormatAndCheck(HttpContext context, AppIdentity appInfo, AppAuthOption appOption)
        {
            if (appInfo.is_partner || appOption.TenantProvider == null || TenantContext.Identity != null)
            {
                return(new Resp());
            }

            // 服务api请求时,必须有值
            if (!appOption.IsWebSite && string.IsNullOrEmpty(appInfo.tenant_id))
            {
                return(new Resp().WithResp(RespTypes.ObjectNull, "未发现租户信息!"));
            }

            var identityRes = await appOption.TenantProvider.InitialAuthTenantIdentity(context, appInfo);

            if (!identityRes.IsSuccess())
            {
                return(identityRes);
            }

            TenantContext.SetIdentity(identityRes.data);
            return(identityRes);
        }