jsOAuth
JavaScript implimentation of the OAuth protocol. Currently supports version 1.0 (RFC5849) of the specification. Node.js & CommonJS compatible.
Getting started - jsOAuth Manual & Documentation how to get started using jsoauth
I am developing a Hybrid app using Cordova/PhoneGap.
While using Twitter login, browser do not close after navigating to success url.
This happens only in Samsung S4.
Code is something like this :
To open :
cb = window.open('https://api.twitter.com/oauth/authorize?' + data.text, '_blank', 'location=yes');
To close :
cb.close();
There is no problem in S3.
Any solution or trick to resolve the same will be appreciated.
Source: (StackOverflow)
I am creating a oauth connectivity using jsoauth 1.3 in cordova 2.0 can anyone tell me how to sent message signer method as plain text because my server only support plain text message signer method. my oauth.get function is working properly bur the default signer is HMAC-SHA1
this is my code
function oauthStart1() {
var oauth;
var requestParams;
var options = {
consumerKey : 'blahblah',
consumerSecret : 'blahblah',
callbackUrl : 'stx://blahblah'
// signatureMethod: 'PLAIN_TEXT'
};
// information in
var twitterKey = "twttrKey"; // what we will store our twitter user information in
// our storedAccessData and Raw Data
var storedAccessData, rawData = localStorage.getItem(twitterKey);
// First thing we need to do is check to see if we already have the user saved!
if(localStorage.getItem(twitterKey) != null){
alert("localStorage not null")
storedAccessData = JSON.parse(rawData); // Parse our JSON object
options.accessTokenKey = storedAccessData.accessTokenKey; // This is saved when they first sign in
options.accessTokenSecret = storedAccessData.accessTokenSecret; // this is saved when they first sign in
localStorage.clear()
}
else{
alert("localStorage is null" );
oauth = OAuth(options);
alert(JSON.stringify(oauth));
oauth
.get(
'http://231.123.123.243:8081/blahblah/oauth/initiate.action',
function(data) {
requestParams = data.text;
alert("requestParams" + requestParams);
window.plugins.childBrowser.showWebPage('http://231.123.123.243:8081/blahblah/oauth/authorize.action?'
+ data.text, { showLocationBar: true}); // page
window.plugins.childBrowser.onLocationChange = function(loc) {
if(loc.indexOf(options.callbackUrl) >=0 ){
window.plugins.childBrowser.close();
var index, verifier = '';
var params = loc.substr(loc.indexOf('?') + 1);
alert("params"+ params);
params = params.split('&');
for (var i = 0; i < params.length; i++) {
var y = params[i].split('=');
if(y[0] === 'oauth_verifier') {
verifier = y[1];
}
}
oauth.get('http://231.123.123.243:8081/blahblah/oauth/authorize.action?oauth_verifier='+verifier+'&'+requestParams,
function(data) {
alert("verify Success" + data)
var accessParams = {};
var qvars_tmp = data.text.split('&');
for (var i = 0; i < qvars_tmp.length; i++) {
var y = qvars_tmp[i].split('=');
accessParams[y[0]] = decodeURIComponent(y[1]);
}
var accessData = {};
accessData.accessTokenKey = accessParams.oauth_token;
accessData.accessTokenSecret = accessParams.oauth_token_secret;
alert("fine")
//localStorage.setItem(twitterKey, JSON.stringify(accessData));
},
function(data) {
alert("varify error");
}
);
}
};
}, function(data) {
alert("ERROR: " + data);
});
}
}
Source: (StackOverflow)
I searched SE's archives, google, directly ripped this off and ran it and I've been on it for like 6 hours now.
Based on the link above (jsOAuth Library) I wrote my code and when I run it on my android, the inAppBrowser (correctly) redirects me to the twitter page where I'm supposed to get my pin. But instead of the pin, it shows "there is no request token for this page... " error.
I even deleted and registered a new app under a different name and got a new pair of Consumer key/secret. But that too did not budge.
This could be a possible solution but even the Boilerplate example is not working. I guess I'm not getting my request token. Any help?
Source: (StackOverflow)
Application type: mobile,
Titanium SDK: 3.0.2.GA,
Platform & version: Android 4.0.4,
Device: Android Xperia P,
i am trying to use twitter API via jsOAuth 1.3.6. all the OAuth dance goes well until I fetch request token (oAuthApi.fetchAccessToken() method). i am always getting "unauthorized" error any idea why? please see code below
oAuthApi.fetchRequestToken(function(data) {
//authorize
var authorizeUi = Ti.UI.createWebView({
width : Ti.UI.FILL,
height : Ti.UI.FILL,
top : 0,
left : 0,
url : data
});
authorizeUi.addEventListener('load', function(e) {
if (authorizeUi.getUrl().indexOf('twitterOauthCallback') > -1) {
oAuthApi.fetchAccessToken(function(data) {
oAuthApi.saveAccessToken();
oAuthApi.setAuthorised(true);
var accessToken = oAuthApi.getAccessToken();
var accessTokenSecret = oAuthApi.getAccessTokenSecret();
...some other code here
}, function(data) {
alert('fetchAccessToken unauthorized error ' + data.error);
});
}
});
}, function(data) {
alert('fetchRequestToken error');
});
here is my jsOAuth initialization:
var oauth = OAuth({
consumerKey : jsonObj.consumerKey,
consumerSecret : jsonObj.consumerSecret,
callbackUrl : jsonObj.callbackUrl
});
my callback is
http://192.168.1.116:8888/callback/twitterOauthCallback.html
1- I call fetchRequestToken (ok)
2- i open the user authorization / login window (ok)
3 - enter username and password and get the callback url (ok)
4 - call fetchAccessToken (get 401 error)
below is my header:
oauth_callback = http://192.168.1.74:8888/callback/twitterOauthCallback.html
oauth_consumer_key = E3xxxxxxxxxxxxxxHfg
oauth_token = J1fxxxxxxxxxxxxxxxxxxxxxxxxxxxx20
oauth_signature_method = HMAC-SHA1
oauth_timestamp = 1365151792
oauth_nonce = 36222C667E353A51
oauth_verifier =
oauth_version = 1.0
any idea what might be the problem ?? i am blocked
Source: (StackOverflow)
I'm building a chrome extension for tumblr. I'm doing the oauth part using the library jsoauth, but I'm getting a 401 error.
The exact error being, "oauth_signature [D6rDCSn/ClGhMyTq24/c6419t8I=] does not match expected value [wnrVNhZYCSfRmKSTaKyb9dg7vNQ=]"
I have no idea what's causing it. Here's the code I have:
Background.html
<html>
<script type="text/javascript" src="jsOAuth-1.3.6.min.js"></script>
<script type="text/javascript" src="background.js"></script>
</html>
background.js
function getAccess(){
var oauth, options;
options = {
consumerKey: 'KEY',
consumerSecret: 'SECRET',
requestTokenUrl: "http://www.tumblr.com/oauth/request_token",
authorizationUrl: "http://www.tumblr.com/oauth/authorize",
accessTokenUrl: "http://www.tumblr.com/oauth/access_token"
};
oauth = OAuth(options);
oauth.fetchRequestToken(openAuthoriseWindow, failureHandler);
function openAuthoriseWindow(url)
{
var wnd = window.open(url, 'authorise');
oauth.setVerifier(false);
oauth.fetchAccessToken(output,failureHandler);
function output(url)
{
console.log("success!");
}
}
function failureHandler(data)
{
console.error(data);
}
}
chrome.extension.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.greeting == "getAccess"){
sendResponse({farewell: "It worked"});
getAccess();
}
});
Source: (StackOverflow)
I'm using jsOAuth: https://github.com/bytespider/jsOAuth
I want to get to the Twitter OAuth page where the user inputs their username/pass so that my app can then get the other token for tweeting etc. (FYI, it's not a web app. It's a mobile app[I know not to show the key and secrets etc.])
When I click this button it doesn't work(do you know why?):
<html>
<head>
<script src="jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="jsOAuth-1.3.4.js"></script>
<script type="text/javascript">
function gimmiegimmie(){
var options = {
consumerKey: 'blahblahblah',
consumerSecret: 'blahblahblah',
callbackUrl: 'http://www.wouwqheqweiqiuwheiug8yg2g123e.com/' };
oauth = OAuth(options);
oauth.get('https://api.twitter.com/oauth/request_token',
function(data) {
requestParams = data.text;
window.location.href = "https://api.twitter.com/oauth/authorize?"+data.text;},
alert("ahhhh");
window.location.replace( "index.html" );
);}
</script>
</head>
<body bgcolor="black" >
<center>
<br>
<button type="button" id="authbut" style="font-size:45px;height: 100px; width: 75%" onClick="gimmiegimmie();">OAuth</button><br>
<br>
</center>
</body>
</html>
Source: (StackOverflow)
I have a strange problem with PhoneGap (3.6.3-0.22.1) using jsoauth. Using only the skeleton app already provided by phonegap, I have just added a simple part of code relative to jsOauth:
,
success: function(data) {
console.log("SUCCESS!");
},
failure: function(data) {
console.log("FAIL!");
},
oauthTest: function() {
var options = {
enablePrivilege: true,
consumerKey: '<here_my_consumer_key>',
consumerSecret: '<here_my_consumer_secret>'
};
var oauth = OAuth(options);
console.log("Ready to perform the get() call");
oauth.get('<my_url_here>', app.success, app.failure);
}
the oauthTest()
function is called when the deviceready
event is fired.
What happens is that, if I comment out the .get()
call, I can see the console message Ready to perform the get() call
. But if that line is not commented, I cannot see any console message and neither success
nor failure
callbacks are called.
Now, I have <access origin="*" />
in my phonegap config.xml, but the strange thing here is that it does not print the console message....
Any hints? Thanks.
EDIT: The code runs over an iPhone6 simulator, and if I put the URL in Safari I can reach it without problems.
EDIT: Solved setting enablePrivilege
to false...
Source: (StackOverflow)
There's a Javascript library for doing OAuth - called jsOAuth.
The examples that are available show it being used from within browsers. There are also some examples that claim to show how to use it from Node.js.
Can it also be used from ASP Classic / JScript ?
The key test would be:
can jsOAuth be used to post a Tweet on behalf of a user, from an ASP Classic page?
Source: (StackOverflow)