Get Access Token via Single sign on using API atuomation

17 Views Asked by At

I have login APIs where I need to generate cookies and get an Html form as a response to initiate the login process which will generate a redirect URL in HTML response I need to take it and post a request with the user name then will get an HTML response with redirect URL for entering password and so on till login.

How to automate it using JavaScript API automation?

 const response1 = await axios.post(apiurl1, body1, header1, { withCredentials: true });

From response1 I am getting an HTML form where I am extracting the URL using const cheerio = require('cheerio');. Wrote a method to extract the action URL:

let config2 = {
            method: 'post',
            maxBodyLength: Infinity,
            url: URL,
            headers: { 
              'Content-Type': 'application/x-www-form-urlencoded', 
              'Cookie': await cookievals / here i am getting cookies values 
            },
            data : qs.stringify({
                'username': '[email protected]' 
              })
          };

const response2 = await axios.post(config2);

For the second response, I am always getting 400 bad requests initially after adding the cookie in headers now getting 500 status code.

0

There are 0 best solutions below