使用Apache Cordova for Visual Studio进行身份validation
我正在使用Visual Studio中的Cordova开发一个跨平台的Twitter应用程序,我仍然坚持使用Twitter帐户进行身份validation。
在定位Windows / Windows Phone时,我可以使用Windows.Security.Authentication.Web.WebAuthenticationBroker.authenticateAsync
API并完成工作。 但对于Android或IOS,我无法使用API,因为它抱怨Windows未定义。
有人可以帮我提供一个示例代码或建议,我应该如何使用JavaScript进行身份validation?
我认为您不应该依赖跨平台应用程序上的Windows API,因为它不会在除Windows之外的任何其他平台上提供。 相反,您可能希望使用适用于每个平台的JavaScript解决方案进行身份validation。
根据您在应用程序中使用的框架和库,有几种可能性在js中执行此操作:如果您使用jquery,则可以使用$ .ajax进行身份validation;如果使用角度,则可以使用$ http服务进行身份validation…如果您没有使用任何库,则可以使用XMLHttpRequest 。
我找到了一个使用Cordova的InAppBrowser插件的解决方案。
将插件添加到项目中,然后使用下面的代码来授权您的应用。
var self = this; var ref = cordova.InAppBrowser.open(startURI, '_blank', 'location=yes'); ref.show(); ref.addEventListener('loadstart', function (event) { if (event.url && event.url.match('oauth_verifier')) { ref.close(); self._continueAuthentication(event.url, callback); } }); ref.addEventListener('loadstop', function (event) { }); ref.addEventListener('exit', function (response) { }); _continueAuthentication: function (returnedTokens, callback) { var self = this, oauthVerifier, oauthToken; var responseKeyValPairs = returnedTokens.split("?")[1].split("&"); //Disect the important parts for (i = 0; i < responseKeyValPairs.length; i++) { splits = responseKeyValPairs[i].split("="); switch (splits[0]) { case "oauth_verifier": oauthVerifier = splits[1]; break; case "oauth_token": oauthToken = splits[1]; break; } }
- 我可以在应用程序包中访问jquery和cordova的Documents目录中创build一个html文件吗?
- 为什么ibooks不提供文本突出显示并在固定布局epub中添加注释function?
- Safari iOS没有加载Javascript文件?
- 如何解决“如果播放不开始,请尝试使用iPad上的Youtube iFrame API重新启动设备?
- 我必须点击两次以激活任何button动作(离子/angular度)
- 从Cordova Capture获取audio数据的base64
- 防止iOS Webkit长按链接
- 检查与cordovaPhonegap 3.3.0 iOS应用程序无法正常工作的互联网连接
- MapKit JS入门