Steam authorization - c#

I'm trying to get html code of authorizated steam page, but I can't log in.
My code is
public string tryLogin(string EXP, string MOD, string TIME)
{
var rsa = new RSA();
string encryptedPass;
rsa.Exponent = EXP;
rsa.Modulus = MOD;
encryptedPass = rsa.Encrypt(Pass);
string reqString = "username=kasyjack&password=" + encryptedPass + "&emailauth=&kasyjackfriendlyname=&captchagid=&captcha_text=&emailsteamid=&rsatimestamp=" + TIME + "&remember_login=false";
byte[] requestData = Encoding.UTF8.GetBytes(reqString);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://store.steampowered.com/login/dologin/");
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request.ContentLength = requestData.Length;
request.Host = "store.steampowered.com";
request.Method = "POST";
request.UserAgent = Http.ChromeUserAgent();
request.CookieContainer = _CookieCont;
using (Stream st = request.GetRequestStream())
st.Write(requestData, 0, requestData.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream());
string RSAR = sr.ReadToEnd();
return RSAR;
}
but response message is
{"success":false,"requires_twofactor":false,"clear_password_field":true,"captcha_needed":false,"captcha_gid":-1,"message":"Incorrect login."}
So does anyone know, what's wrong with login? Need your help.

SteamBot repository on GitHub has a working example on how to login to Steam via their website: link to method.
Here is a diagram explaining the whole process(made by me):

Related

RestAPI Post Method in ASP.NET MVC with special characters not working

We are trying to write special char in post method but we are getting exception below
can not close the stream until all bytes are written
Below is the example code I am using and below are the special char which I am trying to write
internal static T InvokePostService<T>(string serviceUri, string _data)
{
T _returnResponse = default(T);
HttpWebRequest req = null;
HttpWebResponse res = null;
try
{
string url = serviceUri;
req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
req.ContentType = "application/json; charset=utf-8";
req.Timeout = 600000;
req.Headers.Add("SOAPAction", url);
req.ContentLength = _data.Length;
var sw = new StreamWriter(req.GetRequestStream());
sw.Write(_data);
sw.Close();
res = (HttpWebResponse)req.GetResponse();
Stream responseStream = res.GetResponseStream();
var streamReader = new StreamReader(responseStream);
string responseString = streamReader.ReadToEnd();
_returnResponse = JsonConvert.DeserializeObject<T>(responseString);
}
Chars to write : •

Postmates API not working

I am using postmates Delivery Quote API for the last one year, And it is working good by the time when I checked.
But now it seems to be not working
It is throwing an exception with an HTML text with some enable cookies and captcha
I can't understand if i am missing some updates from postmates
Here is my coding
HttpWebRequest req = WebRequest.Create(new Uri("https://api.postmates.com/v1/customers/" + PostmatesCustomerId + "/delivery_quotes")) as HttpWebRequest;
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.Headers.Add("Authorization", "Basic " + Base64string);
StringBuilder paramz = new StringBuilder();
paramz.Append("pickup_address=" + PickUpAddress + "&dropoff_address=" + DeliveryAddress);
byte[] formData =
UTF8Encoding.UTF8.GetBytes(paramz.ToString());
req.ContentLength = formData.Length;
// Send the request:
using (Stream post = req.GetRequestStream())
{
post.Write(formData, 0, formData.Length);
}
string responseString = null;
using (HttpWebResponse resp = req.GetResponse()
as HttpWebResponse)
{
StreamReader reader =
new StreamReader(resp.GetResponseStream());
responseString = reader.ReadToEnd();
}
If you're outside of the US, try using a VPN as a workaround to test.

How To authenticate ALM from C# Windows Application Using Rest API

I am bit stuck here, trying to Integrate ALM using Rest API from C# Window application . But failed at the first step that is authentication .
Here is my Authentication call :
public void auth(string url, string xml)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
byte[] requestBytes = System.Text.Encoding.UTF8.GetBytes(xml.ToString());
req.Method = "POST";
req.ContentType = "application/xml";
req.Accept = "application/xml";
req.KeepAlive = true;
req.AllowAutoRedirect = true;
req.ContentLength = requestBytes.Length;
Stream requestStream = req.GetRequestStream();
requestStream.Write(requestBytes, 0, requestBytes.Length);
requestStream.Close();
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.Default);
backstr = sr.ReadToEnd();
myheader = res.Headers.Get("Set-Cookie");
sr.Close();
res.Close();
}
which i am calling like this :
try
{
// my creds, server details
string server_ = #"https://MyAlmUrl";
string user_ = "username";
string password_ = "password";
string xmll = "<?xml version='1.0' encoding='utf-8'?><alm-authentication><user>" + user_ + "</user><password>" + password_ + "</password></alm-authentication>";
rest.auth(server_ + "/authentication-point/authenticate", xmll);
}
No matter what ever i do It lands into : 401 unauthorized error.
I do have a valid credentials as i am able to login using the web with same credentials .
Some one help me out, what i am doing wrong , As This ALM and using Rest API , both are new to me .
Try this :
HttpWebRequest myauthrequest = (HttpWebRequest)WebRequest.Create("http://{qcserver}/qcbin/authentication-point/alm-authenticate");
string AuthenticationXML = #"<alm-authentication>
<user>{qcserver-username}</user>
<password>{qcserver-pwd}</password>
</alm-authentication>";
byte[] Requestbytes = Encoding.UTF8.GetBytes(AuthenticationXML);
myauthrequest.Method = "POST";
myauthrequest.ContentType = "application/xml";
myauthrequest.ContentLength = Requestbytes.Length;
myauthrequest.Accept = "application/xml";
Stream RequestStr = myauthrequest.GetRequestStream();
RequestStr.Write(Requestbytes, 0, Requestbytes.Length);
RequestStr.Close();
HttpWebResponse myauthres = (HttpWebResponse)myauthrequest.GetResponse();
var AuthenticationCookie = myauthres.Headers.Get("Set-Cookie");
//request to get all domains in ALM
HttpWebRequest domainreq = (HttpWebRequest)WebRequest.Create("http://{qcserver}/qcbin/rest/domains/");
domainreq.Method = "GET";
domainreq.ContentType = "application/xml";
domainreq.Accept = "application/xml";
domainreq.Headers.Set(HttpRequestHeader.Cookie, AuthenticationCookie);
HttpWebResponse domainres= (HttpWebResponse)domainreq.GetResponse();
Stream RStream = domainres.GetResponseStream();
XDocument doc = XDocument.Load(RStream);
//request to dowmload a particular attachement assigned to a test case
HttpWebRequest attachmentreq = (HttpWebRequest)WebRequest.Create("http://{qcserver}/qcbin/rest/domains/{domainname}/project/{projectname}/tests/{testid}/attachments/file.xls");
attachmentreq.Method = "GET";
attachmentreq.ContentType = "application/xml";
attachmentreq.Accept = "application/octet-stream";
attachmentreq.Headers.Set(HttpRequestHeader.Cookie, AuthenticationCookie);
HttpWebResponse attachmentres= (HttpWebResponse)attachmentreq.GetResponse();
Stream RStream = attachmentres.GetResponseStream();
var fileStream = File.Create("C:\\PathToFile");
RStream.InputStream.CopyTo(fileStream);
fileStream.Close();

