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; }
private void LoginBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { //string Body = ((WebBrowser)sender).DocumentText; //MessageBox.Show($"{Body}"); string Mytitle = ((WebBrowser)sender).DocumentTitle.ToLower(); string ind = Mytitle.IndexOf("success code=").ToString(); //MessageBox.Show($"{ind}"); if (Mytitle.IndexOf("success code=") > -1) { string AuthCode = LoginBrowser.DocumentTitle.Replace("Success code=", ""); // 여기부터 수정하십쇼 [2018 12 29 23:57] string webText = ((WebBrowser)sender).DocumentText; int start = webText.IndexOf("code=") + 5; int end = webText.IndexOf(@"&"); //start = webText.IndexOf(AuthCode, start); //int end = webText.IndexOf('"', start); string authCode = webText.Substring(start, end - start); /* * if ( authCode == null || authCode == "") * { * authCode = "null"; * }*/ //MessageBox.Show($"authCode : {authCode}"); //Exchange the code for Access token and refreshtoken. var access = AuthResponse.Exchange(authCode, "554669990764-3rae9jmrbn2g31pq12vsqfimptfcfag7.apps.googleusercontent.com", "k6QB-O_X71vatJwtDBe_9uKv", "urn:ietf:wg:oauth:2.0:oob"); //MessageBox.Show($"AccessToken = {access.Access_token}"); this.AuthToken = access; this.Close(); } }
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); }
public ComputeApiForm(AuthResponse ATT) { InitializeComponent(); this.ATT = ATT; MonoComputeService = GetServiceInstance(); }