Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ministryofjustice/fb-jwt-client-node

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ministryofjustice/fb-jwt-client-node - npm Package Compare versions

Comparing version 0.0.14 to 0.0.15-alpha

43

lib/fb-jwt-client.js

@@ -20,2 +20,5 @@ const request = require('request-promise-native')

*
* @param {string} serviceSecret
* Service secret
*
* @param {string} serviceToken

@@ -35,6 +38,9 @@ * Service token

**/
constructor (serviceToken, serviceSlug, microserviceUrl, errorClass) {
constructor (serviceSecret, serviceToken, serviceSlug, microserviceUrl, errorClass) {
if (errorClass) {
this.ErrorClass = errorClass
}
if (!serviceSecret) {
this.throwRequestError('ENOSERVICESECRET', 'No service secret passed to client')
}
if (!serviceToken) {

@@ -50,2 +56,3 @@ this.throwRequestError('ENOSERVICETOKEN', 'No service token passed to client')

this.serviceSecret = serviceSecret
this.serviceToken = serviceToken

@@ -119,2 +126,36 @@ this.serviceUrl = microserviceUrl

/**
* Encrypt user ID and token using service secret
*
* Guaranteed to return the same value
*
* @param {string} userId
* User ID
*
* @param {string} userToken
* User token
*
* @return {string}
*
**/
encryptUserIdAndToken (userId, userToken) {
const serviceSecret = this.serviceSecret
const ivSeed = userId + userToken
return this.encrypt(serviceSecret, {userId, userToken}, ivSeed)
}
/**
* Decrypt user ID and token using service secret
*
* @param {string} encryptedData
* Encrypted user ID and token
*
* @return {object}
*
**/
decryptUserIdAndToken (encryptedData) {
const serviceSecret = this.serviceSecret
return this.decrypt(serviceSecret, encryptedData)
}
/**
* Create user-specific endpoint

@@ -121,0 +162,0 @@ *

15

lib/fb-jwt-client.unit.spec.js

@@ -14,2 +14,3 @@ const test = require('tape')

const serviceSlug = 'testServiceSlug'
const serviceSecret = 'testServiceSecret'
const serviceToken = 'testServiceToken'

@@ -55,12 +56,16 @@ const microserviceUrl = 'https://microservice'

test('When instantiating client without a service secret', t => {
testInstantiation(t, [], 'ENOSERVICESECRET', 'No service secret passed to client')
})
test('When instantiating client without a service token', t => {
testInstantiation(t, [], 'ENOSERVICETOKEN', 'No service token passed to client')
testInstantiation(t, [serviceSecret], 'ENOSERVICETOKEN', 'No service token passed to client')
})
test('When instantiating client without a service slug', t => {
testInstantiation(t, [serviceToken], 'ENOSERVICESLUG', 'No service slug passed to client')
testInstantiation(t, [serviceSecret, serviceToken], 'ENOSERVICESLUG', 'No service slug passed to client')
})
test('When instantiating client without a service url', t => {
testInstantiation(t, [serviceToken, serviceSlug], 'ENOMICROSERVICEURL', 'No microservice url passed to client')
testInstantiation(t, [serviceSecret, serviceToken, serviceSlug], 'ENOMICROSERVICEURL', 'No microservice url passed to client')
})

@@ -73,3 +78,3 @@

try {
const jwtClient = new FBJWTClient(null, microserviceUrl, serviceSlug, MyError) // eslint-disable-line no-unused-vars
const jwtClient = new FBJWTClient(null, serviceToken, serviceSlug, microserviceUrl, MyError) // eslint-disable-line no-unused-vars
} catch (e) {

@@ -81,3 +86,3 @@ t.equal(e.name, 'MyError', 'it should use the error class passed')

// Set up a client to test the methods
const jwtClient = new FBJWTClient(serviceToken, serviceSlug, microserviceUrl)
const jwtClient = new FBJWTClient(serviceSecret, serviceToken, serviceSlug, microserviceUrl)

@@ -84,0 +89,0 @@ // Endpoint URLs

{
"name": "@ministryofjustice/fb-jwt-client-node",
"version": "0.0.14",
"version": "0.0.15-alpha",
"description": "Form Builder JSON Web Token Client (Node)",
"main": "index.js",
"main": "lib/fb-jwt-client.js",
"repository": {

@@ -7,0 +7,0 @@ "type": "git",

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