Comparing version 0.3.1 to 0.3.2
ChangeLog | ||
========= | ||
0.3.3 (2017-04-27) | ||
------------------ | ||
* #33: Support for OAuth2 Bearer token. | ||
0.3.1 (2017-04-26) | ||
@@ -5,0 +11,0 @@ ------------------ |
@@ -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! |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42351
29
1007