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, [errorClass])
serviceToken
Constructor will throw an error if no service token is passed
errorClass
By default, uses FB
Extending
class FBMyClient extends FBJWTClient {
constructor (serviceToken, myVar) {
super(serviceToken)
this.myVar = myVar
}
}
const myClient = new FBMyClient('service token', 'my var')
class FBAnotherClient extends FBJWTClient {
constructor (serviceToken) {
class FBAnotherClientError extends FBJWTClient.prototype.ErrorClass {}
super(serviceToken, FBAnotherClientError)
super(serviceToken)
}
}
Methods
-
generateAccessToken
Generate JWT access token
-
getEndpointUrl
Create 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.