Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

oauth-1.0a

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oauth-1.0a - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

33

lib/oauth-1.0a.js

@@ -60,2 +60,5 @@ if(typeof(module) !== 'undefined' && typeof(exports) !== 'undefined') {

if(!token)
token = {};
if(token.public)

@@ -105,3 +108,3 @@ oauth_data.oauth_token = token.public;

OAuth.prototype.getParameterString = function(request, oauth_data) {
var base_string_data = this.sortObject(this.percentEncodeData(this.mergeObject(oauth_data, this.mergeObject(request.data, this.deParam(request.url)))));
var base_string_data = this.sortObject(this.percentEncodeData(this.mergeObject(oauth_data, this.mergeObject(request.data, this.deParamUrl(request.url)))));

@@ -142,14 +145,9 @@ var data_str = '';

/*
Get data from url
@param {String} Url
Get data from String
@param {String} String
@return {Object} data
*/
OAuth.prototype.deParam = function(url) {
var tmp = url.split('?');
if(tmp.length === 1)
return {};
var arr = decodeURIComponent(tmp[1]).split('&');
OAuth.prototype.deParam = function(string) {
var arr = decodeURIComponent(string).split('&');
var data = {};

@@ -165,2 +163,17 @@

/*
Get data from url
@param {String} Url
@return {Object} data
*/
OAuth.prototype.deParamUrl = function(url) {
var tmp = url.split('?');
if(tmp.length === 1)
return {};
return this.deParam(tmp[1]);
};
/*
Percent Encode

@@ -167,0 +180,0 @@ @param {String}

{
"name": "oauth-1.0a",
"version": "0.0.5",
"version": "0.0.6",
"description": "OAuth 1.0a Request Authorization for Node and Browser.",

@@ -5,0 +5,0 @@ "scripts": {

@@ -14,2 +14,9 @@ oauth-1.0a

I tested on some popular OAuth 1.0a services:
* Twitter
* Flickr
* Bitbucket
* Linkedin
## Quick Start

@@ -83,3 +90,3 @@

Your token
Your token (optional for some requests)
```js

@@ -143,3 +150,3 @@ var token = {

Your token
Your token (optional for some requests)
```js

@@ -178,20 +185,25 @@ var token = {

**If you want an easier way to handle your OAuth request. Please visit [SimpleOAuth](https://github.com/ddo/SimpleOAuth), it's a wrapper of this project, some features:**
* Some OAuth requests without token use ``.authorize(request_data)`` instead of ``.authorize(request_data, {})``
* Request Token method
* Get Authorize link method
* Access Token method
* OAuth 2.0 support
* Simpler syntax:
* **If you want an easier way to handle your OAuth request. Please visit [SimpleOAuth](https://github.com/ddo/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:
```js
request(simple_oauth.do({
method: 'GET',
url: 'https://api.twitter.com/1.1/statuses/user_timeline.json'
}, function(error, response, body) {
request(oauth.requestsToken(), function(error, response, body) {
//process your data here
});
```
```js
request(oauth.accessToken({
oauth_verifier: '<verifier>'
}), function(error, response, body) {
//process your data here
});
```

@@ -201,9 +213,13 @@ jQuery:

```js
$.ajax(simple_oauth.do({
method: 'GET',
url: 'https://api.twitter.com/1.1/statuses/user_timeline.json'
}.done(function(data) {
$.ajax(oauth.requestsToken()).done(function(data) {
//process your data here
});
```
```js
$.ajax(oauth.accessToken({
oauth_verifier: '<verifier>'
})).done(function(data) {
//process your data here
});
```

@@ -228,4 +244,7 @@ ##Client Side Usage Caution

##[Changelog](https://github.com/ddo/oauth-1.0a/wiki/Changelog)
##Depencies
* Browser: [crypto-js](https://code.google.com/p/crypto-js/)
* Node: [crypto-js](https://github.com/evanvosberg/crypto-js)

@@ -5,3 +5,3 @@ var expect = require('chai').expect;

describe("Personal Consumer", function() {
describe.skip("Twitter Personal Consumer", function() {
var oauth = new OAuth({

@@ -153,2 +153,296 @@ consumer: {

});
});
describe.skip("Flickr Personal Consumer", function() {
this.timeout(10000);
var oauth = new OAuth({
consumer: {
public: 'a47d94cd0d49c24aa14e6bb3b06db5e4',
secret: 'fac91663631aaaf9'
},
signature_method: 'HMAC-SHA1'
});
describe.skip("#Request Token", function() {
var request = {
url: 'http://www.flickr.com/services/oauth/request_token',
method: 'POST',
data: {
oauth_callback: 'http://www.ddo.me'
}
};
it("should be a valid response", function(done) {
Request({
url: request.url,
method: request.method,
form: oauth.authorize(request)
}, function(err, res, body) {
expect(body).to.be.a('string');
body = oauth.deParam(body);
expect(body).to.have.property('oauth_callback_confirmed', 'true');
expect(body).to.have.property('oauth_token');
expect(body).to.have.property('oauth_token_secret');
done();
});
});
});
describe.skip("#Request Token by Header", function() {
var request = {
url: 'http://www.flickr.com/services/oauth/request_token',
method: 'POST',
data: {
oauth_callback: 'http://www.ddo.me'
}
};
it("should be a valid response", function(done) {
Request({
url: request.url,
method: request.method,
form: request.data,
headers: oauth.toHeader(oauth.authorize(request))
}, function(err, res, body) {
expect(body).to.be.a('string');
body = oauth.deParam(body);
expect(body).to.have.property('oauth_callback_confirmed', 'true');
expect(body).to.have.property('oauth_token');
expect(body).to.have.property('oauth_token_secret');
console.log(body);
console.log('http://www.flickr.com/services/oauth/authorize?oauth_token=' + token.public);
done();
});
});
});
/*
Need to get token from Request Token
And oauth_verifier after pass authorize on website
*/
describe.skip("#Access Token", function() {
//this token get from Request Token
var token = {
public: '72157639916605676-87bf560d10e0866e',
secret: 'ff89df792ef7e432'
};
var request = {
url: 'http://www.flickr.com/services/oauth/access_token',
method: 'POST',
data: {
oauth_verifier: '9d692ee8b8aa638d'
}
};
it("should be a valid response", function(done) {
Request({
url: request.url,
method: request.method,
form: oauth.authorize(request, token)
}, function(err, res, body) {
expect(body).to.be.a('string');
body = oauth.deParam(body);
expect(body).to.have.property('fullname');
expect(body).to.have.property('user_nsid');
expect(body).to.have.property('username');
expect(body).to.have.property('oauth_token');
expect(body).to.have.property('oauth_token_secret');
token.public = body.oauth_token;
token.secret = body.oauth_token_secret;
console.log(token);
console.log(body);
done();
});
});
});
/*
Need to get token from Access Token
*/
describe("#flickr.test.login", function() {
var token = {
public: '72157639924000864-a9d73f3d1d30cd85',
secret: 'e6e4e296a0bb6adb'
};
var request = {
url: 'http://api.flickr.com/services/rest/?method=flickr.test.login',
method: 'GET',
data: {
api_key: token.public,
format: 'json'
}
};
it("should be a valid response", function(done) {
Request({
url: request.url,
method: request.method,
qs: oauth.authorize(request, token)
}, function(err, res, body) {
expect(body).to.be.a('string');
expect(body).to.have.string('jsonFlickrApi');
done();
});
});
});
/*
Need to get token from Access Token
*/
describe("#flickr.test.null", function() {
var token = {
public: '72157639924000864-a9d73f3d1d30cd85',
secret: 'e6e4e296a0bb6adb'
};
var request = {
url: 'http://api.flickr.com/services/rest/?method=flickr.test.null',
method: 'GET',
data: {
api_key: token.public,
format: 'json'
}
};
it("should be a valid response", function(done) {
Request({
url: request.url,
method: request.method,
qs: oauth.authorize(request, token)
}, function(err, res, body) {
expect(body).to.be.a('string');
expect(body).to.have.string('jsonFlickrApi');
console.log(body);
done();
});
});
});
});
describe.skip("Bitbucket Personal Consumer", function() {
this.timeout(10000);
var oauth = new OAuth({
consumer: {
public: 'pQ5uxrt3demLPN8s8q',
secret: 'STZwykSSKzazP7fdxjDVfqfnABTTczWn'
},
signature_method: 'HMAC-SHA1'
});
describe("#Request Token", function() {
var request = {
url: 'https://bitbucket.org/api/1.0/oauth/request_token',
method: 'POST',
data: {
oauth_callback: 'http://www.ddo.me'
}
};
it("should be a valid response", function(done) {
Request({
url: request.url,
method: request.method,
form: oauth.authorize(request)
}, function(err, res, body) {
expect(body).to.be.a('string');
body = oauth.deParam(body);
expect(body).to.have.property('oauth_callback_confirmed', 'true');
expect(body).to.have.property('oauth_token');
expect(body).to.have.property('oauth_token_secret');
done();
});
});
});
describe("#Request Token by Header", function() {
var request = {
url: 'https://bitbucket.org/api/1.0/oauth/request_token',
method: 'POST',
data: {
oauth_callback: 'http://www.ddo.me'
}
};
it("should be a valid response", function(done) {
Request({
url: request.url,
method: request.method,
form: request.data,
headers: oauth.toHeader(oauth.authorize(request))
}, function(err, res, body) {
expect(body).to.be.a('string');
body = oauth.deParam(body);
expect(body).to.have.property('oauth_callback_confirmed', 'true');
expect(body).to.have.property('oauth_token');
expect(body).to.have.property('oauth_token_secret');
console.log(body);
done();
});
});
});
});
/*
Can not use Header
*/
describe.skip("Linkedin Personal Consumer", function() {
this.timeout(10000);
var oauth = new OAuth({
consumer: {
public: 'zbud5q8h0eac',
secret: 'BCdXJ6G9sydJqBFC'
},
signature_method: 'HMAC-SHA1'
});
describe("#Request Token", function() {
var request = {
url: 'https://api.linkedin.com/uas/oauth/requestToken',
method: 'POST',
data: {
oauth_callback: 'http://www.ddo.me'
}
};
it("should be a valid response", function(done) {
Request({
url: request.url,
method: request.method,
form: oauth.authorize(request)
}, function(err, res, body) {
expect(body).to.be.a('string');
body = oauth.deParam(body);
expect(body).to.have.property('oauth_callback_confirmed', 'true');
expect(body).to.have.property('oauth_token');
expect(body).to.have.property('oauth_token_secret');
done();
});
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc