A minimal JavaScript module that enables HAWK-authenticated HTTP requests using the Innovaphone SDK's HttpClient
.
Ideal for communicating with APIs secured using the HAWK authentication protocol.
- Lightweight and dependency-free
- Designed for use with the Innovaphone App Platform / SDK
- Generates valid HAWK headers (MAC, timestamp, nonce)
- Simplifies authenticated API access
var credentials = {
id: "<HAWK-ID>", // Your Hawk ID
key: "<HAWK-KEY>" // Your shared secret key
};
var url = "<API-URL>"; // Full HTTPS URL to the resource
HawkClient.request("GET", url, credentials, function (status, response) {
if (status === 200) {
log("Response received:");
log(response);
} else {
log("Initial request failed with status " + status);
log(response);
}
});
To use this module within your Innovaphone SDK backend (JavaScript service):
-
Place
service-hawkclient.js
in your service directory, for example:/app/service/service-hawkclient.js
-
Include the module in your service script using a relative path:
include("service-hawkclient.js");
-
Use the module as needed in your service logic:
HawkClient.request("GET", url, credentials, function (status, response) { // handle response });
β This ensures that the HAWK authentication logic is cleanly separated and reusable within your Innovaphone SDK service.
This module relies on the following APIs provided by the Innovaphone JavaScript runtime:
HttpClient
β for making HTTP(S) requestsCrypto.hmac("SHA256", key)
β for HMAC generationEncoding.binToBase64()
β for base64 encodingTextDecoder("utf-8")
β for decoding binary responses
MIT License β free to use, modify, and distribute.
Created for use with the Innovaphone SDK.