API နှင့် token ဖောက်သည်များအတွက် Microsoft Graph Java 6 ပရောက်စီ ဆက်တင်များ
စတင်ချိန်တွင် Azure Identity ၏ Netty လမ်းကြောင်းနှင့် Graph ၏ middleware ကို ထိန်းသိမ်းသော OkHttp လမ်းကြောင်းကို အသုံးပြုပါ။
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);လက်ရှိ tenant/client အထောက်အထားများကို အသုံးပြုပါ။ token နှင့် Graph အင်ပ်ပွိုင့် နှစ်ခုလုံးအတွက် အများပြည်သူ ကြားခံများကို ခွင့်ပြုထားသည့်နေရာတွင် HTTP ပရောက်စီ စာရင်း သည် အကောင့်မလိုသော မျှဝေ HTTP ပရောက်စီ လိပ်စာအတွက် ကိုယ်စားလှယ်လောင်းများကို ပေးသည်။ ပြသထားသော public-cloud scope များနှင့် ခွင့်ပြုထားသော host သည် ရည်ရွယ်ထားသော cloud ဖြန့်ကျက်မှုနှင့် ကိုက်ညီရမည်။
httpClient(tokenHttp) သည် Azure Identity ၏ token လမ်းကြောင်းကို ပေးသည်။ GraphClientFactory.create() သည် Graph ၏ မူလ middleware ကို ထိန်းသိမ်းပြီး API ပရောက်စီကို ထည့်သည်။ လုပ်ငန်းဆောင်တာများအတွက် နောက်ဆုံး graph ဖောက်သည်ကို အသုံးပြုပါ။
စစ်မှန်ကြောင်းအတည်ပြုထားသော ကြားခံသည် လမ်းကြောင်းနှစ်ခုလုံးတွင် အကောင့်သတ်မှတ်မှု လိုအပ်သည်။ Azure ProxyOptions.setCredentials နှင့် OkHttp proxyAuthenticator တို့သည် ၎င်းတို့၏ သက်ဆိုင်ရာ သယ်ယူပို့ဆောင်မှုကို ဆောင်ရွက်သည်။ သိမ်းဆည်းထားသော token သည် မသတ်မှတ်ရသေးသော token လမ်းကြောင်းကို ဖုံးကွယ်နိုင်သည်။
ပိုင်ဆိုင်သော သယ်ယူပို့ဆောင်မှုများကို အစိတ်အပိုင်းနှင့်အတူ ထိန်းသိမ်းပြီး ရှင်းလင်းပါ။ ဟောင်းသော TokenCredentialAuthProvider တည်ဆောက်သူများသည် အခြား SDK မျိုးဆက်ကို ရည်ရွယ်သည်။