I need to connect to an admin rest api which is protected with mfa code beside basic auth. With a simple java script I can create a MFA code from a MFA secret. However, this lib is not available and thus I can not create the MFA code.
Below is the simple code snippet that would make this work:
const { authenticator } = require('otplib');
// By default, otplib uses SHA-1, but we can override it:
authenticator.options = {
// The hash algorithm to use for the HMAC
algorithm: 'sha512',
// How many digits the TOTP code will have
digits: 6,
// The time step (in seconds) for which a TOTP code is valid
step: 30,
};
const secret = ''; // Must be in Base32
const token = authenticator.generate(secret);
return token;
Same can be used for refresh, thus mfa could be easily added to headers after being exported as a variable.