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

restl

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

restl - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

test.js

6

changelog.md
ChangeLog
=========
0.3.3 (2017-04-27)
------------------
* #33: Support for OAuth2 Bearer token.
0.3.1 (2017-04-26)

@@ -5,0 +11,0 @@ ------------------

24

lib/client.js

@@ -49,8 +49,16 @@ var url = require('url');

if (this.auth && this.auth.type === 'basic') {
// The request library wants a user and pass property.
options.auth = {
user: this.auth.userName,
pass: this.auth.password
};
if (this.auth) {
switch (this.auth.type) {
case 'basic' :
options.auth = {
user: this.auth.userName,
pass: this.auth.password
};
break;
case 'bearer' :
options.auth = {
bearer: this.auth.token
};
break;
}
}

@@ -134,2 +142,6 @@

request.headers.set('Authorization', 'Basic ' + new Buffer(this.auth.userName + ':' + this.auth.password).toString('base64'));
break;
case 'bearer' :
request.headers.set('Authorization', 'Bearer ' + this.auth.token);
break;

@@ -136,0 +148,0 @@ }

{
"name": "restl",
"version": "0.3.1",
"version": "0.3.2",
"description": "Opiniated HAL client.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -16,3 +16,4 @@ {

"redirect" : { "href" : "/redirect" },
"auth-basic" : { "href" : "/auth/basic" }
"auth-basic" : { "href" : "/auth/basic" },
"auth-bearer" : { "href" : "/auth/bearer" }
},

@@ -19,0 +20,0 @@ "title" : "Hal 1",

@@ -10,3 +10,4 @@ {

"echo": { "href" : "/echo" },
"auth-basic" : { "href" : "/auth/basic" }
"auth-basic" : { "href" : "/auth/basic" },
"auth-bearer" : { "href" : "/auth/bearer" }
},

@@ -13,0 +14,0 @@ "title" : "Hal 1",

@@ -81,4 +81,20 @@ const Client = require('../../lib/client');

it('should understand the auth.bearer setting');
it('should understand the auth.bearer setting', async() => {
client.auth = {
type: 'bearer',
token: 'foo'
};
const result = await (await resource.follow('headerTest')).request({
auth: {
bearer: 'foo'
},
});
expect(result.body).to.have.property('authorization');
expect(result.body.authorization).to.eql('Bearer foo');
});
it('should allow posting json', async() => {

@@ -85,0 +101,0 @@

@@ -73,2 +73,16 @@ const Koa = require('koa');

);
app.use(
route('/auth/bearer')
.get(ctx => {
const encoded = 'Bearer foo';
if (!ctx.request.headers.authorization || ctx.request.headers.authorization!==encoded) {
ctx.response.status = 401;
ctx.response.body = '';
ctx.response.set('Authorization', 'Bearer');
} else {
ctx.response.body = { ok: true };
ctx.response.status = 200;
}
})
);

@@ -75,0 +89,0 @@ // Rest stuff!

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