Package Exports
- oauth-1.0a
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (oauth-1.0a) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
oauth-1.0a
OAuth 1.0a Request Authorizer for Node and Browser
Send OAuth request with your favorite HTTP client (request, jQuery.ajax...)
Quick Start
Setup
var oauth = new OAuth({
consumer: {
public: '<your consumer key>',
secret: '<your consumer secret>'
},
signature_method: '<signature method>' //HMAC-SHA1 or PLAINTEXT ...
});
Get OAuth request data then you can use with your http client easily :)
oauth.authorizer(request, token);
Or if you want to get as a header key-value data
oauth.toHeader(oauth_data);
##Installation
###Node.js $ npm install oauth-1.0a
###Browser Download oauth-1.0a.js here
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/hmac-sha1.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js"></script>
<script src="oauth-1.0a.js"></script>
##Examples
###Work with request (Node.js)
Depencies
var request = require('request');
var OAuth = require('oauth-1.0a');
Init
var oauth = new OAuth({
consumer: {
public: 'xvz1evFS4wEEPTGEFPHBog',
secret: 'kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw'
},
signature_method: 'HMAC-SHA1'
});
Your request data
var request_data = {
url: 'https://api.twitter.com/1/statuses/update.json?include_entities=true',
method: 'POST',
data: {
status: 'Hello Ladies + Gentlemen, a signed OAuth request!'
}
};
Your token
var token = {
public: '370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb',
secret: 'LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE'
};
Call a request
request({
url: request_data.url,
method: request_data.method,
data: oauth.authorizer(request_data, token)
}, function(error, response, body) {
//process your data here
});
Or if you want to send OAuth data as header
request({
url: request_data.url,
method: request_data.method,
data: request_data.data,
header: oauth.toHeader(oauth.authorizer(request_data, token))
}, function(error, response, body) {
//process your data here
});
###Work with jQuery.ajax (Browser)
Init
var oauth = new OAuth({
consumer: {
public: 'xvz1evFS4wEEPTGEFPHBog',
secret: 'kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw'
},
signature_method: 'HMAC-SHA1'
});
Your request data
var request_data = {
url: 'https://api.twitter.com/1/statuses/update.json?include_entities=true',
method: 'POST',
data: {
status: 'Hello Ladies + Gentlemen, a signed OAuth request!'
}
};
Your token
var token = {
public: '370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb',
secret: 'LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE'
};
Call a request
$.ajax({
url: request_data.url,
type: request_data.method,
data: oauth.authorizer(request_data, token)
}).done(function(data) {
//process your data here
});
Or if you want to send OAuth data as header
$.ajax({
url: request_data.url,
type: request_data.method,
data: request_data.data,
header: oauth.toHeader(oauth.authorizer(request_data, token))
}).done(function(data) {
//process your data here
});
##Notes
If you want a easier way to handle your OAuth request. Please visit SimpleOAuth, it's a wrapper of this project, some features:
- Request Token method
- Get Authorize link method
- Access Token method
- OAuth 2.0 support
- Simpler syntax:
Node.js:
request(simple_oauth.do({
method: 'GET',
url: 'https://api.twitter.com/1.1/statuses/user_timeline.json',
}, function(error, response, body) {
//process your data here
});
jQuery:
$.ajax(simple_oauth.do({
method: 'GET',
url: 'https://api.twitter.com/1.1/statuses/user_timeline.json',
}.done(function(data) {
//process your data here
});
##Todo
- RSA-SHA1 signature method
##Depencies