hapi-auth-jwt2
Advanced tools
Comparing version 5.2.0 to 5.2.1
@@ -74,3 +74,4 @@ var Boom = require('boom'); // error handling https://github.com/hapijs/boom | ||
else { | ||
return reply.continue({ credentials: credentials || decoded }); | ||
request.auth.token = token; | ||
return reply.continue({ credentials: credentials || decoded, artifacts: token }); | ||
} | ||
@@ -77,0 +78,0 @@ }); |
{ | ||
"name": "hapi-auth-jwt2", | ||
"version": "5.2.0", | ||
"version": "5.2.1", | ||
"description": "Hapi.js Authentication Plugin/Scheme using JSON Web Tokens (JWT)", | ||
@@ -40,3 +40,3 @@ "main": "lib/index.js", | ||
"aguid": "^1.0.3", | ||
"hapi": "^11.0.3", | ||
"hapi": "^11.0.5", | ||
"codeclimate-test-reporter": "^0.1.1", | ||
@@ -43,0 +43,0 @@ "istanbul": "^0.4.0", |
@@ -7,5 +7,5 @@ # Hapi Auth with JSON Web Tokens (JWT) | ||
[](https://travis-ci.org/dwyl/hapi-auth-jwt2) | ||
[](https://codeclimate.com/github/dwyl/hapi-auth-jwt2) | ||
[](https://codecov.io/github/dwyl/hapi-auth-jwt2?branch=master) | ||
[](https://codeclimate.com/github/dwyl/hapi-auth-jwt2) | ||
[](http://hapijs.com) | ||
[](http://hapijs.com) | ||
[](http://nodejs.org/download/) | ||
@@ -244,2 +244,14 @@ [](https://www.npmjs.com/package/hapi-auth-jwt2) | ||
## Want to access the JWT token after validation? | ||
[@mcortesi](https://github.com/mcortesi) requested the ability to | ||
[access the JWT token](https://github.com/dwyl/hapi-auth-jwt2/issues/55) used for authentication. | ||
We added support for that. You can access the extracted JWT token in your handler or any other function | ||
within the request lifecycle with the `request.auth.token` property. | ||
Take in consideration, that this is the *encoded token*, and it's only useful if you want to use to make | ||
request to other servers using the user's token. For information inside the token, just use the | ||
`request.auth.credentials` property. | ||
## Want to send/store your JWT in a Cookie? | ||
@@ -246,0 +258,0 @@ |
@@ -32,2 +32,6 @@ var Hapi = require('hapi'); | ||
var sendToken = function(req, reply) { | ||
return reply(req.auth.token); | ||
}; | ||
server.register(require('../'), function () { | ||
@@ -43,2 +47,3 @@ | ||
{ method: 'GET', path: '/', handler: home, config: { auth: false } }, | ||
{ method: 'GET', path: '/token', handler: sendToken, config: { auth: 'jwt' } }, | ||
{ method: 'POST', path: '/privado', handler: privado, config: { auth: 'jwt' } }, | ||
@@ -45,0 +50,0 @@ { method: 'POST', path: '/required', handler: privado, config: { auth: { mode: 'required', strategy: 'jwt' } } }, |
@@ -331,1 +331,18 @@ var test = require('tape'); | ||
}); | ||
test("Scheme should set token in request.auth.token", function(t) { | ||
// use the token as the 'authorization' header in requests | ||
var token = JWT.sign({ id: 123, "name": "Charlie" }, secret); | ||
var options = { | ||
method: "GET", | ||
url: "/token", | ||
headers: { authorization: "Bearer " + token } | ||
}; | ||
// server.inject lets us similate an http request | ||
server.inject(options, function(response) { | ||
// console.log(" - - - - RESPONSE: ") | ||
// console.log(response.result); | ||
t.equal(response.result, token, 'Token is accesible from handler'); | ||
t.end(); | ||
}); | ||
}); |
74204
1372
448