public void refresh() { var request = (HttpWebRequest)WebRequest.Create("https://accounts.google.com/o/oauth2/token"); string postData = string.Format("client_id={0}&client_secret={1}&refresh_token={2}&grant_type=refresh_token", this.clientId, this.secret, this.refresh_token); var data = Encoding.ASCII.GetBytes(postData); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = data.Length; using (var stream = request.GetRequestStream()) { stream.Write(data, 0, data.Length); } var response = (HttpWebResponse)request.GetResponse(); var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); var refreshResponse = AuthResponse.get(responseString); this.access_token = refreshResponse.access_token; this.created = DateTime.Now; }
public static AuthResponse Exchange(string authCode, string clientid, string secret, string redirectURI) { var request = (HttpWebRequest)WebRequest.Create("https://accounts.google.com/o/oauth2/token"); string postData = string.Format("code={0}&client_id={1}&client_secret={2}&redirect_uri={3}&grant_type=authorization_code", authCode, clientid, secret, redirectURI); //MessageBox.Show($"{postData}"); var data = Encoding.ASCII.GetBytes(postData); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = data.Length; using (var stream = request.GetRequestStream()) { stream.Write(data, 0, data.Length); } var response = (HttpWebResponse)request.GetResponse(); var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); var x = AuthResponse.get(responseString); x.clientId = clientid; x.secret = secret; return(x); }