doucigua0278 2017-10-09 03: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-09 21: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

    评论
    编辑
    预览

    报告相同问题?

    手机看
    程序员都在用的中文IT技术交流社区

    程序员都在用的中文IT技术交流社区

    专业的中文 IT 技术社区,与千万技术人共成长

    专业的中文 IT 技术社区,与千万技术人共成长

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    客服 返回
    顶部