问题描述
我正在使用Visual Studio科尔多瓦一个跨平台的Twitter的应用程序,我停留在Twitter帐号的身份验证。结果
当针对Windows / Windows Phone的,我可以使用 Windows.Security.Authentication.Web.WebAuthenticationBroker.authenticateAsync
API和完成这项工作。但对于Android或IOS,因为它是抱怨Windows是不确定的,我不能使用API。
I am working on a cross-platform Twitter app using Cordova in Visual Studio and I am stuck at the authentication of twitter account.
When targeting Windows/Windows Phone, I can use Windows.Security.Authentication.Web.WebAuthenticationBroker.authenticateAsync
API and get the work done. But for Android or IOS I can't use the API as it is complaining that Windows is undefined.
有人能帮助我的样本code或建议如何,我应该使用JavaScript做身份验证?
Could someone help me with a sample code or suggestion on how should I be doing authentication using JavaScript ?
推荐答案
我发现使用的解决方案插件。
I found a solution using InAppBrowser plugin from Cordova.
插件添加到您的项目,然后让下面的code授权您的应用程序。
Add the plugin to your project and then have the code below to authorize your app.
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;
}
}
这篇关于使用Apache科尔多瓦为Visual Studio认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!