develop wherever and whenever you want...
Docs > OAuth Library Summary

OAuth Library Summary

Jasic provides a native interface to OAuth 1.1, an authentication and authorization framework used by many of the world's leading web service providers. Through Jasic's easy to use OAuth APIs, it is now trivial for you to write Jasic scripts that access the data of services such as Twitter, Dropbox, Facebook, etc. The Jasic OAuth library is designed to remove the complexities around the OAuth implementation, and allow you to focus on accessing the data these services provide.

var oauth = require( "OAuth" );

// onDropBoxSuccess is called immediately upon successful 
// authentication and authorization with the Dropbox service. 
// It must be installed on the authReplyHandler property of the 
// dropboxConfig object passed to the requestPermission call

function onDropBoxSuccess() { 
console.log( "Successfully authenticated...let's do some work!" );

// Now let's query the dropbox store and find out the top level   // directory contents "get", dropboxConfig.baseUrl + "/1/metadata/dropbox/" );   oauth.send( function(data){       console.log( "Got the data!!!!" );       console.log( data );        // Now let's upload a file that is in the current       // directory where this script ( main.js ) is "put", "");       oauth.send( "MyFile.js", function(data){           console.log( "Got the response from the put!" );           console.log( data );            // Cool, now let's pull a file down...  "get", "" );            oauth.send( function(data ){              console.log( "Got the response from the get, which is the contents of the file!" );               console.log( data );       "Dates.txt", data);           });       });   });   


var dropboxConfig = { 
consumerKey : "YourConsumerKeyForRegisteredApp", 
consumerSecret : "YourSecretForYourRegisteredApp", 
baseUrl : "", 
requestTokenUrl : " requesttoken", 
authorizationUrl : "", 
accessTokenUrl : "
authReplyHandler : onDropBoxSuccess 

// Pass in true to force authentication with the service 
oauth.requestPermission( dropboxConfig, true );


object require("OAuth") 
This is the main mechanism to obtain the OAuth object. All other methods are performed on the returned object. The Jasic OAuth API mimics the XHR API as much as possible.

OAuth Methods 
void requestPermission(config, forceAuth) 
Called to initiate the authentication and authorization process. See the "Example" section above for an example of what properties need to be included on the config object. Be sure to set a function object on the "authReplyHandler", as that function is called upon successful authorization from the specified service. Pass in "true" for forceAuth in order to force the authorization process, regardless of previously cached authenticatication settings.

void open("post" | "get", url) 
Creates a request with the host specified in url.

void send(fileName, callback) 
Connect and communicate with the host established via a previous call to the "open" method. The first parameter is only used in "post" operations, otherwise it can be discarded. "callback" is a function object that takes one parameter. That callback is executed upon completion of the send operation.

void setRequestHeader(header, value) 
Adds another header to the HTTP request established via a prior call to the "open" method.