简体   繁体   English

Javascript 中的 ntlm 身份验证

[英]ntlm Authentication in Javascript

Trying to connect to Business central web services hosted on a local server.尝试连接到本地服务器上托管的业务中心 web 服务。

I managed to get a connection with ntlm auth in postman. I can however not get it to work in javascript.我设法在 postman 中与 ntlm auth 建立连接。但是我无法在 javascript 中使用它。

gives me a 401.给我一个 401。

How do I approach this problem?我该如何解决这个问题? Is it even possible to do in Javascript?甚至可以在 Javascript 中进行吗?

You can add a Web Service Access key on a user in Business Central.您可以在 Business Central 中为用户添加 Web 服务访问密钥。 Once you have done that basic authentication will do the trick.完成后,基本身份验证就可以解决问题。 The below works in NAV2018.以下适用于 NAV2018。

For more recent versions of BC oauth2 via Azure Active Directory is recommended.对于更新版本的 BC oauth2,建议通过 Azure Active Directory。

const fetch = require('node-fetch');
const base64 = require('base-64');

module.exports = async function (url, body) {

    let response = fetch(url, {
        method: 'POST',
        headers: {
            'Authorization': 'Basic ' + base64.encode(channel.bc_user + ":" + bcPassword),
            'Content-Type': 'application/json'
        },
        body: JSON.stringify(body)
    }).then(res => {
        return res;
    });

    return response;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM