public override OAuth2UserInfo GetUserInfo(OAuth2TokenAccess token) { Dictionary <string, object> dict = new Dictionary <string, object>(1); dict.Add("access_token", token.AccessToken); string url = "https://api.douban.com/v2/user/" + token.UserId + "?" + HttpBuildQuery(dict); string json = HttpGetContents(url); JsonObject user = JsonValue.LoadJson(json) as JsonObject; if (user == null || user.ContainsKey("msg")) { throw new OAuth2Exception(500, json); } return(new OAuth2UserInfo() { Type = OAuth2ProviderType.douban, UserId = user["id"] as JsonString, ScreenName = user["uid"] as JsonString, UserName = user["name"] as JsonString, Location = "", Description = "", Image = user["avatar"] as JsonString, AccessToken = token.AccessToken, ExpireAt = token.Expires, RefreshToken = token.RefreshToken }); }
public override OAuth2Member GetUserInfo(OAuth2TokenAccess token) { SortedDictionary <string, object> dict = new SortedDictionary <string, object>(); dict.Add("access_token", token.AccessToken); dict.Add("uid", token.UserId); string url = "https://api.weibo.com/2/users/show.json?" + HttpBuildQuery(dict); string json = HttpGetContents(url); JsonObject user = JsonValue.LoadJson(json) as JsonObject; if (user == null || user.ContainsKey("error")) { throw new OAuth2Exception(500, json); } return(new OAuth2Member() { Type = Key, UserId = user["id"] as JsonString, ScreenName = user["screen_name"] as JsonString, UserName = user["name"] as JsonString, Location = user["location"] as JsonString, Description = user["description"] as JsonString, Image = user["profile_image_url"] as JsonString, AccessToken = token.AccessToken, ExpireAt = token.Expires, RefreshToken = token.RefreshToken }); }
public override OAuth2UserInfo GetUserInfo(OAuth2TokenAccess token) { Dictionary <string, object> dict = new Dictionary <string, object>(2); dict.Add("access_token", token.AccessToken); dict.Add("app_id", _options.ClientId); string url = "http://api.189.cn/upc/vitual_identity/user_network_info?type=json&" + HttpBuildQuery(dict); string json = HttpGetContents(url); JsonObject user = JsonValue.LoadJson(json) as JsonObject; if (user == null || user.ContainsKey("error")) { throw new OAuth2Exception(500, json); } return(new OAuth2UserInfo() { Type = OAuth2ProviderType.tianyi, UserId = token.UserId, ScreenName = user["user_nickname"] as JsonString, UserName = "", Location = "", Description = user["user_selfdesc"] as JsonString, Image = "", AccessToken = token.AccessToken, ExpireAt = token.Expires, RefreshToken = token.RefreshToken }); }
public override OAuth2UserInfo GetUserInfo(OAuth2TokenAccess token) { Dictionary <string, object> dict = new Dictionary <string, object>(5); dict.Add("access_token", token.AccessToken); dict.Add("format", "JSON"); dict.Add("v", "1.0"); dict.Add("call_id", Guid.NewGuid().ToString("N")); dict.Add("method", "users.getInfo"); string url = "https://api.renren.com/restserver.do"; string json = HttpGetContents(url, HttpBuildQuery(dict)); JsonObject user = JsonValue.LoadJson(json) as JsonObject; //! is_array($user) OR ! isset($user[0]) OR ! ($user = $user[0]) OR array_key_exists("error_code", $user) if (user == null || user.ContainsKey("error_code")) { throw new OAuth2Exception(500, json); } return(new OAuth2UserInfo() { Type = OAuth2ProviderType.renren, UserId = user["uid"] as JsonString, ScreenName = user["name"] as JsonString, UserName = "", Location = "", Description = "", Image = user["tinyurl"] as JsonString, AccessToken = token.AccessToken, ExpireAt = token.Expires, RefreshToken = token.RefreshToken }); }
public override OAuth2Member GetUserInfo(OAuth2TokenAccess token) { SortedDictionary <string, object> dict = new SortedDictionary <string, object>(); dict.Add("access_token", token.AccessToken); dict.Add("uid", token.UserId); string url = "https://openapi.baidu.com/rest/2.0/passport/users/getLoggedInUser?" + HttpBuildQuery(dict); string json = HttpGetContents(url); JsonObject user = JsonValue.LoadJson(json) as JsonObject; if (user == null || user.ContainsKey("error")) { throw new OAuth2Exception(500, json); } return(new OAuth2Member() { Type = Key, UserId = user["uid"] as JsonString, ScreenName = user["uname"] as JsonString, UserName = "", Location = "", Description = "", Image = "http://tb.himg.baidu.com/sys/portraitn/item/" + (user["portrait"] as JsonString).Value, AccessToken = token.AccessToken, ExpireAt = token.Expires, RefreshToken = token.RefreshToken }); }
public override OAuth2Member GetUserInfo(OAuth2TokenAccess token) { SortedDictionary <string, object> dict = new SortedDictionary <string, object>(); dict.Add("access_token", token.AccessToken); dict.Add("openid", token.UserId); dict.Add("lang", "zh_CN"); string url = API_URL + "sns/userinfo?" + HttpBuildQuery(dict); string json = HttpGetContents(url); JsonObject user = JsonValue.LoadJson(json) as JsonObject; if (user == null || user.ContainsKey("errcode")) { throw new OAuth2Exception(500, json); } return(new OAuth2Member() { Type = Key, UserId = user["openid"] as JsonString, ScreenName = user["nickname"] as JsonString, UserName = user["nickname"] as JsonString, Location = user["province"] as JsonString, Description = "", Image = user["headimgurl"] as JsonString, AccessToken = token.AccessToken, ExpireAt = token.Expires, RefreshToken = token.RefreshToken }); }
public override OAuth2UserInfo GetUserInfo(OAuth2TokenAccess token) { Dictionary <string, object> dict = new Dictionary <string, object>(1); dict.Add("access_token", token.AccessToken); string url = "http://api.t.sohu.com/users/show/id.json?" + HttpBuildQuery(dict); string json = HttpGetContents(url); JsonObject user = JsonValue.LoadJson(json) as JsonObject; if (user == null || user.ContainsKey("error")) { throw new OAuth2Exception(500, json); } return(new OAuth2UserInfo() { Type = OAuth2ProviderType.sohu, UserId = user["id"] as JsonString, ScreenName = user["screen_name"] as JsonString, UserName = user["name"] as JsonString, Location = "", Description = user["description"] as JsonString, Image = user["profile_image_url"] as JsonString, AccessToken = token.AccessToken, ExpireAt = token.Expires, RefreshToken = token.RefreshToken }); }
public override OAuth2UserInfo GetUserInfo(OAuth2TokenAccess token) { Dictionary <string, object> dict = new Dictionary <string, object>(1); dict.Add("access_token", token.AccessToken); string url = "https://i.feixin.10086.cn/api/user.json?" + HttpBuildQuery(dict); string json = HttpGetContents(url); JsonObject user = JsonValue.LoadJson(json) as JsonObject; if (user == null || user.ContainsKey("error")) { throw new OAuth2Exception(500, json); } return(new OAuth2UserInfo() { Type = OAuth2ProviderType.feixin, UserId = user["userId"] as JsonString, ScreenName = user["nickname"] as JsonString, UserName = "", Location = "", Description = user["introducation"] as JsonString, Image = user["portraitTiny"] as JsonString, AccessToken = token.AccessToken, ExpireAt = token.Expires, RefreshToken = token.RefreshToken }); }
public void Cb(string type) { string target = Request.QueryString["target"]; if (string.IsNullOrEmpty(target)) { target = GetUrl("/"); } OAuth2Provider provider = GetProvider(type); if (provider != null) { OAuth2TokenAccess token = provider.Access() as OAuth2TokenAccess; M.OAuth2Member user = provider.GetUserInfo(token); if (!string.IsNullOrEmpty(user.UserId)) { M.Member member; M.LoginStatus status = M.OAuth2Member.Login(DataSource, type.ToLower(), user.UserId, ClientIp, out member); if (status == M.LoginStatus.Success) { PassportAuthentication.SetAuthCookie(true, false, member); OnLogined(member.Id); Refresh(target); } else { if (status == M.LoginStatus.NeedBind) { this["Oauth2Type"] = user.Type; this["Oauth2UserId"] = user.UserId; this["Target"] = target; this["Sms"] = SMSCaptchaSection.GetSection(); Render("oauth2.html"); } else { Redirect(GetUrl("/login")); } } } else { Redirect(GetUrl("/login")); } } else { Redirect(GetUrl("/login")); } }
public override OAuth2UserInfo GetUserInfo(OAuth2TokenAccess token) { return(new OAuth2UserInfo() { Type = OAuth2ProviderType.duoshuo, UserId = token.UserId, ScreenName = token.UserId, UserName = "", Location = "", Description = "", Image = "", AccessToken = token.AccessToken, ExpireAt = 0, RefreshToken = "" }); }
public override OAuth2Member GetUserInfo(OAuth2TokenAccess token) { SortedDictionary <string, object> dict = new SortedDictionary <string, object>(); dict.Add("access_token", token.AccessToken); string url = "https://graph.qq.com/oauth2.0/me?" + HttpBuildQuery(dict); string json = HttpGetContents(url); if (json.IndexOf("callback") > -1) { int lpos = json.IndexOf('('); int rpos = json.LastIndexOf(')'); json = json.Substring(lpos + 1, rpos - lpos - 1).Trim(); } JsonObject me = JsonValue.LoadJson(json) as JsonObject; if (me == null || me.ContainsKey("error")) { throw new OAuth2Exception(500, json); } dict.Add("openid", (me["openid"] as JsonString).Value); dict.Add("oauth_consumer_key", _options.ClientId); url = "https://graph.qq.com/user/get_user_info?" + HttpBuildQuery(dict); json = HttpGetContents(url); JsonObject user = JsonValue.LoadJson(json) as JsonObject; if (user == null || user.ContainsKey("error")) { throw new OAuth2Exception(500, json); } return(new OAuth2Member() { Type = Key, UserId = me["openid"] as JsonString, ScreenName = user["nickname"] as JsonString, UserName = "", Location = "", Description = "", Image = user["figureurl"] as JsonString, AccessToken = token.AccessToken, ExpireAt = token.Expires, RefreshToken = token.RefreshToken }); }
public override OAuth2Member GetUserInfo(OAuth2TokenAccess token) { SortedDictionary <string, object> dict = new SortedDictionary <string, object>(); dict.Add("access_token", token.AccessToken); dict.Add("method", "taobao.user.get"); dict.Add("v", "2.0"); dict.Add("format", "json"); dict.Add("fields", "user_id,uid,nick,location,avatar"); string url = "https://eco.taobao.com/router/rest?" + HttpBuildQuery(dict); string json = HttpGetContents(url); JsonObject user = JsonValue.LoadJson(json) as JsonObject; if (user == null || user.ContainsKey("error_response")) { throw new OAuth2Exception(500, json); } JsonObject data = user["user_get_response"] as JsonObject; if (data == null) { throw new OAuth2Exception(500, json); } JsonObject u = data["user"] as JsonObject; if (u == null) { throw new OAuth2Exception(500, json); } return(new OAuth2Member() { Type = Key, UserId = u["user_id"] as JsonString, ScreenName = u["nick"] as JsonString, UserName = u["uid"] as JsonString, Location = u["location"] as JsonString, Description = "", Image = u["avatar"] as JsonString, AccessToken = token.AccessToken, ExpireAt = token.Expires, RefreshToken = token.RefreshToken }); }
public override OAuth2UserInfo GetUserInfo(OAuth2TokenAccess token) { Dictionary <string, object> dict = new Dictionary <string, object>(5); dict.Add("access_token", token.AccessToken); dict.Add("oauth_consumer_key", _options.ClientId); dict.Add("openid", token.UserId); dict.Add("clientip", HttpContext.Current.Request.UserHostAddress); dict.Add("oauth_version", "2.a"); string url = "https://open.t.qq.com/api/user/info?" + HttpBuildQuery(dict); string json = HttpGetContents(url); JsonObject user = JsonValue.LoadJson(json) as JsonObject; if (user == null || user.ContainsKey("ret")) { throw new OAuth2Exception(500, json); } JsonObject data = user["data"] as JsonObject; if (data == null) { throw new OAuth2Exception(500, json); } return(new OAuth2UserInfo() { Type = OAuth2ProviderType.tweibo, UserId = data["openid"] as JsonString, ScreenName = data["nick"] as JsonString, UserName = data["name"] as JsonString, Location = "", Description = data["introduction"] as JsonString, Image = (data["head"] as JsonString).Value + "/100", AccessToken = token.AccessToken, ExpireAt = token.Expires, RefreshToken = token.RefreshToken }); }
public override OAuth2UserInfo GetUserInfo(OAuth2TokenAccess token) { throw new NotImplementedException(); }