Ejemplo n.º 1
0
        public async Task Invoke(HttpContext context)
        {
            if (MemberShiper.AppAuthorize != null)
            {
                await _next.Invoke(context);

                return;
            }

            SysAuthorizeInfo sysInfo = null;
            //  这里是为了兼容App嵌套h5页面,使用App的授权信息
            string auticketStr = context.Request.Headers[GlobalKeysUtil.AuthorizeTicketName];

            if (!string.IsNullOrEmpty(auticketStr))
            {
                sysInfo = new SysAuthorizeInfo();
                sysInfo.FromSignData(auticketStr);

                var secretKeyRes = ApiSourceKeyUtil.GetAppSecretKey(sysInfo.AppSource);

                if (!secretKeyRes.IsSuccess())
                {
                    await ResponseEnd(context, secretKeyRes);

                    return;
                }
                if (!sysInfo.CheckSign(secretKeyRes.data))
                {
                    await ResponseEnd(context, new ResultMo(ResultTypes.ParaError, "签名验证失败!"));

                    return;
                }
                sysInfo.OriginAppSource = sysInfo.AppSource;
            }

            //  如果不是App访问,添加Web相关系统信息
            if (sysInfo == null)
            {
                sysInfo = new SysAuthorizeInfo
                {
                    Token    = context.Request.Cookies[GlobalKeysUtil.UserCookieName],
                    DeviceId = "WEB"
                };

                // todo appclient
            }

            CompleteAuthInfo(sysInfo, context);
            MemberShiper.SetAppAuthrizeInfo(sysInfo);

            await _next.Invoke(context);
        }
Ejemplo n.º 2
0
        public async void TestRestCommonJson()
        {
            var req = new OsHttpRequest
            {
                AddressUrl = "http://localhost:62936",
                HttpMethod = HttpMethod.Get
            };

            MemberShiper.SetAppAuthrizeInfo(new AppAuthorizeInfo());
            var res = await req.RestCommonJson <ResultMo>();

            Assert.True(res.IsSuccess());
        }
Ejemplo n.º 3
0
        public async Task Invoke(HttpContext context)
        {
            if (MemberShiper.AppAuthorize != null)
            {
                await _next.Invoke(context);

                return;
            }

            AppAuthorizeInfo sysInfo = null;

            //  这里是为了兼容App内部嵌套h5页面,使用App的授权信息
            string auticketStr = context.Request.Headers[GlobalKeysUtil.AuthorizeTicketName];

            if (!string.IsNullOrEmpty(auticketStr))
            {
                sysInfo = new AppAuthorizeInfo();
                sysInfo.FromSignData(auticketStr);
            }

            //  如果不是App访问,添加Web相关系统信息
            if (sysInfo == null)
            {
                sysInfo = new AppAuthorizeInfo
                {
                    Token    = context.Request.Cookies[GlobalKeysUtil.UserCookieName],
                    DeviceId = "WEB"
                };
                // todo 给 webbrowser 赋值
            }

            sysInfo.AppVersion = _appVersion;
            sysInfo.AppSource  = _appSource;

            if (string.IsNullOrEmpty(sysInfo.IpAddress))
            {
                sysInfo.IpAddress = GetIpAddress(context);
            }

            MemberShiper.SetAppAuthrizeInfo(sysInfo);
            await _next.Invoke(context);
        }
Ejemplo n.º 4
0
        public async Task Invoke(HttpContext context)
        {
            if (MemberShiper.AppAuthorize != null)
            {
                await _next.Invoke(context);

                return;
            }

            SysAuthorizeInfo sysInfo = null;
            //  这里是为了兼容App嵌套h5页面,使用App的授权信息
            string auticketStr = context.Request.Headers[authorizeTicket];

            if (!string.IsNullOrEmpty(auticketStr))
            {
                sysInfo = new SysAuthorizeInfo();
                sysInfo.FromSignData(auticketStr);

                var secretKeyRes = ApiSourceKeyUtil.GetAppSecretKey(sysInfo.AppSource);
                if (!secretKeyRes.IsSuccess || !sysInfo.CheckSign(secretKeyRes.Data))
                {
                    context.Response.Redirect(string.Concat("/un/error?msg=", "不正确的应用来源!"));
                    return;
                }
                sysInfo.OriginAppSource = sysInfo.AppSource;
            }

            //  如果不是App访问,添加Web相关系统信息
            if (sysInfo == null)
            {
                sysInfo       = new SysAuthorizeInfo();
                sysInfo.Token = context.Request.Cookies["ct_id"];

                // todo appclient
                sysInfo.DeviceId = "WEB";
            }

            CompleteAuthInfo(sysInfo, context);
            MemberShiper.SetAppAuthrizeInfo(sysInfo);

            await _next.Invoke(context);
        }
