Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Problem] Twitter Implementation #19

Open
martinop opened this issue Jul 10, 2016 · 3 comments
Open

[Problem] Twitter Implementation #19

martinop opened this issue Jul 10, 2016 · 3 comments

Comments

@martinop
Copy link

martinop commented Jul 10, 2016

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

@larssn
Copy link

larssn commented Jul 12, 2016

Try out this fork:
https://github.com/stalniy/ng2-cordova-oauth

It (seems) to have simplified provider creation, but it might have other problems.

@nraboy
Copy link
Owner

nraboy commented Jul 12, 2016

@stalniy and I are working to merge the two repositories. He has done a good job with provider inheritance.

Stay tuned.

@ciekawy
Copy link

ciekawy commented May 16, 2019

I thought the ngx is derivate of the ng plugin - after 3 years - wonder if there is a chance for having it working? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants