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

ใช้ข้อมูลรับรองผู้เช่า/ไคลเอนต์ที่มีอยู่ เมื่ออนุญาตให้ใช้ตัวกลางสาธารณะทั้งสำหรับปลายทางโทเค็นและ Graph รายการพร็อกซี่ HTTP จะจัดหาตัวเลือกสำหรับที่อยู่พร็อกซี่ HTTP ที่ใช้ร่วมกันโดยไม่ต้องมีบัญชี สโคประบบคลาวด์สาธารณะและโฮสต์ที่อนุญาตซึ่งแสดงไว้ต้องตรงกับการปรับใช้คลาวด์ที่ตั้งใจไว้

httpClient(tokenHttp) จัดหาเส้นทางโทเค็นของ Azure Identity GraphClientFactory.create() รักษามิดเดิลแวร์เริ่มต้นของ Graph ไว้พร้อมกับเพิ่มพร็อกซี่ของ API ใช้ไคลเอนต์ graph สุดท้ายสำหรับการดำเนินการ

ตัวกลางที่ผ่านการตรวจสอบสิทธิ์ต้องตั้งค่าบัญชีในทั้งสองเส้นทาง: Azure ProxyOptions.setCredentials และ OkHttp proxyAuthenticator ให้บริการการรับส่งของแต่ละฝ่าย โทเค็นที่แคชไว้อาจซ่อนเส้นทางโทเค็นที่ยังไม่ได้กำหนดค่า

เก็บรักษาและทำความสะอาดการรับส่งที่เป็นของคุณพร้อมกับคอมโพเนนต์ ตัวสร้าง TokenCredentialAuthProvider รุ่นเก่ามุ่งเป้าไปที่ SDK อีกรุ่นหนึ่ง

บทความที่เกี่ยวข้อง