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

Sebenzisa ubufakazi obukhona be-tenant/iklayenti. Lapho iziphakathi zomphakathi zivunyelwe kukho kokubili i-token namaphoyinti okugcina e-Graph, uhlu lwe-proxy ye-HTTP lunikeza abangeneleli bakhe ikheli le-HTTP proxy elabiwe elingenayo i-akhawunti. Ama-scope efu lekufu lomphakathi kanye nomgcini ovunyelwe okukhonjisiwe kufanele kuhambisane nokufakwa kwefu elicatshangelwe.

httpClient(tokenHttp) sinikeza indlela ye-token ye-Azure Identity. I-GraphClientFactory.create() igcina i-middleware ezenzakalelayo ye-Graph ngenkathi yengeza i-proxy ye-API; sebenzisa iklayenti lokugcina le-graph emisebenzini.

Isiphakathi esiqinisekisiwe sidinga ukusethwa kwe-akhawunti kuzo zombili izindlela: i-Azure ProxyOptions.setCredentials ne-OkHttp proxyAuthenticator zikhonza ukuthutha kwazo. I-token egciniwe ingafihla indlela ye-token engakalungiselelwa.

Gcina futhi uhlanze ukuthutha okuphethwe yingxenye. Abakhi bakudala be-TokenCredentialAuthProvider baqondise kwesinye isizukulwane se-SDK.

Izihloko ezihlobene