Socket
Socket
Sign inDemoInstall

@connectedcars/jwtutils

Package Overview
Dependencies
Maintainers
3
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@connectedcars/jwtutils - npm Package Compare versions

Comparing version 1.0.9 to 1.0.10

jsconfig.json

2

bin/jwtdecode.test.js

@@ -48,3 +48,3 @@ 'use strict'

})
jwtEncode.stderr.on('data', () => {
jwtEncode.stderr.on('end', () => {
stderrStr = Buffer.concat(errorData).toString('utf8')

@@ -51,0 +51,0 @@ })

{
"name": "@connectedcars/jwtutils",
"version": "1.0.9",
"version": "1.0.10",
"description": "Zero dependency JWT encoding/decoding for Node",

@@ -28,2 +28,4 @@ "main": "src/index.js",

"devDependencies": {
"@types/mocha": "^2.2.45",
"@types/node": "^8.5.2",
"babel-eslint": "^7.2.3",

@@ -30,0 +32,0 @@ "benchmark": "^2.1.4",

@@ -135,3 +135,3 @@ # node-jwtutils

// Register the middleware
app.use(JwtAuthMiddleware(pubKeys, audiences, user => {
app.use(JwtAuthMiddleware(pubKeys, audiences, user => { // Also supports Promises and async
if (user.issuer === 'https://jwt.io/') {

@@ -138,0 +138,0 @@ if (!user.subject.match(/^[^@]+@domain\.tld$/)) {

@@ -0,1 +1,4 @@

// @ts-check
'use strict'
function base64EncodeUrlSafe(buffer) {

@@ -2,0 +5,0 @@ return buffer

@@ -0,1 +1,2 @@

// @ts-check
'use strict'

@@ -2,0 +3,0 @@

@@ -0,1 +1,2 @@

// @ts-check
'use strict'

@@ -356,3 +357,3 @@

let customJwtHeader = Object.assign({}, jwtHeader)
customJwtHeader.kid = 2
customJwtHeader.kid = '2'
let jwt = JwtUtils.encode(rsaPrivateKey, customJwtHeader, jwtBody)

@@ -359,0 +360,0 @@ try {

@@ -0,1 +1,2 @@

// @ts-check
'use strict'

@@ -20,2 +21,3 @@

}
request.user = {

@@ -28,7 +30,13 @@ audience: decodedJwtBody.aud,

}
// Handle async
let result
if (typeof mapper === 'function') {
mapper(request.user)
result = mapper(request.user, request, response)
}
return next()
if (isPromise(result)) {
result.then(() => next()).catch(e => next(e))
} else {
return next()
}
} catch (e) {

@@ -44,2 +52,10 @@ if (e instanceof JwtVerifyError) {

function isPromise(value) {
return (
typeof value === 'object' &&
value !== null &&
typeof value.then === 'function'
)
}
module.exports = jwtAuthMiddleware

@@ -0,1 +1,4 @@

// @ts-check
'use strict'
const express = require('express')

@@ -68,2 +71,12 @@ const app = express()

)
app.use(
'/async',
JwtAuthMiddleware(pubKeys, audiences, user => {
if (user.subject === 'error') {
return Promise.reject(new JwtVerifyError('Async error'))
} else {
return Promise.resolve('test')
}
})
)
app.use('/', JwtAuthMiddleware(pubKeys, audiences))

@@ -83,2 +96,5 @@ app.use((err, req, res, next) => {

})
app.get('/async', function(req, res) {
res.send(`Async response`)
})

@@ -164,2 +180,29 @@ done()

})
it('should fail with async error', () => {
let customJwtBody = Object.assign({}, jwtBody)
customJwtBody.sub = 'error'
let jwt = JwtUtils.encode(ecPrivateKey, jwtHeader, customJwtBody)
let responsePromise = doRequest('GET', 'localhost', port, '/async', {
Authorization: 'Bearer ' + jwt,
Accept: 'application/json',
'User-Agent': 'test',
'X-Error': 'Async error'
})
return expect(responsePromise, 'to be fulfilled with value satisfying', {
statusCode: 401,
data: 'Async error'
})
})
it('should success with async', () => {
let jwt = JwtUtils.encode(ecPrivateKey, jwtHeader, jwtBody)
let responsePromise = doRequest('GET', 'localhost', port, '/async', {
Authorization: 'Bearer ' + jwt,
Accept: 'application/json',
'User-Agent': 'test'
})
return expect(responsePromise, 'to be fulfilled with value satisfying', {
statusCode: 200,
data: 'Async response'
})
})
})

@@ -166,0 +209,0 @@ })

@@ -0,1 +1,2 @@

// @ts-check
'use strict'

@@ -2,0 +3,0 @@

@@ -0,1 +1,2 @@

// @ts-check
'use strict'

@@ -2,0 +3,0 @@

@@ -0,1 +1,2 @@

// @ts-check
'use strict'

@@ -2,0 +3,0 @@

@@ -0,1 +1,2 @@

// @ts-check
'use strict'

@@ -2,0 +3,0 @@

@@ -0,1 +1,2 @@

// @ts-check
'use strict'

@@ -2,0 +3,0 @@

Sorry, the diff of this file is not supported yet

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