Form Builder JSON Web Token client (Node)
Base client for making requests to Form Builder platform endpoints that require JSON Web Tokens for authenctication
Requirements
Node
Installation
npm install @ministryofjustice/fb-jwt-client-node
Usage
Loading and initialising
const FBJWTClient = require('@ministryofjustice/fb-jwt-client-node')
const jwtClient = new FBJWTClient(serviceToken, serviceUrl, [errorClass])
serviceToken
Constructor will throw an error if no service token is passed
serviceUrl
Constructor will throw an error if no service url is passed
errorClass
By default, uses FB
Extending
class FBMyClient extends FBJWTClient {
constructor (serviceToken, serviceUrl, myVar) {
super(serviceToken)
this.myVar = myVar
}
}
const myClient = new FBMyClient('service token', 'http://myservice', 'my var')
class FBAnotherClient extends FBJWTClient {
constructor (serviceToken, serviceUrl) {
class FBAnotherClientError extends FBJWTClient.prototype.ErrorClass {}
super(serviceToken, serviceUrl, FBAnotherClientError)
super(serviceToken)
}
}
Methods
-
generateAccessToken
Generate JWT access token
-
createEndpointUrl
Return user-specific endpoint
-
sendGet
Handle client get requests
-
sendPost
Handle client post requests
-
encrypt
Encrypt data with AES 256
-
decrypt
Decrypt data
-
handleRequestError
Handle client response errors
-
createRequestOptions
Create request options
-
throwRequestError
Convenience function for throwing errors
See documentation in code for further details and fb-user-datastore-client-node
and fb-submitter-client-node
for examples.