Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
Retrieve access_token from console log using Mocha

I can get the entire response log using console.log(res) but can't retrieve access_token from it. The response containing access_token looks like this:

    accept: [Array],
      'content-length': [Array]
    }
  },
  text: '{"access_token":"eyJhbGciOiJS....

I've tried the following:

 .end(  function (res, err, access_token, refresh_token) {
      
       if (err) console.error(err);
       else {
      
      console.log(res)
      expect(res).to.have.status(200);
       
       //console.log(res.body)
       const token = JSON.stringify.access_token;
      // token = res.access_token;
       console.log(token)

      //  let accessToken = await auth.getAccessToken();
      //  console.log(accessToken);
      //  assert(accessToken != null, 'token is null');
       

       //var token = body.access_token
       //console.log(token + "see on token");
      // console.log(`options.access_token: ${options.access_token}`);

This is what I'm getting

UPDATE: By using the below code, parsing and using stringify I'm able to log out the token, but I'm still not able to use the parsed in the next request as header, getting undefined

chai.request(uaaUrl)
.post('/oauth/token')
.set('Content-Type', 'application/x-www-form-urlencoded')
.set('Accept', '*/*',)
   .send(Authuser)   
   .end(function(err, res, body) {      
       const eurotoken = JSON.parse(JSON.stringify(res.body.access_token));
       console.log('parsedd token', eurotoken);
       expect(res).to.have.status(200)
       done();
})




it('./health', (done) => {
    let eurotoken;
      chai.request(euro_url)
          .get('/request-statuses')
          .set('Content-Type', 'application/x-www-form-urlencoded')
          .set('Accept', '*/*',)
          .set('Authorization', `Bearer ${eurotoken}` )
          .end(  function (res, err, body) {  
          if (err) console.error(err);
          else {
            expect(res).to.have.status(200)           
            done();
               }
            done();
        })
        });
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!