Google+从Javascript登录 - 原始参数值无效 [英] Google+ Sign in from Javascript - Invalid Parameter value for origin

查看:213
本文介绍了Google+从Javascript登录 - 原始参数值无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经完成了步骤,要将 https: //developers.google.com/+/web/signin/



在典型网站中使用时,客户端流程正好。现在,我想在PhoneGap中整合这个Google+标志。由于PhoneGap将网页作为文件:// URL运行,因此在请求中发送的源是file://。



但是,当我在PhoneGap中的我的页面上点击Google+登录按钮时,作为file://发送时会产生以下错误消息:



错误:invalid_request

参数值无效origin:缺少权限:file://



我访问了Google API控制台并尝试将file://指定为授权的Javascript源。但是,当然,它不允许file://作为原始输入。



所以我想知道如果有人有任何洞察如何做这种类型的Web风格(Javascript)Google+从PhoneGap(或从没有服务器的本地网页 - 只是作为文件运行的页面://)登录。我真的不想在本机代码中进行登录,然后将令牌重新集成到PhoneGap领域,因为这种做法失败了为多个平台编写应用程序一次的目的。

解决方案

我的理解是,你不能使用Cordova / PhoneGap的标准客户端流,因为 file:// 不是有效的来源。



但是,您可以使用应用程序内浏览器插件以及 window.open ,这将允许启动标准客户端流从应用程序内。然后,您可以在打开的窗口上侦听事件以处理响应。



插件可跨平台运行,因此您不必维护多个本机实现。 p>

ng-cordova-oauth 库为AngularJS实现了这一点。



有关实现的更多细节,请参阅本教程,以及 Google OAuth文档


I've been going through the steps to add a Google+ Sign-in to my web application as found in https://developers.google.com/+/web/signin/

When used in a 'typical' web site, the 'client side' flow works just fine. Now, I'm trying to integrate this Google+ sign inside PhoneGap. Since PhoneGap runs the web page as a file:// URL, the origin that gets sent in the request is file://. In every other PhoneGap I've written, this hasn't been a problem.

However, when I click the Google+ sign in button from my page in PhoneGap, the origin being sent as file:// causes the following error message:

Error: invalid_request
Invalid parameter value for origin: Missing authority: file://

I went to the Google API console and tried to assign file:// as an authorized Javascript origin. But, of course, it doesn't allow file:// to be entered as an origin.

So I'm wondering if anyone has any insight in how to do this kind of web-style (Javascript) Google+ sign in from within PhoneGap (or from a local web page where there is no server - just a page being run as a file://). I really don't want to have to do the sign-in in native code and then integrate the token back over into the 'PhoneGap' realm since that kind of defeats the purpose of writing the app once for multiple platforms.

解决方案

My understanding is that you cannot use the standard client-side flow with Cordova/PhoneGap because file:// is not a valid origin.

However, you can use the In-App Browser plugin along with window.open, which will allow to initiate a "standard" client-side flow from within the application. You then listen to events on the opened window to deal with the responses.

The plugin works cross-platform so you won't have to maintain multiple native implementations.

The ng-cordova-oauth library implements this for AngularJS.

For more details about the implementation, see this tutorial for details, as well as the Google OAuth documentation.

这篇关于Google+从Javascript登录 - 原始参数值无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