Ejemplo n.º 5
0
        public async Task Invoke(HttpContext context)
        {
            string auticketStr = context.Request.Headers[GlobalKeysUtil.AuthorizeTicketName];

            if (string.IsNullOrEmpty(auticketStr))
            {
                await ResponseEnd(context, new ResultMo(ResultTypes.UnKnowSource, "未知应用来源"));

                return;
            }

            var sysInfo = new SysAuthorizeInfo();

            sysInfo.FromSignData(auticketStr);

            var secretKeyRes = ApiSourceKeyUtil.GetAppSecretKey(sysInfo.AppSource);

            if (!secretKeyRes.IsSuccess())
            {
                await ResponseEnd(context, secretKeyRes);

                return;
            }

            if (!sysInfo.CheckSign(secretKeyRes.data))
            {
                await ResponseEnd(context, new ResultMo(ResultTypes.ParaError, "非法应用签名!"));

                return;
            }

            if (string.IsNullOrEmpty(sysInfo.IpAddress))
            {
                sysInfo.IpAddress = GetIpAddress(context);
            }

            MemberShiper.SetAppAuthrizeInfo(sysInfo);

            await _next.Invoke(context);
        }
Ejemplo n.º 6
0
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            AppAuthorizeInfo sysInfo = null;
            var checkSign            = !context.Filters.Any(filter => filter is AllowNoSignAttribute);

            if (checkSign)
            {
                string auticketStr = context.HttpContext.Request.Headers[GlobalKeysUtil.AuthorizeTicketName];
                if (string.IsNullOrEmpty(auticketStr))
                {
                    context.Result = new JsonResult(new ResultMo(ResultTypes.UnKnowSource, "未知应用来源"));
                    return;
                }

                sysInfo = new AppAuthorizeInfo();
                sysInfo.FromTicket(auticketStr);

                var secretKeyRes = ApiSourceKeyUtil.GetAppSecretKey(sysInfo.AppSource, sysInfo.TenantId);
                if (!secretKeyRes.IsSuccess())
                {
                    context.Result = new JsonResult(secretKeyRes);
                    return;
                }

                if (!sysInfo.CheckSign(secretKeyRes.data))
                {
                    context.Result = new JsonResult(new ResultMo(ResultTypes.ParaError, "非法应用签名!"));
                    return;
                }
            }

            if (sysInfo == null)
            {
                sysInfo = new AppAuthorizeInfo();
            }

            SetSystemAuthorizeInfo(sysInfo, context);
            MemberShiper.SetAppAuthrizeInfo(sysInfo);
        }
Ejemplo n.º 7
0
        public async Task Invoke(HttpContext context)
        {
            string auticketStr = context.Request.Headers[authorizeTicket];

            if (auticketStr == null)
            {
                await ResponseEnd(context, new ResultMo(ResultTypes.UnKnowSource, "未知应用来源"));

                return;
            }

            var sysInfo = new SysAuthorizeInfo();

            sysInfo.FromSignData(auticketStr);

            var secretKeyRes = ApiSourceKeyUtil.GetAppSecretKey(sysInfo.AppSource);

            if (!secretKeyRes.IsSuccess)
            {
                await ResponseEnd(context, secretKeyRes);

                return;
            }

            if (!sysInfo.CheckSign(secretKeyRes.Data))
            {
                await ResponseEnd(context, new ResultMo(ResultTypes.ParaNotMeet, "非法应用签名!"));

                return;
            }

            CompleteAuthInfo(sysInfo, context);
            MemberShiper.SetAppAuthrizeInfo(sysInfo);

            await _next.Invoke(context);
        }