Tá pointí iontrála iompair ar leith ag glaonna Graph API agus ag iarratais chomhartha ClientSecretCredential. Le Microsoft.Graph 5 agus Azure Identity, cumraigh an dá rud sula ndéantar an cliant:

var proxy = new System.Net.WebProxy(
    "http://proxy.example.net:8080");

var tokenHandler = new System.Net.Http.HttpClientHandler
{
    Proxy = proxy,
    UseProxy = true
};

var credentialOptions = new Azure.Identity.ClientSecretCredentialOptions
{
    Transport = new Azure.Core.Pipeline.HttpClientTransport(tokenHandler)
};

var credential = new Azure.Identity.ClientSecretCredential(
    tenantId, clientId, clientSecret, credentialOptions);

var authProvider =
    new Microsoft.Kiota.Authentication.Azure.AzureIdentityAuthenticationProvider(
        credential, scopes: new[] { "https://graph.microsoft.com/.default" });

var graphHttp = Microsoft.Graph.GraphClientFactory.Create(proxy: proxy);
var graphClient = new Microsoft.Graph.GraphServiceClient(
    graphHttp, authProvider);

Le haghaidh bealaigh HTTP phoiblí neamhfhíordheimhnithe, soláthraíonn an liosta seachfhreastalaí HTTP seoltaí iarrthacha don WebProxy roinnte. Soláthraíonn an feidhmchlár tenantId, clientId agus clientSecret trína láimhseáil dintiúir atá ann cheana. Úsáideann raon .default na ceadanna feidhmchláir atá cumraithe don chlárú sin; ní féidir le bealach ceadanna a dheonú.

Léigh an dá líne iompair mar an péire tábhachtach. Iompraíonn HttpClientTransport(tokenHandler) iarraidh chomhartha an dintiúir. Coinníonn GraphClientFactory.Create(proxy: proxy) tógáil meánbhogearraí HTTP an Graph SDK agus cumraíonn sé a bhealach API.

Má éilíonn an idirghabhálaí fíordheimhniú, sanntar an cuntas riachtanach d'airí Credentials an ruda sheachfhreastalaí. Coinnigh iompar atá faoi úinéireacht ar feadh shaolré na comhpháirte agus scaoil iad ag am múchta.

Úsáid an patrún seo leis an nglúin SDK a luaitear. Baineann samplaí le HttpProvider agus DelegateAuthenticationProvider le glúin níos luaithe agus ní féidir iad a mheascadh isteach sa slabhra cruthaitheora seo.

Ailt ghaolmhara