- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我是这个领域的新手,我正在开发一个 HTML5
移动应用程序,它调用一个 restful webservices api 并交换 JSON 对象。
我想对客户端进行一次身份验证并提供一个 key / token ,之后可以使用该 key / token 直到预定义的到期日期。我有 4 个问题:
最佳答案
OAuth 可能无法满足您的需求,请确认您确实需要使用如此强大(且复杂)的标准。
您可能使用的 PHP 服务器端软件的两个示例:
是的!请注意,您必须使用 OAuth 2.0 隐式授权流程才能在客户端获取 token 。
ChildBrowser 是一个插件,用于为身份验证过程打开一个单独的浏览器窗口。
我已经编写了一个可以为您执行 OAuth 2.0 的 javascript 库 JSO。也存在其他库。
在混合环境下运行在移动设备上的WebApps使用JSO进行OAuth 2.0授权是JSO的一个重要部署场景。
这里是关于使用 Phonegap for iOS 设置 JSO 和使用 Google 配置 OAuth 2.0 的详细说明。您也可以将其与 Facebook 或其他 OAuth 提供商一起使用。
创建一个新的应用
./create /Users/andreas/Sites/cordovatest no.erlang.test "CordovaJSOTest"
原始的 ChildBrowser 插件可在此处获得。
但是,它不与 Cordova 2.0 兼容。相反,您可以使用 ChildBrowser 的这个分支,它应该与 Cordova 2.0 一起工作:
您需要做的是复制这些文件:
通过使用拖放到 XCode 中的 Plugins 文件夹,进入您的 WebApp 项目区域。
现在您需要编辑位于 WebApp 项目区域的 Resources/Cordova.plist
中的文件。
在此文件中,您需要将一个带有“*”的数组条目添加到 ExternalHosts 中,并在 Plugins 中添加两个条目:
如屏幕截图所示。
(来源:erlang.no)
我建议在继续使用 OAuth 之前测试并验证您是否让 ChildBrowser 正常工作。
在您的 index.html
文件中尝试此操作,并使用模拟器进行验证。
<script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
<script type="text/javascript" charset="utf-8" src="ChildBrowser.js"></script>
<script type="text/javascript">
var deviceready = function() {
if(window.plugins.childBrowser == null) {
ChildBrowser.install();
}
window.plugins.childBrowser.showWebPage("http://google.com");
};
document.addEventListener('deviceready', this.deviceready, false);
</script>
下载最新版本的 JSO:
那里也提供了有关 JSO 的文档。
回调 URL 需要指向某处,一种方法是将回调 HTML 页面放在某处,尽管是您信任的主机,但放在哪里并不重要。并在那里放一个漂亮的空白页:
<!doctype html>
<html>
<head>
<title>OAuth Callback endpoint</title>
<meta charset="utf-8" />
</head>
<body>
Processing OAuth response...
</body>
</html>
现在,设置您的应用程序索引页。这是一个工作示例:
<script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
<script type="text/javascript" charset="utf-8" src="ChildBrowser.js"></script>
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="jso/jso.js"></script>
<script type="text/javascript">
var deviceready = function() {
var debug = true;
/*
* Setup and install the ChildBrowser plugin to Phongap/Cordova.
*/
if(window.plugins.childBrowser == null) {
ChildBrowser.install();
}
// Use ChildBrowser instead of redirecting the main page.
jso_registerRedirectHandler(window.plugins.childBrowser.showWebPage);
/*
* Register a handler on the childbrowser that detects redirects and
* lets JSO to detect incomming OAuth responses and deal with the content.
*/
window.plugins.childBrowser.onLocationChange = function(url){
url = decodeURIComponent(url);
console.log("Checking location: " + url);
jso_checkfortoken('facebook', url, function() {
console.log("Closing child browser, because a valid response was detected.");
window.plugins.childBrowser.close();
});
};
/*
* Configure the OAuth providers to use.
*/
jso_configure({
"facebook": {
client_id: "myclientid",
redirect_uri: "https://myhost.org/callback.html",
authorization: "https://www.facebook.com/dialog/oauth",
presenttoken: "qs"
}
}, {"debug": debug});
// For debugging purposes you can wipe existing cached tokens...
// jso_wipe();
// jso_dump displays a list of cached tokens using console.log if debugging is enabled.
jso_dump();
// Perform the protected OAuth calls.
$.oajax({
url: "https://graph.facebook.com/me/home",
jso_provider: "facebook",
jso_scopes: ["read_stream"],
jso_allowia: true,
dataType: 'json',
success: function(data) {
console.log("Response (facebook):");
console.log(data);
}
});
};
document.addEventListener('deviceready', this.deviceready, false);
</script>
关于HTML5+jQuery+phonegap 移动应用安全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12171227/
Example image 如何在 Phonegap 中添加像这张图片这样的 float 气泡通知。 最佳答案 没有您正在寻找的“开箱即用”插件。但是,您可以创建自己的插件或简单地使用 phonega
我正在使用 HTML 和 JS、JQuery Mobile 构建一个应用程序,并使用 PhoneGap Build 进行打包。客户想知道是否可以添加打印功能...有人知道吗?没有 PG Build 打
我已经安装了 Phonegap 使用 $ npm install -g PhoneGap 我也创建了项目。之后我做了 $ PhoneGap build android 它给出了 [phonegap]
我尝试创建 Phonegap 项目,其中需要集成 ASIHTTPRequest 和 JASON 引用, 并出现以下错误 ld: duplicate symbol _SBJSONErrorDomain
我有一个 Phonegap 应用程序,我从早期版本的 Phonegap 开始,我想升级到最新版本。我需要采取哪些步骤来升级它? 我正在寻求一般性答案,但我的具体情况是 Phonegap 1.1.0 -
我已在我的 MAC 电脑(IOS 10.5.8,SDK 3.1.2)上成功安装 PhoneGap。尝试创建一个新的基于 PhoneGap 的应用程序,包含 PhoneGap 框架并将所需的文件复制到
我正在 phonegap 中为三个不同的平台构建一个应用程序:Android、iOS 和 Blackberry。这样做时,我必须检测设备类型,以便我可以在不同平台和不同设备(如 Android Pho
开始在Mac上使用phonegap(Xcode 4,构建iPhone应用程序)我已经阅读了很多有关名为phonegap.plist的文件的内容,包括外部URL的白名单和其他内容。 这是我的问题,我在
所以我有一个运行 Phonegap 1.4.0 的应用程序(不要问),我决定升级到 1.8.1,这样做时 Phonegap 全局变量不再存在,将被替换为实用程序。 所以我转换了每一次出现: var t
我尝试了什么: 我正在开发一个安卓应用程序。在我的应用程序中,我必须打开 -> 向用户显示 Microsoft Office 文档(doc、docx、xls、xlsx、ppt、pptx)内容。为此,我
使用phonegap制作iOS应用时,ChildBrowser插件可以打开一个可以使用phonegap功能的远程页面吗? 例如:在phonegap应用程序中的index.html,调用childbro
我有一个带有 angularjs 的网络应用程序。我想使用 phonegap 将它变成一个移动应用程序 (android)。 我使用了 phonegap 构建:https://build.phoneg
我正在使用 Phonegap build 为每个平台生成可执行文件。每次更改代码时,我都必须在 phonegap build 上上传代码并生成新的 Apk 文件(适用于 android)。我不想在真实
我很生气,这是毫无疑问的,除了明显的可见差异之外,有人报告高度为: $('body').outerHeight(); //1780 与在我的本地 Windows 8 机器上使用 phonegap
我最近使用 phonegap 完成了我的第一个混合应用程序项目。当谈到公开测试时,我有点害怕签名过程。我从这里以及网上的其他地方阅读了许多不同的建议 fragment 来完成这项工作。 以下是如何为
我是 phonegap 的新手,我尝试创建一个简单的 phonegap 应用程序。 使用命令行安装phonegap后:--- 我已经成功创建了项目,但是当我尝试运行 phonegap build io
我正在为 Android 平台制作一个 phonegap 应用程序。在这个应用程序中,我想在多个 html 页面中滑动导航。请告诉我该怎么做。要么在单个 html 页面中完成,要么我必须为此滑动导航创
是否有任何插件可用于 Juce我可以添加哪些库可以同时适用于 IOS 和 android?如果没有,我如何集成 Juce我的电话间隙应用程序中的库? 最佳答案 没有插件。但您可以使用介绍榨汁机来创建不
Phonegap 刚刚推出了一种方法,可以使用以下命令使用本地服务器立即查看您对 phonegap 应用程序的更改: phonegap serve 然后通过下载 PhoneGap Developer
我们对如何集成phonegap插件,然后使用phonegap build构建我们的移动应用程序有一些疑问,这可能吗? 当您使用 Phonegapbuild 构建您的应用程序时,它会为所有受支持的设备构
我是一名优秀的程序员,十分优秀!