Bellow code functioning fine, but when authorization header come with empty token from php code (Eg- 'Authorization: bearer '), node.js application get crash. I'm using "passport-azure-ad" node module. I checked with Post man, it's validate the token, but when the request come from php curl request, application get crash. The reason for this, http header set two times in "passport-azure-ad" node module. I couldn't catch this error.
router.get('/getUser', passport.authenticate('oauth-bearer', {
session: false,
tenantIdOrName: TENANT
}), function (req, token, done) {
// Send response
});
Crash error trace - _http_outgoing.js:356 throw new Error('Can\'t set headers after they are sent.'); ^
Error: Can't set headers after they are sent. at \node_modules\passport\lib\middleware\authenticate.js:156:13)
PHP code = >
$headers = array ('Authorization: bearer ' . $Requestheader['id_token']);
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ( $ch, CURLOPT_URL, 'http://serverhost/auth/getUser' );
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
return curl_exec ( $ch );
How can I handle this error from my side, Thank you.