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

simple-oauth2

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-oauth2 - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

lib/client/password.js

31

lib/core.js

@@ -6,9 +6,10 @@ var exports = module.exports,

//
// Core module.
//
module.exports = function(config) {
var errors = require("./error.js")();
// High level method to call API

@@ -50,5 +51,3 @@ function api(method, path, params, callback) {

if (response.statusCode >= 500) body = errorResponse(response);
if (response.statusCode >= 400) return callback(new HTTPError(body), null)
if (response.statusCode >= 400) return callback(new errors.HTTPError(response.statusCode), null)
callback(error, body);

@@ -58,23 +57,2 @@ }

// 500 Error response
function errorResponse(response) {
return { "status": response.statusCode,
"request": response.request.uri.href,
"error": {
"code": "notifications.service.not_working",
"description": "Lelylan is not working correctly (we are investigating)."
}
}
}
// Personalized errror
function HTTPError(message) {
Error.call(this);
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
this.message = message;
} HTTPError.prototype.__proto__ = Error.prototype;
function isEmpty(ob){

@@ -90,4 +68,3 @@ for(var i in ob){ return false;}

'api': api,
'HTTPError': HTTPError
}
};

@@ -42,4 +42,5 @@ //

'AuthCode': require('./client/auth-code')(config),
'AccessToken': require('./client/access-token')(config),
'Password': require('./client/password')(config),
'AccessToken': require('./client/access-token')(config)
}
};
{
"name": "simple-oauth2",
"version": "0.1.0",
"version": "0.1.1",
"description": "Node.js client for OAuth2",

@@ -5,0 +5,0 @@ "author": "Andrea Reginato <andrea.reginato@gmail.com>",

@@ -64,2 +64,3 @@ # Simple OAuth2

```javascript
// Authorization code flow

@@ -71,2 +72,3 @@ var uri = OAuth2.AuthCode.authorizeURL({ redirect_uri: 'http://localhost:3000/callback');

var token = OAuth2.Password.getToken({ username: 'username', 'password': 'password' }, callback);
```

@@ -76,2 +78,3 @@ If the functions fails an error object is passed as first argument to the callback.

## Errors

@@ -85,3 +88,4 @@

Through the error message attribute you can access the JSON representation.
Through the error message attribute you can access the JSON representation
based on HTTP `status` and error `message`.

@@ -88,0 +92,0 @@ ```javascript

@@ -9,3 +9,3 @@ var credentials = { client: { id: 'client-id', secret: 'client-secret', site: 'https://example.org' } },

describe.only('OAuth2.AccessToken',function() {
describe('OAuth2.AccessToken',function() {

@@ -12,0 +12,0 @@ beforeEach(function(done) {

var credentials = { client: { id: 'client-id', secret: 'client-secret', site: 'https://example.org' } },
OAuth2 = require('./../lib/simple-oauth2.js')(credentials),
qs = require('querystring'),
nock = require('nock');

@@ -5,0 +4,0 @@

@@ -1,96 +0,58 @@

//var Lelylan = require('./../lib/lelylan-node.js')({ 'token': '5f7fb8f11b8499b' });
//var nock = require('nock');
//var request, response, error;
var credentials = { client: { id: 'client-id', secret: 'client-secret', site: 'https://example.org' } },
OAuth2 = require('./../lib/simple-oauth2.js')(credentials),
nock = require('nock');
//describe('Lelylan Error',function() {
var request, result, error;
//describe('with status code 500',function() {
describe('Simple OAuth2 Error',function() {
//beforeEach(function(done) {
//request = nock('http://api.lelylan.com').get('/devices/1').reply(500, 'Internal Server Error');
//done();
//})
describe('with status code 401',function() {
//beforeEach(function(done) {
//Lelylan.Device.find('1', function(e, r) {
//error = e; response = r; done();
//})
//})
beforeEach(function(done) {
var params = { 'code': 'code', 'redirect_uri': 'http://callback.com', 'grant_type': 'authorization_code' };
request = nock('https://example.org:443').post('/oauth/token', params).reply(401, 'Unauthorized');
done();
});
//it('makes the HTTP request', function() {
//request.isDone();
//});
beforeEach(function(done) {
var params = { 'code': 'code', 'redirect_uri': 'http://callback.com' }
OAuth2.AuthCode.getToken(params, function(e, r) {
error = e; result = r; done();
});
});
//it('return a json array',function() {
//error.should.be.a('object');
//});
//});
it('makes the HTTP request', function() {
request.isDone();
});
//describe('with status code 401',function() {
it('returns an access token',function() {
error.message.message.should.eql('Unauthorized');
});
});
//beforeEach(function(done) {
//request = nock('http://api.lelylan.com').get('/devices/1').replyWithFile(401, __dirname + '/fixtures/errors/401.json');
//done();
//})
describe('with status code 500',function() {
//beforeEach(function(done) {
//Lelylan.Device.find('1', function(e, r) {
//error = e; response = r; done();
//})
//})
beforeEach(function(done) {
var params = { 'code': 'code', 'redirect_uri': 'http://callback.com', 'grant_type': 'authorization_code' };
request = nock('https://example.org:443').post('/oauth/token', params).reply(500, 'Server Error');
done();
});
//it('makes the HTTP request', function() {
//request.isDone();
//});
beforeEach(function(done) {
var params = { 'code': 'code', 'redirect_uri': 'http://callback.com' }
OAuth2.AuthCode.getToken(params, function(e, r) {
error = e; result = r; done();
});
});
//it('return a json array',function() {
//error.should.be.a('object');
//});
//});
it('makes the HTTP request', function() {
request.isDone();
});
//describe('with status code 404',function() {
it('returns an access token',function() {
error.message.message.should.eql('Internal Server Error');
});
});
})
//beforeEach(function(done) {
//request = nock('http://api.lelylan.com').get('/devices/1').replyWithFile(404, __dirname + '/fixtures/errors/404.json');
//done();
//})
//beforeEach(function(done) {
//Lelylan.Device.find('1', function(e, r) {
//error = e; response = r; done();
//})
//})
//it('makes the HTTP request', function() {
//request.isDone();
//});
//it('return a json array',function() {
//error.should.be.a('object');
//});
//});
//describe('with status code 422',function() {
//beforeEach(function(done) {
//request = nock('http://api.lelylan.com').get('/devices/1').replyWithFile(422, __dirname + '/fixtures/errors/422.json');
//done();
//})
//beforeEach(function(done) {
//Lelylan.Device.find('1', function(e, r) {
//error = e; response = r; done();
//})
//})
//it('makes the HTTP request', function() {
//request.isDone();
//});
//it('return a json array',function() {
//error.should.be.a('object');
//});
//});
//})
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