jwt-mock-server
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "jwt-mock-server", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Start a mock jwt authentication server for local development", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -21,2 +21,3 @@ ## A JWT mock server for local development | ||
get a jwt token and pass claims in post body | ||
```shell | ||
@@ -28,2 +29,8 @@ curl --location --request POST 'localhost:9000/jwt/token' \ | ||
get a jwt using get and pass claims in query params: | ||
```shell | ||
curl --location --request GET 'localhost:9000/jwt/token?username=abc@test.com.au&authorities=AUTH_WP&authorities=AUTH_WP2' \ | ||
--header 'Content-Type: application/json' | ||
``` | ||
shutdown the server gracefully | ||
@@ -30,0 +37,0 @@ ```shell |
@@ -27,6 +27,6 @@ var express = require('express'); | ||
var token = await new Promise((resolve) => { | ||
jose.JWS.createSign({ alg: 'RS256', format: 'compact' }, key). | ||
update(JSON.stringify(req.body)). | ||
final(). | ||
then(function(result) { | ||
jose.JWS.createSign({ alg: 'RS256', format: 'compact' }, key) | ||
.update(JSON.stringify(req.body)) | ||
.final() | ||
.then(function(result) { | ||
resolve(result); | ||
@@ -39,3 +39,21 @@ }); | ||
router.get('/token', async function(req, res) { | ||
var keys = await getKeyStore(); | ||
var key = keys.all()[0]; | ||
var body = req.query; | ||
body["iat"] = Math.floor(Date.now() / 1000); | ||
body["exp"] = Math.floor(Date.now() / 1000) + 3600; | ||
var token = await new Promise((resolve) => { | ||
jose.JWS.createSign({ alg: 'RS256', format: 'compact' }, key) | ||
.update(JSON.stringify(body)) | ||
.final() | ||
.then(function(result) { | ||
resolve(result); | ||
}); | ||
}); | ||
res.json({token: token}); | ||
}); | ||
module.exports = router; |
6136
76
38