ngx-cordova-oauth
ngx-cordova-oauth copied to clipboard
[Problem] Twitter Implementation
Hi, I was trying to implement twitter oauth with this lib, but i have that problem: When I open https://api.twitter.com/oauth/authenticate? to get the oauth_verifier I get the problem: "This page is no longer valid. It's looks like someone already used the token information your provider, blabla.."
Im creating a Request token with node, like:
app.get("/auth/twitter/token", function (req, res) {
var requestTokenUrl = "https://api.twitter.com/oauth/request_token";
var requestTokenOauth = {
consumer_key: "***********",
consumer_secret: "***",
callback: "***/auth/twitter/token"
};
request.post({
url: requestTokenUrl,
oauth: requestTokenOauth
}, function (err, response, body) {
var oauthToken = qs.parse(body);
res.send(oauthToken);
});
});
With this i get the token and token secret, after I call the Twitter Login, thats my implementation:
"use strict";
var utility_1 = require("../utility");
var PROVIDER_NAME = "Twitter";
var Twitter = (function () {
function Twitter(options) {
this.twitterOptions = options;
this.flowUrl = ""
}
Twitter.prototype.login = function (token, tokenSecret) {
var _this = this;
return new Promise(function (resolve, reject) {
_this.flowUrl = "https://api.twitter.com/oauth/authenticate?oauth_token="+token;
var browserRef = window.cordova.InAppBrowser.open(_this.flowUrl, "_blank", "location=no,clearsessioncache=yes,clearcache=yes");
browserRef.addEventListener("loadstart", function (event) {
if ((event.url).indexOf(_this.twitterOptions.redirectUri) === 0) {
browserRef.removeEventListener("exit", function (event) { });
browserRef.close();
var parsedResponse = event.url.split("?")[1].split("&");
if (parsedResponse) {
resolve(parsedResponse);
}
else {
reject("Problem authenticating with " + PROVIDER_NAME);
}
}
});
browserRef.addEventListener("exit", function (event) {
reject("The " + PROVIDER_NAME + " sign in flow was canceled");
});
});
};
return Twitter;
}());
exports.Twitter = Twitter;
In the Component I Make:
this.API.twitterToken().subscribe(
data => {
alert(data.oauth_token)
alert(data.oauth_token_secret)
this.twitterOAuth.login(data.oauth_token, data.oauth_token_secret).then((success) => {
alert(JSON.stringify(success))}, (error) => {alert(JSON.stringify(error));
});
},
err => alert(JSON.stringify(err))
);
Someone can help? this can be a feature in the future
Try out this fork: https://github.com/stalniy/ng2-cordova-oauth
It (seems) to have simplified provider creation, but it might have other problems.
@stalniy and I are working to merge the two repositories. He has done a good job with provider inheritance.
Stay tuned.
I thought the ngx is derivate of the ng plugin - after 3 years - wonder if there is a chance for having it working? :)