jsOAuth

Manual & Documentation

API Reference

This is what you were really after.

OAuth

Creates an OAuth object which signs and makes requests. You must so this first, as all other calls are based on the object this creates.

Parameters

  1. config
    object

The following config parameters can be set.

ParameterValueRequiredDefaultNotes
consumerKeystringtrue  
consumerSecretstringtrue  
accessTokenKeystring  

Some services give you an access token so you can skip the OAuth dance

accessTokenSecretstringRequired if 'accessTokenKey' was set  
signatureMethodstring HMAC-SHA1jsOAuth only supports HMAC-SHA1
realmstring   
requestTokenUrlstringRequired for 3-legged requests  
authorizationUrlstringRequired for 3-legged requests  
accessTokenUrlstringRequired for 3-legged requests  
enablePrivilegeboolean falseAllows you to put Firefox into a Cross domain requests enabled mode*

* Should only be used for testing

Usage

	
var config = {
    consumerKey: 'MY-KEY',
    consumerSecret: 'MY-SECRET'
};

var oauth = OAuth(config);

get

Performs a GET request

Parameters

  1. url
    string
  2. success
    function
  3. failure
    function

Usage


function success(data) {
	alert('Success ' + data.text);
}

function failure(data) {
	alert('Something bad happened! :(');
}
		
oauth.get('http://www.example.com/person/1', success, failure);

post

Performs a POST request

Parameters

  1. url
    string
  2. data
    object
  3. success
    function
  4. failure
    function

Usage


function success(data) {
	alert('Success ' + data.text);
}

function failure(data) {
	alert('Something bad happened! :(');
}

var data = {
	name: 'Darth Vader',
	age: 43
};
		
oauth.post('http://www.example.com/person/edit/1', data, success, failure);

getJSON

Performs a GET request and parses JSON. Requires a JSON library

Parameters

  1. url
    string
  2. success
    function
  3. failure
    function

Usage


function success(data_object) {
	alert('Name: ' + data_object.name);
}

function failure(data) {
	alert('Something bad happened! :(');
}
		
oauth.getJSON('http://www.example.com/person/1', success, failure);

request

Performs a request based on the configuration you give. More flexible than the previous request methods as you can specify additional headers.

Parameters

  1. options
    object
ParameterValueRequiredDefaultNotes
methodstring GET 
urlstringtrue  
dataobject   
headersobject   
successfunction   
failurefunction   

Usage


function success(data) {
	alert('Name: ' + data.text);
}

function failure(data) {
	alert('Something bad happened! :(');
}

var options = {
	method: 'POST';
	url: 'http://www.example.com/person/edit/2',
	success: success,
	failure: failure,
	headers: {
		'X-Do-Not-Track': 1
	},
	data: {
		'name': 'Luke Skywalker',
		'age': '18'
	}
};
		
oauth.request(options);