开发者

JavaScript OAuth sign in with Twitter

开发者 https://www.devze.com 2022-12-24 10:37 出处:网络
I have to integrate Sign-in-with Twitter in my app as below. https://dev.twi开发者_如何转开发tter.com/docs/auth/sign-twitter

I have to integrate Sign-in-with Twitter in my app as below. https://dev.twi开发者_如何转开发tter.com/docs/auth/sign-twitter It is browser based app developed in JavaScript I have been refering google code java script OAuth, but im confused how to use oauth/authenticate and how to get the oauth_token

Can any one please help me out with some samples ?


Problem with this is that anyone who views your page can also now view your consumer key and secret which must be kept private.

Now, someone could write an app that uses your app credentials and do naughty and bad things to the point that twitter and users ban you, and there isnt anything you can do.

Twitter do state that every possible effort must be made to keep these values private to avoid this happening

Unfortunately, there is currently no way to use oAuth in Browser based JavaScript securely.


Check out the Twitter @Anywhere JSDK authComplete and signOut events and callbacks at https://dev.twitter.com/docs/anywhere/welcome#login-signup

twttr.anywhere(function (T) {

    T.bind("authComplete", function (e, user) {
      // triggered when auth completed successfully
    });

    T.bind("signOut", function (e) {
      // triggered when user logs out
    });

});


Use below code in consumer.js and select example provider in index.html drop down list

consumer.example =
{ consumerKey   : "your_app_key"
, consumerSecret: "your_app_secret"
, serviceProvider:
  { signatureMethod     : "HMAC-SHA1"
  , requestTokenURL     : "https://twitter.com/oauth/request_token"
  , userAuthorizationURL: "https://twitter.com/oauth/authorize"
  , accessTokenURL      : "https://twitter.com/oauth/access_token"
  , echoURL             : "http://localhost/oauth-provider/echo" 
  }
};


Since I was searching for the same thing, trying not to use a custom PHP solution, I came across this very simple integration at http://www.fullondesign.co.uk/coding/2516-how-use-twitter-oauth-1-1-javascriptjquery.htm which uses a PHP proxy that accepts whatever twitter api call you'd like to retrieve from your javascript ..

I'm definitely taking a look at it

0

精彩评论

暂无评论...
验证码 换一张
取 消