Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Google oAuth on WP7

I trying out a small app for windows phone 7 that use Google tasks services, the problem is I'm not able to get pass to login.

I have read the all the steps given in documentation and following them
http://code.google.com/apis/accounts/docs/OAuth2.html#IA according to the document I need to make use of web control to login.

Is there any way I can just expect username password and get the authentication token in background?

like image 568
Prashant Cholachagudda Avatar asked Aug 01 '11 16:08

Prashant Cholachagudda


2 Answers

You can use ClientLogin to do things in the background, but it is being replaced (slowly) and doesn't work with all Google accounts (two-step) so I would suggest you stick with oAuth2, it definitely works.

How I do it is open a WebBrowser control, making sure IsScriptEnabled="true" then point it at

https://accounts.google.com/o/oauth2/auth?client_id=xxx&redirect_uri=https://www.mydomain.com/oauth2callback&scope=xxx&response_type=code

The really important part is the redirect url. You then wire up a Navigating method for your WebBrowser control to intercept the redirect to that url.

<phone:WebBrowser Name="webbrowser" Navigating="webbrowser_Navigating" IsScriptEnabled="true" />  

private void webbrowser_Navigating(object sender, NavigatingEventArgs e) {
  if (e.Uri.Host.Equals("www.mydomain.com")) {
    e.Cancel = true;
    HandleOAuthResponse(e.Uri.Query);
  }
}

This will give you back the querystring google redirects with which has the code=xxx that you then follow the rest of the docs and exchange it for a token that will last 30mins and a refresh token to keep the authentication active.

like image 180
Chris Sainty Avatar answered Sep 27 '22 20:09

Chris Sainty


Have a look at this post it is about a twitter client but twitter uses OAuth too.

EDIT

I read more on this and it seems to be a problem because it is mandatory to use the webpage and have to user copy the access code to the app. It appears to be hard/impossible to scrape the Webbrowser I could not find any references to a real solution at the moment.

like image 27
Emond Avatar answered Sep 27 '22 21:09

Emond