private string ReadFromProxy(ApiTerminal.Clients.Request.WoowRequest request) { var r = new BrowserClient(); var resp = r.SendHttpRequest(Config.ProxyApiUri, false, "POST", request.ObjToJson(), null, null, null, "UTF-8", "application/json", "application/json"); return(resp.Content); }
public AccountAvatarsPO ReadAvatar() { var now = DateTime.Now; var avatar = Avatar ?? new AccountAvatarsPO { CreateTime = now, Valid = true }; try { var url = "https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token={0}"; var r = new BrowserClient(); var response = r.SendHttpRequest(string.Format(url, avatar.Token), true, "GET", "", null, null, null, "UTF-8", "application/json", "application/json"); //r.SendHttpRequestGet(string.Format(url,avatar.Token),"", "application/json", null); Logger.Info(response); var user = response.JsonToObjContract <GoogleUser>(); if (user != null) { avatar.ChannelIdentity = user.Id; avatar.ChannelId = Channel.Id; avatar.DisplayName = user.Name; avatar.Code = user.Id; } } catch (Exception ex) { Logger.Error(ex); } return(avatar); }
/// <summary> /// 刷新令牌 /// </summary> /// <param name="refreshToken"></param> /// <returns></returns> public AccountAvatarsPO RefreshToken(string refreshToken) { var now = DateTime.Now; var avatar = Avatar ?? new AccountAvatarsPO { CreateTime = now, Valid = true }; var url = "https://login.microsoftonline.com/common/oauth2/v2.0/token"; Logger.Info(Channel.SerializeXml()); var data = string.Format( "grant_type=refresh_token&refresh_token={0}&redirect_uri={1}&client_id={2}&client_secret={3}&scope={4}", refreshToken, HttpUtility.UrlEncode(Channel.CodeCallback), Channel.AppId, Channel.AppSecret, Channel.Parameters); Logger.Info("data=" + data); try { var r = new BrowserClient(); var response = r.SendHttpRequest(url, true, "POST", data, null, null, null, "utf-8", "application/json", "application/x-www-form-urlencoded"); Logger.Info(response); var token = response.JsonToObjContract <Response.MsonlineToken>(); if (token != null) { avatar.ChannelId = Channel.Id; avatar.Token = token.AccessToken; avatar.RefreshToken = token.RefreshToken; avatar.TokenGenerated = now; avatar.TokenExpires = now.AddSeconds(token.ExpiresIn); avatar.UpdateTime = now; } } catch (Exception ex) { Logger.Error(ex); } return(avatar); }
public string ReadApi(string url) { try { var kv = new Dictionary <string, string> { { "Authorization", $"Bearer {Avatar.Token}" } }; var r = new BrowserClient(); var response = r.SendHttpRequest(url, true, "GET", "", kv, null, null, "utf-8", "application/json", "application/x-www-form-urlencoded"); Logger.Info(response); return(response.Content); } catch (Exception ex) { Logger.Error(ex); } return(""); }
public AccountAvatarsPO RefreshToken(string refreshToken) { var now = DateTime.Now; var avatar = Avatar ?? new AccountAvatarsPO { CreateTime = now, Valid = true }; var url = "https://www.googleapis.com/oauth2/v4/token"; var data = string.Format( "grant_type=refresh_token&refresh_token={0}&redirect_uri={1}&client_id={2}&client_secret={3}", refreshToken, System.Web.HttpContext.Current.Server.UrlEncode(Channel.CodeCallback), Channel.AppId, Channel.AppSecret); try { var r = new BrowserClient(); var response = r.SendHttpRequest(url, true, "POST", data, null, null, null, "UTF-8", "application/json", "application/x-www-form-urlencoded"); Logger.Info(response); var token = response.JsonToObjContract <Response.MsonlineToken>(); if (token != null) { avatar.ChannelId = Channel.Id; avatar.Token = token.AccessToken; avatar.RefreshToken = token.RefreshToken; avatar.TokenGenerated = now; avatar.TokenExpires = now.AddSeconds(token.ExpiresIn); avatar.UpdateTime = now; avatar.CreateTime = now; } } catch (Exception ex) { Logger.Error(ex); } return(avatar); }