doucigua0278 2017-10-09 11:55
浏览 668

Microsoft Azure Active Directory Passport身份验证

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 ode_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.

  • 写回答

1条回答 默认 最新

  • dsa1234569 2017-10-10 05:29
    关注

    The Node.js is being run in a single thread, it will crash when the error is not handled. Here is a very helpful thread about Exception Handling in Node.js:

    Node.js Best Practice Exception Handling

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP