Using Google oAuth on WP7

I tried a small application for Windows Phone 7 that uses Google task services, the problem is that I can’t access the login.

I have read all the steps given in the documentation and follow them
http://code.google.com/apis/accounts/docs/OAuth2.html#IA as per the doc, I need to use web control to login.

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

+6
source share
4 answers

You can use ClientLogin to run in the background, but it is replaced (slowly) and does not work with all Google accounts (two-step), so I suggest you stick with oAuth2, it definitely works.

As I do this, open the WebBrowser , making sure IsScriptEnabled="true" then point it to

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

The important part is the redirect URL. Then you hook up the Navigating method for your WebBrowser to intercept the redirect to this 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 return you Google redirect redirects using code=xxx , which will then follow the rest of the documents and exchange them for a token that will last 30 minutes and an update token to activate authentication.

+15
source

You have a look at this post , it's about a Twitter client, but twitter also uses OAuth.

EDIT

I read more about this, and this seems like a problem, because it is mandatory to use a web page and the user must copy the access code into the application. It seems hard / impossible to clear Webbrowser I could not find links to the real solution at the moment.

+2
source

I think you can opt out of webBrowser using the webBrowser.SaveToString () method.

0
source

In fact, you can clear the browser URI by taking e.Uri.ToString() and use the replace method to remove unnecessary items, for example. thestring.Replace("http://fakeuri.com/code=","");

Only I have a problem with the access token.

-2
source

Source: https://habr.com/ru/post/894041/


All Articles