Ejemplo n.º 1
0
 /// <summary>
 ///   完善授权信息
 /// </summary>
 /// <param name="sysInfo"></param>
 /// <param name="context"></param>
 private static void CompleteAuthInfo(SysAuthorizeInfo sysInfo, HttpContext context)
 {
     if (string.IsNullOrEmpty(sysInfo.IpAddress))
     {
         sysInfo.IpAddress = GetIpAddress(context);
     }
     //  todo  applcient , webbrowser
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 校验数据签名
 /// </summary>
 /// <param name="value"></param>
 /// <param name="appInfo"></param>
 /// <returns></returns>
 public static bool CheckSignData(this string value, SysAuthorizeInfo appInfo)
 {
     if (appInfo != null)
     {
         return(appInfo.CheckSign(value));
     }
     return(false);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 转换为签名字符串
 /// </summary>
 /// <param name="value"></param>
 /// <param name="appInfo"></param>
 /// <returns></returns>
 public static string ToSignString(this string value, SysAuthorizeInfo appInfo)
 {
     if (appInfo != null)
     {
         return(appInfo.ToSignData(value));
     }
     return(value);
 }
Ejemplo n.º 4
0
        public void TestMethod1()
        {
            string key = Guid.NewGuid().ToString().Replace("-",string.Empty);
            SysAuthorizeInfo appInfo = new SysAuthorizeInfo();
            appInfo.FromSignData("timespan=1434372013;appsource=1;appclient=1;token=SeBCjJYRkujxEsgv9XupyHY7aMkdQuQcqGMu0wQMbhw=;appversion=1.0;");

            var newSignData = appInfo.ToSignData(key);
            appInfo.FromSignData(newSignData);
            var result = appInfo.CheckSign(key);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///   完善授权信息
        /// </summary>
        /// <param name="sysInfo"></param>
        /// <param name="context"></param>
        private static void CompleteAuthInfo(SysAuthorizeInfo sysInfo, HttpContext context)
        {
            if (string.IsNullOrEmpty(sysInfo.IpAddress))
            {
                sysInfo.IpAddress = GetIpAddress(context);
            }

            // todo webbrowser
            sysInfo.AppSource  = _appSource;
            sysInfo.AppVersion = _appVersion;
        }
Ejemplo n.º 6
0
        public static void SysAuth()
        {
            string           key     = Guid.NewGuid().ToString().Replace("-", string.Empty);
            SysAuthorizeInfo appInfo = new SysAuthorizeInfo();

            appInfo.FromSignData("timespan=1434372013;appsource=1;appclient=1;token=SeBCjJYRkujxEsgv9XupyHY7aMkdQuQcqGMu0wQMbhw=;appversion=1.0;");

            var newSignData = appInfo.ToSignData(key);

            appInfo.FromSignData(newSignData);
            var result = appInfo.CheckSign(key);
        }
Ejemplo n.º 7
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.º 8
0
        public void TikectTest()
        {
            var info = new SysAuthorizeInfo();

            info.AppSource  = "FrontWeb";
            info.AppClient  = "PC";
            info.AppVersion = "1.0";
            info.DeviceId   = "Test Device";

            info.WebBrowser = "Chrome";

            var ticket = info.ToSignData("5c567449b8714a038c464059788d4fa6");
            //  appclient=PC;appsource=FrontWeb;appversion=1.0;deviceid=Test%20Device;timespan=1495277505;webbrowser=Chrome;sign=tBL1yvayljCTiBvO7u3As%2F3RLoc%3D
        }
Ejemplo n.º 9
0
    /// <summary>
    /// 复制新的授权信息实体
    /// </summary>
    /// <returns></returns>
    public SysAuthorizeInfo Copy()
    {
        SysAuthorizeInfo newOne = new SysAuthorizeInfo();

        newOne.AppClient  = this.AppClient;
        newOne.AppSource  = this.AppSource;
        newOne.AppVersion = this.AppVersion;
        newOne.DeviceId   = this.DeviceId;
        newOne.IpAddress  = this.IpAddress;

        newOne.OriginAppSource = this.OriginAppSource;
        newOne.Sign            = this.Sign;
        newOne.TimeSpan        = this.TimeSpan;
        newOne.Token           = this.Token;
        newOne.WebBrowser      = this.WebBrowser;
        return(newOne);
    }
Ejemplo n.º 10
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.º 11
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);
            }

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

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

            MemberShiper.SetAppAuthrizeInfo(sysInfo);

            await _next.Invoke(context);
        }
Ejemplo n.º 12
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.º 13
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);
        }
Ejemplo n.º 14
0
 public static void TriggerUserLoginEvent(UserInfoBigMo arg1, SysAuthorizeInfo arg2)
 {
     // todo  推送登录消息
 }
Ejemplo n.º 15
0
 public static void TriggerUserRegiteEvent(UserInfoBigMo arg1, SysAuthorizeInfo arg2)
 {
     // todo  推送注册消息
 }
Ejemplo n.º 16
0
        /// <summary>
        /// 注册用户信息
        /// </summary>
        /// <param name="value">注册的账号信息</param>
        /// <param name="passCode">密码</param>
        /// <param name="type">注册类型</param>
        /// <param name="auInfo">注册的系统信息</param>
        /// <returns></returns>
        public async Task <ResultMo <UserInfoMo> > RegisteUser(string value, string passCode, RegLoginType type, SysAuthorizeInfo auInfo)
        {
            var checkRes = await CheckIfCanRegiste(type, value);

            if (!checkRes.IsSuccess)
            {
                return(checkRes.ConvertToResultOnly <UserInfoMo>());
            }

            var userInfo = new UserInfoBigMo();

            if (type == RegLoginType.Email)
            {
                userInfo.email = value;
            }
            else
            {
                userInfo.mobile = value;
            }

            if (type != RegLoginType.MobileCode)
            {
                userInfo.pass_word = Md5.HalfEncryptHexString(passCode);
            }

            var idRes = await Rep <IUserInfoRep> .Instance.Insert(userInfo);

            if (!idRes.IsSuccess)
            {
                return(idRes.ConvertToResultOnly <UserInfoMo>());
            }

            userInfo.Id = idRes.Id;
            // todo 触发新用户注册事件
            return(new ResultMo <UserInfoMo>(userInfo));
        }