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);

Benotzt déi bestehend Tenant-/Client-Umeldungsdaten. Wou ëffentlech Vermëttler souwuel fir den Token- wéi och fir den Graph-Endpunkt erlaabt sinn, bitt d'HTTP-Proxy-Lëscht Kandidaten fir déi gemeinsam HTTP-Proxy-Adress ouni Kont. Déi gewise Public-Cloud-Scopes an den erlaabten Host mussen zu der geplangter Cloud-Bereitstellung passen.

httpClient(tokenHttp) bitt d'Token-Route vun Azure Identity. GraphClientFactory.create() behält d'Standard-Middleware vu Graph a füügt de API-Proxy derbäi; benotzt de finalen graph-Client fir Operatiounen.

En authentifizéierte Vermëttler brauch Konto-Arichtung op béide Weeër: Azure ProxyOptions.setCredentials an OkHttp proxyAuthenticator bedéngen hir jeeweileg Transporten. En gecachte Token kann en net konfiguréierte Token-Wee verstoppen.

Behält an botzt eegen Transporten zesumme mam Komponent. Méi al TokenCredentialAuthProvider-Builder zielen op eng aner SDK-Generatioun.

Ähnlech Artikelen