【发布时间】:2021-06-04 10:14:42
【问题描述】:
我正在尝试从 Azure B2C Active Directory 获取用户列表,对于非代理环境,我的代码运行良好,但是当我通过传递代理配置运行它时,我收到“SocketTimeoutException”
下面是我的代码...
GraphServiceClient<Request> graphClient;
if (this.proxy.equals("true")) {
final ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
.clientId(this.clientId)
.clientSecret(this.clientSecret)
.tenantId(this.b2cTenant)
.build();
final TokenCredentialAuthProvider tokenCredentialAuthProvider =
new TokenCredentialAuthProvider(Constant.scopes, clientSecretCredential);
final Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(this.hostAddress, this.hostPort));
final OkHttpClient httpClient = HttpClients.createDefault(tokenCredentialAuthProvider)
.newBuilder()
.proxy(proxy)
.build();
graphClient = GraphServiceClient.builder()
.authenticationProvider(tokenCredentialAuthProvider)
.httpClient(httpClient)
.buildClient();
} else {
final ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
.clientId(this.clientId)
.clientSecret(this.clientSecret)
.tenantId(this.b2cTenant)
.build();
final TokenCredentialAuthProvider tokenCredentialAuthProvider =
new TokenCredentialAuthProvider(Constant.scopes, clientSecretCredential);
graphClient = GraphServiceClient.builder()
.authenticationProvider(tokenCredentialAuthProvider)
.buildClient();
}
在“if”中我使用 PROXY,而在“else”中我在没有 PROXY 的情况下使用。
所以我有一个通过命令行传递的 hostAddress 和 hostPort...我正在使用 clientId、clientSecret 和 b2cTenantId 创建一个 ClientSecretCredential。
然后我正在使用范围和客户端机密凭据创建 TokenCredentialAuthProvider。
对我来说,范围是 - https://graph.microsoft.com/.default
然后我使用地址和端口创建一个代理,并将其传递给 OkHttpClient。然后我正在创建将所有内容传递给 graphClient。
对于非代理(“else”)工作正常,但是当我通过代理工作时,我得到“超时”。我尝试调试代码,但调用 API 时唯一的例外是......
final User me = graphClient.me().buildRequest().get();
我收到“SocketTimeoutException”
我已经阅读了多个文档,github线程,我无法理解问题。
https://github.com/microsoftgraph/msgraph-sdk-java/issues/162
https://github.com/microsoftgraph/msgraph-sdk-java/issues/158
https://github.com/microsoftgraph/msgraph-sdk-java-core
请帮忙。
【问题讨论】:
标签: java microsoft-graph-api azure-ad-b2c