@ministryofjustice/fb-jwt-client-node
Advanced tools
Comparing version 0.0.14 to 0.0.15-alpha
@@ -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 @@ * |
@@ -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", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
0
31234
9
789