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

Brûk besteande tenant-/kliïntreferinsjes. Wêr't iepenbiere tuskenlju tastien binne foar sawol it token- as it Graph-einpunt, leveret de HTTP-proksylist kandidaten foar it mienskiplike HTTP-proxyadres sûnder akkount. De sjen litten public-cloud-omfangen en de tastiene host moatte oerienkomme mei de bedoelde wolkimplementaasje.

httpClient(tokenHttp) leveret de tokenrûte fan Azure Identity. GraphClientFactory.create() behâldt de standertmiddleware fan Graph wylst it de API-proxy tafoeget; brûk de definitive graph-kliïnt foar operaasjes.

In autentisearre tuskenpersoan hat akkountynstelling nedich op beide paden: Azure ProxyOptions.setCredentials en OkHttp proxyAuthenticator betsjinje harren respektivelike transporten. In cachet token kin in net konfigurearre tokenpad ferbergje.

Behâld en romje eigen transporten op tegearre mei de komponint. Aldere TokenCredentialAuthProvider-bouwers rjochtsje har op in oare SDK-generaasje.

Relatearre artikelen