Socket
Socket
Sign inDemoInstall

jwt-mock-server

Package Overview
Dependencies
7
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.2 to 0.0.3

2

app.js
var createError = require('http-errors');
var express = require('express');
var cors = require('cors');
var path = require('path');

@@ -14,2 +15,3 @@ var logger = require('morgan');

app.use(express.urlencoded({ extended: false }));
app.use(cors());

@@ -16,0 +18,0 @@ app.use('/jwt', indexRouter);

10

package.json
{
"name": "jwt-mock-server",
"version": "0.0.2",
"version": "0.0.3",
"description": "Start a mock jwt authentication server for local development",

@@ -18,7 +18,8 @@ "keywords": [

"dependencies": {
"cors": "^2.8.5",
"debug": "~2.6.9",
"express": "~4.16.1",
"http-errors": "~1.6.3",
"jsonwebtoken": "latest",
"morgan": "~1.9.1",
"jsonwebtoken": "latest",
"node-jose": "latest"

@@ -33,4 +34,5 @@ },

"main": "bin/www",
"bin": { "start": "bin/www"}
"bin": {
"start": "bin/www"
}
}

@@ -34,2 +34,12 @@ ## A JWT mock server for local development

or you can get the default claims, the default claims needs to be passed when you start the server
```shell
npx --package github:ruiyang/jwt-mock-server start --claims '{"username": "test-user@test.com"}'
curl --location --request GET 'localhost:9000/jwt/token' \
--header 'Content-Type: application/json'
```
shutdown the server gracefully

@@ -36,0 +46,0 @@ ```shell

@@ -38,8 +38,22 @@ var express = require('express');

function getDefaultJwtClaim() {
var index = process.argv.indexOf("--claims");
var args = process.argv.slice(index + 1);
if (args.length > 0) {
return JSON.parse(args[0]);
} else {
return undefined;
}
}
router.get('/token', async function(req, res) {
var keys = await getKeyStore();
var key = keys.all()[0];
var body = req.query;
var body = Object.keys(req.query).length > 0 ? req.query : getDefaultJwtClaim();
console.log(req.query);
body["iat"] = Math.floor(Date.now() / 1000);
body["exp"] = Math.floor(Date.now() / 1000) + 3600;
var token = await new Promise((resolve) => {

@@ -46,0 +60,0 @@ jose.JWS.createSign({ alg: 'RS256', format: 'compact' }, key)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc