Microsoft Azure Active Directory Passport身份validation

贝娄的代码运行良好,但是当授权头来自php代码的空令牌(eg-'Authorization:bearer')时,node.js应用程序会崩溃。 我正在使用“passport-azure-ad”节点模块。 我与邮政人检查,它是validation令牌,但是当请求来自PHPcurl请求,应用程序崩溃。 其原因是,http头在“passport-azure-ad”节点模块中设置了两次。 我无法捕捉到这个错误。

router.get('/getUser', passport.authenticate('oauth-bearer', { session: false, tenantIdOrName: TENANT }), function (req, token, done) { // Send response }); 

崩溃错误跟踪 – _http_outgoing.js:356抛出错误('发送后不能设置标题'); ^

错误:发送后无法设置标题。 在\ node_modules \ passport \ lib \ middleware \ authenticate.js:156:13)

PHP代码=>

 $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 ); 

我该如何处理这个错误,谢谢。

Node.js正在一个线程中运行,当错误没有被处理时它会崩溃。 这里是关于Node.js中exception处理的非常有用的线程:

Node.js最佳实践exception处理