【问题标题】:Adding a proxy settings to Microsoft Graph Client in Java在 Java 中向 Microsoft Graph 客户端添加代理设置
【发布时间】:2021-05-28 12:28:48
【问题描述】:

我正在尝试实现 GraphClient,下面是一个运行良好的示例代码...

   ClientCredentialProvider authProvider = 
              new ClientCredentialProvider(clientId,
                      scopes,
                      clientSecret,
                      b2cTenant,
                      endpoint);
    
    IGraphServiceClient graphClient = graphClient = GraphServiceClient.builder()
                .authenticationProvider(authProvider)
                .buildClient();

这工作正常......但在某些情况下,从运行代码的地方,有一个代理,所以我需要设置代理来连接到互联网。我需要设置代理并以某种方式将其传递给 graphClient 以告知通过代理拨打电话。

我试图找到一份文件,但找不到任何文件...

ProxyOptions proxyOptions = new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress(proxyUrl, proxyPort));
proxyOptions.setCredentials(proxyUser, proxyPassword);

final UsernamePasswordCredential usernamePasswordCredential = new UsernamePasswordCredentialBuilder()
                    .clientId(clientId)
                    .username(username)
                    .password(password)
                    .httpClient(HttpClient.createDefault(new HttpClientOptions().setProxyOptions(proxyOptions)))
                    .build();

但问题是 Maven 中没有“ProxyOptions”,我不确定它属于哪个库。

任何人都可以提出一个想法。

【问题讨论】:

    标签: java proxy microsoft-graph-api azure-ad-b2c azure-ad-graph-api


    【解决方案1】:

    你应该这样做。如果这是您需要的,请标记答案。

                    ProxyOptions proxyOptions = new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress("host", 9999));
                    
                    HttpClient httpClient = new NettyAsyncHttpClientBuilder()
                            .proxy(proxyOptions)
                            .build();
                    
                    IHttpProvider httpProvider = DefaultClientConfig.createWithAuthenticationProvider(authProvider)
                            .getHttpProvider(httpClient);
                    
                    graphClient = GraphServiceClient.builder()
                            .authenticationProvider(authProvider)
                            .httpProvider(httpProvider)
                            .buildClient();
    

    【讨论】:

    • 对于 Maven,com.azureazure-core-http-netty1.9.2依赖>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-12
    • 1970-01-01
    • 1970-01-01
    • 2013-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多