0

我正在关注网站以连接到 Microsoft Graph 以使用 ADAL gem 获取访问令牌。我已经编写了一个 Rake 任务来执行此操作。这在开放网络中运行良好,但在企业网络中失败。

我已经在 bash 配置文件和终端的 bashrc 文件中设置了代理凭据

export http_proxy=http://username:pwd@proxy.corporate.com:8080/
export HTTP_PROXY=http://username:pwd@proxy.corporate.com:8080/
export https_proxy=http://username:pwd@proxy.corporate.com:8080/
export HTTPS_PROXY=http://username:pwd@proxy.corporate.com:8080/

我正在接收

SocketError:无法打开与 login.microsoftonline.com 的 TCP 连接:443(主机名未知:login.microsoftonline.com)

4

1 回答 1

0

Solution by OP.

Issue has been resolved after tweeking the user_credential.rb file in ADAL gem

File to edit: /azure-activedirectory-library-for-ruby-24e1b7f0dc37/lib/adal/user_credential.rb

def realm_discovery_response
  @realm_discovery_response ||=
    JSON.parse(Net::HTTP.get(realm_discovery_uri))
end

Replace the above code with the below as Net::HTTP.get doesnot take the system proxy use and only Net::HTTP.Get.new works

    def realm_discovery_response
      uri = URI.parse(realm_discovery_uri.to_s)
      puts "URI #{uri}"
      http = Net::HTTP.new(uri.host, uri.port)
      http.use_ssl = true if uri.scheme == 'https'
      req = Net::HTTP::Get.new(uri.request_uri)
      res = http.request(req)
      @realm_discovery_response ||= JSON.parse(res.body)
    end
于 2019-01-01T17:46:50.993 回答