Exemple #1
0
        /// <summary>
        /// 暴走账号登录
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public async Task <User> LoginAsync(string userName, string password)
        {
            //先清除Authorization信息
            HttpBaseService.RemoveHeader("Authorization");

            var result = await BaoZouOAuthAsync(userName, password);

            if (result != null && string.IsNullOrEmpty(result.Error))
            {
                LoginPost loginPost = new LoginPost()
                {
                    AccessToken = result.AccessToken,
                    Source      = "baozou",
                    User        = result.UserId
                };

                User user = await GetUserInfo(loginPost);

                if (user != null)
                {
                    HttpBaseService.SetHeader("Authorization", "Bearer " + user.AccessToken);
                }
                return(user);
            }

            return(null);
        }
Exemple #2
0
        /// <summary>
        /// 新浪weibo登录
        /// </summary>
        /// <returns></returns>
        public async Task <User> SinaWeiboLoginAsync()
        {
            //先清除Authorization信息
            HttpBaseService.RemoveHeader("Authorization");

            string result = await AuthenticationHelper.SinaAuthenticationAsync();

            Regex regex = new Regex(@"(?<=code=)(.)*");
            Match match = regex.Match(result);

            if (match.Success)
            {
                Dictionary <string, string> dic = new Dictionary <string, string>();
                dic.Add("client_id", "3341101057");
                dic.Add("client_secret", "0d0fe859e31afdc487d89fa3f3f0fe40");
                dic.Add("grant_type", "authorization_code");
                dic.Add("redirect_uri", "http://daily.ibaozou.com/sina_weibo/auth");
                dic.Add("code", match.Value);

                var acccessToken = await PostDic <AccessTokenResult>(dic, ServiceUri.AccessToken);

                if (acccessToken != null)
                {
                    LoginPost loginPost = new LoginPost()
                    {
                        AccessToken = acccessToken.AccessToken,
                        Source      = "sina",
                        User        = acccessToken.Uid,
                    };

                    User user = await GetUserInfo(loginPost);

                    if (user != null)
                    {
                        HttpBaseService.SetHeader("Authorization", "Bearer " + user.AccessToken);
                    }
                    return(user);
                }
            }
            return(null);
        }