I'm trying to authorize a spotify user in my windows forms application. I am able to make a GET call to the web API, and I get a response back that is HTML. When loaded into the browser, this HTML is a login page, but my question is two parts.
1) What would be the best way to display this login page. Obviously if I could launch the browser and have it return the authorization code somehow, that would be best, which brings me to my second question.
2) How would I get the authorization code from the browser when I launch the login screen? I can't see a way that my forms application would be able to receive any information after the login screen is launched. Sorry if this seems obvious.
I figured it out, the URL I was using was not meant to be requested from, but to have the user navigate to in their browser. I basically just put the link in my application as a button and it would launch in chrome. Once the user logs in, I used http://httpbin.org/get to display the authentication code and just copied the code into my app as a temporary fix. Obviously this is not ready for release, and I am still working out how to get the code from the redirect url to my application, but it's a step in the right direction!
1) You can display a web browser inside your form to do the login part.
2) Browsers like Chrome can't return values. You could look at the data sent / received from your browser and search for an authentication token or something like that
Related
I need information about how am I suppose to get a token from an external browser passed to my WPF application.
The user will click a button on my WPF which will launch a chrome browser, then the user will log in and after they do, I have to get the access_token passed back to my WPF.
Something like google authentication, when you sign in to a desktop application using google, you get a new tab on your browser, you sign in and then you return to the web application to find it signed in automatically.
I want to build something like this, if possible!
There is a google sample app online that you can reference for how to do this in WPF.
https://github.com/googlesamples/oauth-apps-for-windows
Specifically, the WPF app is the one named 'OAuthDesktopApp'.
I am currently working on a project for which there exists both a mobile app and a web site. One task can be performed on either the web site (meant for desktop users) or the app. Right now, the requested functionality for the site is as follows:
If a desktop user visits the web page, continue on that page as usual.
If a mobile user visits the web page, redirect them to the installed mobile app.
I have already implemented logic to tell whether the user is on a desktop or mobile device (most of the time, at least); however, it occurred to me that some users may not have the app installed, or that a desktop device could be incorrectly identified as a mobile device in the future. If a computer that does not have the app installed is redirected, they will encounter some error or an about:blank page. So, my question is, is there any way to tell whether a Response.Redirect to a mobile app will succeed?
So far I have investigated the HttpWebRequest/HttpWebResponse option to try and determine success or failure based on a requested page response prior to the redirect, but this does not seem like a valid option since a URL linked to an app will not provide a valid URI for the HttpWebRequest to test with. Any assistance or advice would be greatly appreciated. Thank you!
For clarification, the redirect looks something like this:
Response.Redirect("opencustomapp://SomePage?Parameter1=bar&Parameter2=foo");
The expected result is not to open a web page, but rather to interact with an app installed on the user's phone which has been mapped to this url.
EDIT: I have accepted the answer that it does not seem possible to do what I was asking for, but in case others have this problem, I wanted to attach some useful links to other questions about how to use a cookie to determine if the app is installed and how to redirect the user to some other place if the cookie is not set. For my own code, I will probably be going with a combination of a user-agent check and the setTimeout() function, as this can be implemented from code-behind using ClientScript.RegisterStartupScript without requiring any changes to the existing app.
No, there is no way to tell at the server if the redirect would succeed. This is because the redirect is sent back to the client from your server and executed at the client. Probably the best thing that you can do is use the mobile app to set a cookie for the website on the device, and then check for that cookie on the server side of the request... if it exists, redirect. Be careful to clear the cookie if they delete the app (if possible, not super familiar with mobile apps), otherwise the redirect would fail.
I am currently developing an app that uses a public API. After performing the login procedure with that API, I get a cookie that I store in my app. I need to pass this cookie with every API call, that I request. So far so good.
Now unfortunately this API doesn't give me acces to all features of the service. What I want to do is giving the users of my app a button, which open a WebBrowser for that specific features. The problem is, that the user is, of course, not logged in in that WebBrowser.
What I found out on my PC is, that the login-cookie, that I get from the API, would actually work for the website itself as well. So what I want to do is: When the user clicks on the button, it opens the WebBrowser and passes the login cookie I already have to the WebBrowser, so the user is already logged in and can use the feature. Is there any solution for that problem? I couldn't an answer for that.
Cheers! :)
You can only set cookies from invoking javascript on the page when loading is completed.
Windows Phone WebBrowser set cookies
I have a problem with facebook and google logout. My scenario is when user first time login with facebook or google for particular site.(using clint api, it will redirect to their own web browser). then it will show the login page . after successfully logout if again login with facebook or google i m trying it's not showing the login page , it directly shows the login success message.(because webbrowser history already there, and i am not able to delete the history) so in this situation multiple user can't login with facebook or google.
have anyone idea? how to solve this problem?
On WP7 you'll have to use InvokeScript and javascript to logout and/or get rid of cookies required by different services like FB and Google. Fiddler comes in handy for this.
If I remember correctly, for Google you'll have to watch for specific URL's and cancel navigation, run InvokeScript and continue navigation.
I worked on a project that accessed different providers and this was the solution we were able to get working.
On WP8 there is a method to clear cookies.
Try finding out if there is an OAuth or API url for logging the user out such as
m.facebook.com/logout.php?confirm=1&next=(url encoded login page)
to navigate the user to.
the company that I work for has a website to enter some user's code and get details of user.
The problem is I have to enter the codes one by one and this bothers me (very boring job!), so I want to make a win app to post batch data and get response. I have to login first to access the data entry page.
What scenario do you suggest to make this app?
I think this post should help you with the login portion of the problem
HTTP client and forms authentication in C#