I’m having trouble with a secure iparam used for authentication to an external API.
My iparams.json file looks like this:’
{
"apiKey": {
"display_name": "API Key",
"type": "text",
"required": true,
"secure": true,
"visible": true
}
}
My code where I use the api key looks like this:
const headers = {
"Authorization": "Bearer <%= encode(iparam.apiKey) %>",
"Content-Type": "application/json"
};
const options = { headers: headers };
client.request.get(url, options);
When I run my app, it seems like my API is being sent to the external API encoded so it doesn’t match the API key that the endpoint is expecting.
If I change my code to look like this (removing the encode()
function), authentication is successful.
const headers = {
"Authorization": "Bearer <%= iparam.apiKey %>",
"Content-Type": "application/json"
};
const options = { headers: headers };
client.request.get(url, options);
While the above works, it doesn’t seem correct per the documentation and I’m not sure if it is secure doing it this way.