Пример #1
0
        protected async Task <YunUser> GetUserByToken(string ticket, string appID, string appSecret, string yunXT)
        {
            YUNAPI.YUNXT = yunXT;
            YunUser user = await YUNAPI.GetYunUser(ticket, appID, appSecret);

            return(user);
        }
Пример #2
0
        public async Task <ActionResult> Index()
        {
            string ticket = Request["ticket"];//"fb82c715df4f8bb8ded6737bb868a257";//

            if (string.IsNullOrEmpty(ticket))
            {
                return(View("Error"));
            }

            //获取AppSettings的节点

            string appID     = ConfigurationManager.AppSettings["appID"];     //轻应用注册到云之家时生成
            string appSecret = ConfigurationManager.AppSettings["appSecret"]; //轻应用注册到云之家时生成

            YUNAPI.YUNXT = ConfigurationManager.AppSettings["yunxt"];

            try
            {
                YunUser user = await YUNAPI.GetYunUser(ticket, appID, appSecret);

                ViewData["userName"] = user.mobile;

                ViewData["msg"] = "";
            }
            catch (Exception ex)
            {
                return(View("Error"));
            }
            return(View());
        }
        public async Task AuthenticateAsync(HttpAuthenticationContext context, CancellationToken cancellationToken)
        {
            IPrincipal user = null;
            AuthenticationHeaderValue headerValue =
                context.Request.Headers.Authorization;

            if (null != headerValue && headerValue.Scheme == "Basic")
            {
                //string credential = Encoding.Default.GetString(
                //    Convert.FromBase64String(headerValue.Parameter));
                YunUser yunUser = await GetUserFromTicket(headerValue.Parameter);

                if (yunUser != null)//云之家验证
                {
                    GenericIdentity identity = new GenericIdentity(yunUser.mobile);
                    user = new GenericPrincipal(identity, new string[0]);
                }
            }
            else if (null != headerValue && headerValue.Scheme == "WGCUS")
            {
                GenericIdentity identity = new GenericIdentity(headerValue.Parameter);
                user = new GenericPrincipal(identity, new string[0]);
            }

            context.Principal = user;
            // return Task<object>(null);
        }
        private async Task <YunUser> GetUserFromTicket(string ticket)
        {
            string  appID     = ConfigurationManager.AppSettings["appID"];     //轻应用注册到云之家时生成
            string  appSecret = ConfigurationManager.AppSettings["appSecret"]; //轻应用注册到云之家时生成
            string  yunxt     = ConfigurationManager.AppSettings["yunxt"];     //轻应用注册到云之家时生成
            YunUser user      = null;

            try
            {
                user = await YUNAPI.GetYunUser(yunxt, ticket, appID, appSecret);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
            }
            return(user);
        }