Exemplo n.º 1
0
        public static string GetAuthorization(GoogleConnection conn, string email, string password,
                                              GoogleService service, string token, string captcha)
        {
            if (email == null || email == String.Empty || password == null || password == String.Empty)
            {
                return(null);
            }

            email    = HttpUtility.UrlEncode(email);
            password = HttpUtility.UrlEncode(password);
            string appname      = HttpUtility.UrlEncode(conn.ApplicationName);
            string service_code = service.ServiceCode;

            StringBuilder content = new StringBuilder();

            content.Append("accountType=HOSTED_OR_GOOGLE");
            content.AppendFormat("&Email={0}", email);
            content.AppendFormat("&Passwd={0}", password);
            content.AppendFormat("&email={0}", email);
            content.AppendFormat("&service={0}", service_code);
            content.AppendFormat("&source={0}", appname);

            if (token != null)
            {
                content.AppendFormat("&logintoken={0}", token);
                content.AppendFormat("&logincaptcha={0}", captcha);
            }
            byte [] bytes = Encoding.UTF8.GetBytes(content.ToString());

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(client_login_url);

            request.Method        = "POST";
            request.ContentType   = "application/x-www-form-urlencoded";
            request.ContentLength = bytes.Length;

            Stream output = request.GetRequestStream();

            output.Write(bytes, 0, bytes.Length);
            output.Close();

            HttpWebResponse response = null;

            try {
                response = (HttpWebResponse)request.GetResponse();
            } catch (WebException wexc) {
                response = wexc.Response as HttpWebResponse;
                if (response == null)
                {
                    throw;
                }
                ThrowOnError(response);
                throw;                 // if the method above does not throw, we do
            }

            //string sid = null;
            //string lsid = null;
            string auth = null;

            using (Stream stream = response.GetResponseStream()) {
                StreamReader sr = new StreamReader(stream, Encoding.UTF8);
                string       s;
                while ((s = sr.ReadLine()) != null)
                {
                    if (s.StartsWith("Auth="))
                    {
                        auth = s.Substring(5);
                    }
                    //else if (s.StartsWith ("LSID="))
                    //	lsid = s.Substring (5);
                    //else if (s.StartsWith ("SID="))
                    //	sid = s.Substring (4);
                }
            }
            response.Close();

            return(auth);
        }
Exemplo n.º 2
0
 public GoogleConnection(GoogleService service)
 {
     Service = service;
 }
		public static string GetAuthorization (GoogleConnection conn, string email, string password,
				GoogleService service, string token, string captcha)
		{
			if (email == null || email == String.Empty || password == null || password == String.Empty)
				return null;

			email = HttpUtility.UrlEncode (email);
			password = HttpUtility.UrlEncode (password);
			string appname = HttpUtility.UrlEncode (conn.ApplicationName);
			string service_code = service.ServiceCode;

			StringBuilder content = new StringBuilder ();
			content.Append ("accountType=HOSTED_OR_GOOGLE");
			content.AppendFormat ("&Email={0}", email);
			content.AppendFormat ("&Passwd={0}", password);
			content.AppendFormat ("&email={0}", email);
			content.AppendFormat ("&service={0}", service_code);
			content.AppendFormat ("&source={0}", appname);

			if (token != null) {
				content.AppendFormat ("&logintoken={0}", token);
				content.AppendFormat ("&logincaptcha={0}", captcha);
			}
			byte [] bytes = Encoding.UTF8.GetBytes (content.ToString ());

			HttpWebRequest request = (HttpWebRequest) WebRequest.Create (client_login_url);
			request.Method = "POST";
			request.ContentType = "application/x-www-form-urlencoded";
			request.ContentLength = bytes.Length;

			Stream output = request.GetRequestStream ();
			output.Write (bytes, 0, bytes.Length);
			output.Close ();

			HttpWebResponse response = null;
			try {
				response = (HttpWebResponse) request.GetResponse ();
			} catch (WebException wexc) {
				response = wexc.Response as HttpWebResponse;
				if (response == null)
					throw;
				ThrowOnError (response);
				throw; // if the method above does not throw, we do
			}

			//string sid = null;
			//string lsid = null;
			string auth = null;

			using (Stream stream = response.GetResponseStream ()) {
				StreamReader sr = new StreamReader (stream, Encoding.UTF8);
				string s;
				while ((s = sr.ReadLine ()) != null) {
					if (s.StartsWith ("Auth="))
						auth = s.Substring (5);
					//else if (s.StartsWith ("LSID="))
					//	lsid = s.Substring (5);
					//else if (s.StartsWith ("SID="))
					//	sid = s.Substring (4);
				}
			}
			response.Close ();

			return auth;
		}
		public GoogleConnection (GoogleService service)
		{
			this.service = service;
		}