JavaScript SDK
Learn how to use the Keyfax Web API JavaScript SDK.
The Keyfax Web API JavaScript SDK is a self-contained JavaScript file with no external dependencies. To use the Keyfax Web API JavaScript SDK you'll need to include the Keyfax JavaScript SDK within your web pages. The following script tag should be placed towards the bottom of pages that wish to utilitize the Keyfax Web API JavaScript SDK....
We would recommend copying and linking to this file locally within your integration and avoid linking to this file externally.
To ensure your Keyfax API signing key is never revealed to end users client side requests into the Keyfax Web API must use a JSON Web Token or JWT for verification - this is also true for our JavaScript SDK. You cannot use your API key or Signing key when using the JavaScript Web API SDK and instead need to use a JSON Web Token to verify requests.
The JWT required for client side verification should be first obtained via a secure server side call to GET /api/v1/token
. This server side call will require your Keyfax Web API key and Signing key. Once the JSON Web Token has been obtained via server side code it can then be shared with the client to verify subsequent client side requests into the Keyfax Web API.
Obtaining the JSON Web Token via secure server side code is easy using the Keyfax Web API .NET SDK as shown in the following C# code example...
The generated JSON Web Token will only be valid for 24 hours after creation. For long running client side sessions you should use the JSON Web Token generated by the server side call to GET /api/v1/token
to call POST /api/v1/token
on the client side to periodically generate a new JSON Web Token. See "Renewing the JSON Web Token" within this guide.
Once you've obtained a valid JSON Web Token via server side code you can then share this with the client and configure the Keyfax Web API JavaScript SDK as shown below...
You'll notice in the example above our server side code added the JSON Web Token to a hidden form field called txtHiddenJWTField
. We then retrieve the token stored within this hidden form field via client side code to configure the Keyfax Web API JavaScript SDK. There are many ways to share content generated on the server with the client but in this example to keep things simple we used a hidden form field to store the JSON Web Token.
Once the Keyfax Web API JavaScript SDK has been configured with the URL, host name & JSON Web Token as shown above you can then use the methods provided by the Keyfax Web API JavaScript SDK to make verified requests into the Keyfax Web API.
Launching Keyfax
IMPORTANT The start -up data you provide to Keyfax should be customized to suit your environment & integration. The start -up data presented in these examples is minimal and for demonstration purposes only. Please contact Omfax Systems for assistance with configuring your start -up data to fully leverage the intelligent scripting features offered by Keyfax.
The following JavaScript shows how you can obtain Keyfax launch data via client side JavaScript code upon a button click...
Obtaining Keyfax Results
The JavaScript below shows how to check for results for a previously launched Keyfax session using the Keyfax Web API JavaScript SDK when a button is clicked...
Renewing the JSON Web Token
Renewing the JSON Web Token is made easy using the Keyfax Web API JavaScript SDK and is just a few lines of code as shown below. By default the JSON Web Token expires after 24 hours. If you expect clients to remain within your browser application for more than 24 hours you may wish to periodically call this code to issue clients with a new token.
For this request to succeed the current JSON Web Token supplied within the Authorization
header to POST /api/v1/token
must still be valid. If the current JSON Web Token has expired this request will fail returning a 401 Unauthorized response.
Error Handling with the Keyfax Web API JavaScript SDK
Developers can use the onError
method as shown below to handle any exceptions that may be thrown by the Keyfax Web API JavaScript SDK...
Available SDK Methods
A brief summary of each method available within the Keyfax Web API JavaScript SDK is provided below.
startup.get
(GET /api/v1/startup
) Returns minimal example start-up data for the current master configuration.startup.post
(POST /api/v1/startup
) Post start-up data to Keyfax to obtain launch results.results.post
(POST /api/v1/results
) Post launch results to Keyfax to obtain diagnostic results.token.post
(POST /api/v1/token
) Renews a JSON Web Token given a currently valid JSON Web Token.key.get (
GET /api/v1/key
) Obtain initial API & Signing Keys for authentication.
Last updated
Was this helpful?