Authentication loop (or block) while using jsreport online api



  • Dear JsReport team,

    For the last few days I've been trying to solve this problem: Whenever I try to render a report with jsreport online api, my website asks for authentication:

    0_1496084887229_upload-56d2d395-338b-463a-b47a-4778eb32c534

    I tried using my website's admin account, as well as the jsreport account, but it just didn't get through. That window keeps popping up, and it doesn't even show whether the account is correct or not.

    I'm new to both nodejs and jsreport, so this has really been difficult for me. I hope you guys can help me understand this authentication thing, or show me how to disable it completely if possible.

    Looking forward to your reply.
    Best regards,


  • administrators

    hi! that popup usually shows when either the credentials are not being sent or are invalid..

    can you share the code that you are using to communicate with jsreportonline? that would help to identify what is wrong



  • Hi,

    Below is my code:

    app.get('/invoice', function(req, res, next) {

    fs.readFile('./invoice.json', function (err, content) {
    
    	const invoiceData = JSON.stringify(JSON.parse(content));
    
    	var data = {
    		template:{"shortid":'BJMUIjAFWZ'},
    		// data:invoiceData
    	}
    
    	var options = {
    		url:'https://ptduw-cntn2014-nhom07.jsreportonline.net/api/report',
    		method:'POST',
    		json:data
    	}
    
    	try {
        	request(options).pipe(res);
      	} catch (err) {
    	    res.write(err.message);
    	    res.end();
    	}
    });
    

    });

    I believe I got the correct template's shortid and the api's uri. Everything else is on default, I made no change to them.



  • You seems to be using the node.js request module, right?
    In this case you are missing the auth in the options - https://github.com/request/request#http-authentication

    Maybe you could also take a look on the official jsreport client for node.js which wraps some stuff like authentication for you
    https://jsreport.net/learn/nodejs-client



  • Thank you very much for your solution, jan_blaha. I tried adding username:password to the url and it finally works!

    Again, thanks for your help, han_blaha and bjrmatos.



  • Great! Thanks for info.


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.