0

My problem is exactly same as this one.

The fact is, it's answer didn't worked for me. It is still showing "wrong code".

{ message: 'Access denied: Invalid token, wrong code' }

headers are

headers: {
      'Content-Type': 'application/json',
      Authorization: 'Basic bW9oaXRrdW1hcnNpbmdoMTIzNDRAZ21haWwuY29tOjE1NDg3NjY3Njg='
}

Here is the code used

import axios from 'axios';
import base64 from 'base-64';
import utf8 from 'utf8';

import { totp } from 'otplib';


const reqJSON =
{
    github_url: GITHUB_URL,
    contact_email: EMAIL
}
const stringData = JSON.stringify(reqJSON);

const URL = API_URL;
const sharedSecret = reqJSON.contact_email + "SOME_STRING";

totp.options = { digits: 10, algorithm: "sha512", epoch: 0 }

const myTotp = totp.generate(sharedSecret);
const isValid = totp.check(myTotp, sharedSecret);

console.log("Token Info:", { myTotp, isValid });




const authStringUTF = reqJSON.contact_email + ":" + myTotp;
const bytes = utf8.encode(authStringUTF);
const encoded = base64.encode(bytes);

console.log('encoded ->', encoded);



const createReq = async () => {
    try {
        const config = {
            headers: {
                'Content-Type': 'application/json',
                'Authorization': "Basic " + encoded
            }
        };

        console.log("Making req", { URL, reqJSON, config });

        const res = await axios.post(URL, stringData, config);
        console.log(res.data);
    }
    catch (err) {
        console.error(err.response.data);
    }
};

createReq();

EDIT - Added current code for generating Basic HTTP RFC2617 Authentication Code

Thanks you so much!

  • How are you generating it now? – Evert Feb 14 '23 at 16:51
  • @Evert Added current code in use – ʍօɦɨȶ ӄʊʍǟʀ ֆɨռɢɦ Feb 14 '23 at 18:00
  • The specific thing you're trying to do is not just HTTP Basic auth. It's some other protocol specific to the service you are trying to interact with. You should share what that service is and include a link to their documentation. I don't see anything obviously wrong, but it's hard to know what they expect to receive. – Evert Feb 14 '23 at 19:01

0 Answers0