Even though on postman, OCI_REST_INITIALIZATION/ONE_TIME_INITIALIZATION_CALL and OCI_REST_COLLECTION/GET_OCI_ANNOUNCEMENTS collections are working fine. But when calling from Nodejs project/program, below error response is returned.
{
"code" : "NotAuthenticated",
"message" : "The required information to complete authentication was not provided or was incorrect."
}
Below is my Nodejs code
const jwt = require('jsonwebtoken');
const fs = require('fs');
const request = require('request');
const dotenv = require('dotenv');
dotenv.config();
const vaultUrl = process.env.vaultUrl;
const secretBundleUrl = `${vaultUrl}/${process.env.secretBundle}/${process.env.vaultSecret}`;
const tenancyId = process.env.tenancyId;
const authUserId = process.env.authUserId;
const keyFingerprint = process.env.keyFingerprint;
const privateKey = fs.readFileSync('./oci_private_key.pem', 'utf8');
const header = {
alg: 'RS256',
typ: 'JWT',
kid: keyFingerprint,
};
const payload = {
iss: tenancyId,
sub: authUserId,
aud: `${vaultUrl}/${process.env.secretBundle}`,
iat: Math.floor(Date.now() / 1000),
exp: Math.floor(Date.now() / 1000) + 3600,
};
const jwtToken = jwt.sign(payload, privateKey, { header });
const options = {
method: 'GET',
url: secretBundleUrl,
headers: {
Authorization: `Bearer ${jwtToken}`,
},
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
Code output
{
"code" : "NotAuthenticated",
"message" : "The required information to complete authentication was not provided or was incorrect."
}
Thanks in advance.
can you try using oci-sdk for typescript and JavaScript and see if that works for you? https://www.npmjs.com/package/oci-sdk