public static OAuthUserInfo GetOAuthUserInfo(OAuthSystemType systemtype) { var client = GetOAuthClient(systemtype); var userinfo = client.GetOAuthUserInfo(); return(userinfo); }
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); } }
public JsonResult GetOauthLoginUrl(OAuthSystemType systemtype) { var client = OAuthClientFactory.GetOAuthClient(systemtype); JsonResult jr = new JsonResult(); jr.Data = new { url = client.GetAuthorizationUrl() }; return(jr); }
public static OpenAuthenticationBase GetOAuthClient(OAuthSystemType systemtype) { switch (systemtype) { case OAuthSystemType.Weibo: return(GetWeiBoClient()); case OAuthSystemType.QQ: return(GetQQClient()); default: throw new NotSupportedException(); } }
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); } } }
public static string GetOAuthLoginUrl(OAuthSystemType systemtype) { var client = GetOAuthClient(systemtype); return(client.GetAuthorizationUrl()); }