var address = new java.net.InetSocketAddress("proxy.example", 8080);
var tokenProxy = new com.azure.core.http.ProxyOptions(
    com.azure.core.http.ProxyOptions.Type.HTTP, address);
var tokenHttp = new com.azure.core.http.netty.NettyAsyncHttpClientBuilder()
    .proxy(tokenProxy).build();
var credential = new com.azure.identity.ClientSecretCredentialBuilder()
    .tenantId(tenantId).clientId(clientId).clientSecret(clientSecret)
    .httpClient(tokenHttp).build();

String[] scopes = {"https://graph.microsoft.com/.default"};
String[] allowedHosts = {"graph.microsoft.com"};
var auth = new com.microsoft.kiota.authentication.AzureIdentityAuthenticationProvider(
    credential, allowedHosts, scopes);
var graphHttp = com.microsoft.graph.core.requests.GraphClientFactory.create()
    .proxy(new java.net.Proxy(java.net.Proxy.Type.HTTP, address))
    .build();
var graph = new com.microsoft.graph.serviceclient.GraphServiceClient(auth, graphHttp);

Gebruik bestaande tenant-/clientreferenties. Waar openbare tussenpersonen zijn toegestaan voor zowel het token- als het Graph-eindpunt, levert de HTTP-proxylijst kandidaten voor het gedeelde HTTP-proxyadres zonder account. De getoonde public-cloud-scopes en de toegestane host moeten overeenkomen met de beoogde cloudimplementatie.

httpClient(tokenHttp) levert de tokenroute van Azure Identity. GraphClientFactory.create() behoudt de standaardmiddleware van Graph en voegt de API-proxy toe; gebruik de uiteindelijke graph-client voor bewerkingen.

Een geauthenticeerde tussenpersoon vereist accountinstelling op beide paden: Azure ProxyOptions.setCredentials en OkHttp proxyAuthenticator bedienen hun respectieve transporten. Een gecacht token kan een niet-geconfigureerd tokenpad verbergen.

Behoud en ruim eigen transporten op samen met de component. Oudere TokenCredentialAuthProvider-builders richten zich op een andere SDK-generatie.

Gerelateerde artikelen