How to use WebRequest in c#

I'am trying to use example api call in below link please check link
http://sendloop.com/help/article/api-001/getting-started
My account is "code5" so i tried 2 codes to get systemDate.
1. Code
var request = WebRequest.Create("http://code5.sendloop.com/api/v3/System.SystemDate.Get/json");
request.ContentType = "application/json; charset=utf-8";
string text;
var response = (HttpWebResponse)request.GetResponse();
using (var sr = new StreamReader(response.GetResponseStream()))
{
text = sr.ReadToEnd();
}
2.Code
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("http://code5.sendloop.com/api/v3/System.SystemDate.Get/json");
httpWebRequest.Method = WebRequestMethods.Http.Get;
httpWebRequest.Accept = "application/json";
But i don't know that i use correctly api by above codes ?
When i use above codes i don't see any data or anything.
How can i get and post api to Sendloop.And how can i use api by using WebRequest ?
I will use api first time in .net so
any help will be appreciated.
Thanks.
It looks like you need to post your API key to the endpoint when making requests. Otherwise, you will not be authenticated and it will return an empty response.
To send a POST request, you will need to do something like this:
var request = WebRequest.Create("http://code5.sendloop.com/api/v3/System.SystemDate.Get/json");
request.ContentType = "application/json; charset=utf-8";
string postData = "APIKey=xxxx-xxxxx-xxxxx-xxxxx-xxxxx";
request.Method = "POST";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(postData);
request.ContentLength = data.Length;
Stream newStream = request.GetRequestStream(); //open connection
newStream.Write(data, 0, data.Length); // Send the data.
newStream.Close();
string text;
var response = (HttpWebResponse)request.GetResponse();
using (var sr = new StreamReader(response.GetResponseStream()))
{
text = sr.ReadToEnd();
}
string userAuthenticationURI =
"https://maps.googleapis.com/maps/api/distancematrix/json?origins="+ originZip +
"&destinations="+ DestinationZip + "&units=imperial&language=en-
EN&sensor=false&key=Your API Key";
if (!string.IsNullOrEmpty(userAuthenticationURI))
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(userAuthenticationURI);
request.Method = "GET";
request.ContentType = "application/json";
WebResponse response = request.GetResponse();
var responseString = new
StreamReader(response.GetResponseStream()).ReadToEnd();
dynamic obj = JsonConvert.DeserializeObject(responseString);
}

Get access token from google oauth from code

i used following code to get the access token from code as below
String code = HttpContext.Current.Request["code"];
string redirecturl = HttpContext.Current.Request["url"];
string Url = "https://accounts.google.com/o/oauth2/token";
string grant_type = "authorization_code";
string redirect_uri_encode = UrlEncodeForGoogle(url);
string data = "code={0}&client_id={1}&client_secret={2}&redirect_uri={3}&grant_type={4}&access_type={5}";
HttpWebRequest request = HttpWebRequest.Create(Url) as HttpWebRequest;
string result = null;
request.Method = "POST";
request.KeepAlive = true;
request.ContentType = "application/x-www-form-urlencoded";
string param = string.Format(data, code,configurationInfo.oauthclientid , configurationInfo.oauthclientsecretid, redirect_uri_encode, grant_type, "offline");
var bs = Encoding.UTF8.GetBytes(param);
using (Stream reqStream = request.GetRequestStream())
{
reqStream.Write(bs, 0, bs.Length);
}
using (WebResponse response = request.GetResponse())
{
var sr = new StreamReader(response.GetResponseStream());
result = sr.ReadToEnd();
sr.Close();
}
i am getting response as
The remote server returned an error: (400) Bad Request.
i do not know where i went wrong
waiting for your valuable comments
Google also provides a higher level library for accessing its services. I find it makes it much easier to work with its APIs.
http://code.google.com/p/google-api-dotnet-client/

Categories