示例#1
0
        public static OAuthUserInfo GetOAuthUserInfo(OAuthSystemType systemtype)
        {
            var client   = GetOAuthClient(systemtype);
            var userinfo = client.GetOAuthUserInfo();

            return(userinfo);
        }
示例#2
0
        public static bool AuthorizedCode(OAuthSystemType systemtype, string code)
        {
            var client = GetOAuthClient(systemtype);

            client.GetAccessTokenByCode(code);
            if (client.IsAuthorized)
            {
                HttpContext.Current.Session["access_token"] = client.AccessToken;
                HttpCookie cookie = new HttpCookie("uid", client.UID);
                if (HttpContext.Current.Request.Cookies["uid"] != null)
                {
                    cookie       = HttpContext.Current.Request.Cookies["uid"];
                    cookie.Value = client.UID;
                }
                cookie.Expires = DateTime.Now.AddDays(7);
                HttpContext.Current.Response.Cookies.Add(cookie);
                //HttpContext.Current.Response.AppendCookie(new HttpCookie("uid", client.UID) { Expires = DateTime.Now.AddDays(7) });
                log4net.LogManager.GetLogger("api").Info(string.Format("SystemType:{0}--AccessToken:{1}--Uid:{2}", systemtype.ToString(), client.AccessToken, client.UID));
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#3
0
        public JsonResult GetOauthLoginUrl(OAuthSystemType systemtype)
        {
            var        client = OAuthClientFactory.GetOAuthClient(systemtype);
            JsonResult jr     = new JsonResult();

            jr.Data = new { url = client.GetAuthorizationUrl() };
            return(jr);
        }
示例#4
0
        public static OpenAuthenticationBase GetOAuthClient(OAuthSystemType systemtype)
        {
            switch (systemtype)
            {
            case OAuthSystemType.Weibo:
                return(GetWeiBoClient());

            case OAuthSystemType.QQ:
                return(GetQQClient());

            default:
                throw new NotSupportedException();
            }
        }
示例#5
0
        public UserInfo GetUserInfoByUid(string uid, OAuthSystemType systemtype)
        {
            using (MVCBlogContext Context = new MVCBlogContext())
            {
                switch (systemtype)
                {
                case OAuthSystemType.QQ:
                    return(Context.UserInfo.FirstOrDefault(x => x.QQUid == uid));

                case OAuthSystemType.Weibo:
                    return(Context.UserInfo.FirstOrDefault(x => x.WeiBoUid == uid));

                default:
                    return(null);
                }
            }
        }
示例#6
0
        public static string GetOAuthLoginUrl(OAuthSystemType systemtype)
        {
            var client = GetOAuthClient(systemtype);

            return(client.GetAuthorizationUrl());
        }