【问题标题】:proxy setting in adal-node packageadal-node 包中的代理设置
【发布时间】:2021-06-12 18:38:49
【问题描述】:

我正在尝试使用 adal-node package() 在我的节点服务器中生成令牌以向 Azure AD 进行身份验证。它在我的本地机器上工作,但是当尝试在虚拟机上运行时,它给出以下错误:

{ 错误:getaddrinfo EAI_AGAIN login.microsoftonline.com login.microsoftonline.com:443 在 GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:57:26) 错误号:'EAI_AGAIN', 代码:'EAI_AGAIN', 系统调用:'getaddrinfo', 主机名:'login.microsoftonline.com', 主机:'login.microsoftonline.com', 端口:443`}

示例代码sn-p

var authorityUrl = 'https://login.microsoftonline.com/53d652a4-6f71-416f-971f-*****'
    var applicationId = '26915ab6-22fc-4017-8741-***************'; // Application Id of app registered under AAD.
    var clientSecret = '2NZtB5mIX1xZaXZ_I6I~-*********'; // Secret generated for app. Read this environment variable.
    var resource = 'https://**************.com'; // URI that identifies the resource for which the token is valid.
    var context = new AuthenticationContext(authorityUrl);
    context.acquireTokenWithClientCredentials(resource, applicationId, clientSecret, function(err, tokenResponse) {
        if (err) {
            console.log('well that didn\'t work: ' + err.stack);
            console.log(err);
            res.json(err.stack);
        } else {
           
            console.log(tokenResponse.accessToken);
           
        }
        

分析:看起来是代理问题,但无法弄清楚如何使用 adal-node 包设置代理 url。请提出前进的方向。

【问题讨论】:

    标签: node.js node-modules adal


    【解决方案1】:

    如果你想在你的应用中使用代理服务器,请参考以下代码

    const { AuthenticationContext, Logging } = require("adal-node");
    const proxy = require("node-global-proxy").default;
    proxy.setConfig({
      http: "",
    https: ""
    });
    proxy.start();
    const context = new AuthenticationContext(
      "https://login.microsoftonline.com/const { AuthenticationContext, Logging } = require("adal-node");
    const proxy = require("node-global-proxy").default;
    proxy.setConfig({
      http: "http://149.28.43.184:8080",
    });
    proxy.start();
    const context = new AuthenticationContext(
      "https://login.microsoftonline.com/e4c9ab4e-bd27-40d5-8459-230ba2a757fb"
    );
    
    Logging.setLoggingOptions({
      log: function (level, message, error) {
        console.log(message);
        if (error) {
          console.log(error);
        }
      },
      loggingWithPII: false,
      level: Logging.LOGGING_LEVEL.VERBOSE,
    });
    var applicationId = ""; // Application Id of app registered under AAD.
    var clientSecret = ""; // Secret generated for app. Read this environment variable.
    var resource = "";
    context.acquireTokenWithClientCredentials(
      resource,
      applicationId,
      clientSecret,
      function (err, tokenResponse) {
        if (err) {
          console.log("well that didn't work: " + err.stack);
        } else {
          console.log(tokenResponse);
        }
      }
    );
    
    proxy.stop()
    
    
    

    【讨论】:

      猜你喜欢
      • 2020-11-20
      • 1970-01-01
      • 2015-07-21
      • 1970-01-01
      • 2013-07-04
      • 2017-11-13
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多