简体   繁体   English

在WP7上使用Google oAuth

[英]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. 我尝试了一个使用Google任务服务的Windows Phone 7小应用程序,问题是我无法通过登录。

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. 根据我需要使用网络控件登录的文档, http://code.google.com/apis/accounts/docs/OAuth2.html#IA

Is there any way I can just expect username password and get the authentication token in background? 有什么办法可以让我期望用户名密码并在后台获取身份验证令牌?

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. 您可以使用ClientLogin在后台执行操作,但是(正在缓慢地)替换它,并且不能在所有Google帐户中使用(两步操作),因此我建议您坚持使用oAuth2,它肯定可以使用。

How I do it is open a WebBrowser control, making sure IsScriptEnabled="true" then point it at 我该怎么做是打开一个WebBrowser控件,确保IsScriptEnabled="true"然后将其指向

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. 真正重要的部分是重定向URL。 You then wire up a Navigating method for your WebBrowser control to intercept the redirect to that url. 然后,为您的WebBrowser控件连接一个Navigating方法,以拦截到该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. 这将带给您带有google code=xxx谷歌重定向查询字符串,然后您跟随其余文档并将其交换为一个持续30分钟的令牌和一个刷新令牌以保持身份验证有效。

Have a look at this post it is about a twitter client but twitter uses OAuth too. 看一下这篇文章,它是关于Twitter客户端的,但是Twitter也使用OAuth。

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. 刮刮Webbrowser似乎很难/不可能,我目前找不到任何有关实际解决方案的参考。

我认为您可以使用webBrowser.SaveToString()方法抓取webBrowser。

You can actually scrape the browser URI by taking the e.Uri.ToString() and use the replace method to remove items not needed eg thestring.Replace("http://fakeuri.com/code=",""); 实际上,您可以通过使用e.Uri.ToString()来抓取浏览器URI,并使用replace方法删除不需要的项目,例如thestring.Replace("http://fakeuri.com/code=",""); e.Uri.ToString()

Only issue I have is with the Access Token. 我唯一的问题是访问令牌。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM