I've been trying to log into Gmail using:
WebClient Web = new WebClient();
Web.Credentials = new NetworkCredential(Email, Password, "https://mail.google.com");
and then browse the email using IHTMLDocument2 interface by getting the id associated to each email, building up the url, navigating to that url and using DownloadString method, pass the HTML content to the IHTMLDocument2 interface.
The problem is that google does not accept the credentials that I send so I can never log in. However, after a few attempts I saw that this activity has been monitored by Google as I saw a notification about that on the actual email account.
I would like to know how this problem can be solved or is it possible at all to log into Gmail using WebClient? if yes, how exactly ?
Use Fiddler to observe what the browser does. Fiddler can capture HTTPS traffic. A Google login is more complex than you might think.
The Credentials property has no effect on web forms. There is no standardized way to have a login form in HTML. WebClient cannot possibly know how the Google login form works. It cannot possibly automate this for you.
Related
My requirement is like that, I want to create an OAuth client for the website
https://onehub.com/. I got all the required information from that site but I don't know from where I need to start.
Application URI http://XYZ/SIDemo
Redirect URI http://XYZTest/SIDemo
Client ID -->9rtk1k9fsdgziiuvakujytuea6doxpk
Client Secret--> Only available immediately after the Client is created.
I am not getting what is Application URI and Redirect URI ,This website is basically used for Uploading and downloading files. I want Oauth for this site So that I can able to share files with my clients like for different clients different folder.
You should probably do some homework on OAuth.
The application URI is where your web app resides. I'm not sure of Onehub's API, but this is generally what happens in the OAuth flow -
i) You register your app and get client credentials (you already have those!). I'll talk of redirect_uri later.
ii) User clicks on a log in with onehub button that you have added to your website (which resides at the application URI).
iii) basically, you have delegated the login process to one-hub. Onehub's login page would open, it would prompt the user to accept/decline the permissions that your app has demanded.
iv) Now, once the user accepts -> Onehub would send an access token/authorization code (depending on the flow) to the redirect_uri link that you provide. So basically, you need to catch the access token in that page, hit Onehub's REST API (for which you are using OAuth) with the token and perhaps redirect to your own page once onehub returns the info to you.
I have a webpage which is windows forms authenticated ,and i want to download a copy of this page's HTML in to my server, when user request this page. I have tried something like this
using (WebClient client = new WebClient())
{
string htmlCode = client.DownloadString("http://aksphases:200/lynliste.aspx");
}
which doesn't gives me correct result because of the URL I had passes to system creates new session.And in that case i need to authenticate this web-request,which I can't do.Only way to authenticate this webpage is that user log in manually(I know ways to authenticate werequests by code,but I can't try that here for some special reasons). Is there any other way for me to download current page's HTML which is running in in browser with out authenticating the URL.
You could send the current forms authentication cookie along with the request:
using (WebClient client = new WebClient())
{
client.Headers[HttpRequestHeader.Cookie] =
System.Web.HttpContext.Current.Request.Headers["Cookie"];
string htmlCode = client.DownloadString("http://aksphases:200/lynliste.aspx");
}
This way we are basically transferring the current HTTP request cookies to the remote HTTP call.
If the web server does not allow anonymous access then there is no way around - you must authenticate yourself with the web site.
However, contrary to your belief that log on operation has to be done manually, it can be done via code also. In case of windows authentication, pass credentials via Credentials property. For Forms authentication, you need to POST log-on credentials to login page and then use the authentication cookie from the response in subsequent request (Use tool such fiddler to inspect request/responses from browser to replicate same within your code).
How to send messages to facebook users using ASP.NET? I need to send messages and images to the Users. I have the Email Id and user authentication keys also if needed. Please try to give some code snippet to implement this one.
Using the Facebook C# SDK (http://facebooksdk.codeplex.com)
var app = new FacebookApp("access_token");
var parameters = new Dictionary<string, object>();
parameters["message"] = "This is a test message";
app.Api("/me", parameters, HttpMethod.Post);
That will post a message to the current user's wall. You can also post images using that SDK. There are samples in the tests on how to do that. Note, if you meant that you wanted to sent them a private message rather than post on their wall that is not possible. Facebook does not allow applications to send messages directly to users.
Similar to the CSV file which can be downloaded from http://download.finance.yahoo.com/d/quotes.csv?s=RHT . How can I downloada file which requires authentication?
I can simply use
My.Computer.Network.DownloadFile("http://download.finance.yahoo.com/d/quotes.csv?s=RHT,MSFT,NOVL&f=sl1c1d1&e=.csv", "h:\s.csv")
To download the file which is available in public. I tried setting the username and password as per the MSDN documentation but all I get is the HTML content of the login page.
If the site uses Cookie based authentication, you'll need to post the login details to the server, collect the cookies, then pass them up on the request for the file.
That's not as easy as it sounds...
There's an example here
http://blogs.msdn.com/dgorti/archive/2005/08/16/452347.aspx
Phil
It all depends on whether or not the web site will interpret your username/password when you provide it in your HTTP request. Some sites/protocols will, and others won't.
Here's an article that shows how you can download with the WebRequest class.
Downloading Files with the WebRequest and WebResponse Classes
All you need in addition to this article is adding your username/password to the WebRequest. You can do it like this:
// Create a request for the specified remote file name
WebRequest request = WebRequest.Create(remoteFilename);
if (request != null)
{
string username = "your username";
string password = "your password";
request.Credentials = new System.Net.NetworkCredential(username, password);
...
}
Unfortunately, if using this method doesn't work, then Yahoo's finance page doesn't allow providing a username/password automatically, and you'd have to login "the old fashioned way" to be able to download your file.
It sounds like the site you are working with is using forms authentication. Unless you have access to a version that uses realm authentication you will probably need to use HttpWebRequest and fake POST request to the site while you have a CookieContainer so you can retain the token. Then you would be able to include that token in a get request to download the CSV file.
I'm trying to login directly to Google Analytics. To explain, I have an account system and I'd like when you select an ASP.NET button for instance it re-directs you - via a silent login - to a specified Google Analytics account.
I've looked long and hard at Dave Cullen's ASP.NET library and although I can login 'silently' using HttpWebRequest, I can't then stick the user on that page. I'm having allsorts of dramas with a 'Cannot send a content-body with this verb-type' error too.
Here is the very basic code I have currently based on Dave's library;
string token = GoogleAnalytics.getSessionTokenClientLogin(username, password);
NameValueCollection profiles = GoogleAnalytics.getAccountInfo(token, GoogleAnalytics.mode.ClientLogin);
HttpWebRequest theRequest = (HttpWebRequest)WebRequest.Create("https://www.google.com/analytics/settings/?et=reset&hl=en_uk&et=reset&hl=en-US&et=reset&hl=en-GB");
theRequest.Headers.Add("Authorization: GoogleLogin auth=" + token);
Stream responseBody = theRequest.GetRequestStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader readStream = new StreamReader(responseBody, encode);
My question therefore is; 1. can this be done? and 2. is this even the right way to do this?
Advice welcomed!
I'm not sure what the overall goal of signing someone in to Google Analytics automatically is, but if its just to display some of the data that is in Google Analytics you might want to consider using the Google Data API to pull the information that you want from Google Analytics. You could create a simple dashboard of what they really need to see without giving access to other things in Google Analytics, by logging them in you are most likely giving them access to data and tools that they just don't need?
Check out the API if it doesn't fit your needs maybe provide some more information on the overall goal is of this functionality.
http://code.google.com/apis/analytics/
Unless you're willing to implement a proxy server to proxy google analytics, I don't think you're going to be able to do this because you can't assign cookies to the client for another domain.
If the auth tokens are stored in cookies you can add the cookies to your ASP.NET response - then host the google page in an IFRAME just by setting the src (no inlining). That IFRAME will "inherit" the cookies from your parent page and the page will think it's authenticated.