Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,490 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I got a problem when trying to upgrade GraphServiceClient from 3.19.0 to 5.56.0 (as shown below), how do I update this code to Microsoft.Graph 5.56? Please note, I find all examples on the web and they don't show me a solution:
protected GraphServiceClient graphServiceClient
{
get
{
GraphServiceClient gsc = new GraphServiceClient(
new DelegateAuthenticationProvider(
(requestMessage) =>
{
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", GetUserToken().GetAwaiter().GetResult());
return Task.FromResult(0);
}));
return gsc;
}
}
protected async Task<string> GetUserToken()
{
string signedInUserID = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
string tenantID = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/tenantid").Value;
string userObjectID = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
// get a token for the Graph without triggering any user interaction (from the cache, via multi-resource refresh token, etc)
Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential clientCredentials =
new Microsoft.IdentityModel.Clients.ActiveDirectory
.ClientCredential(Config.ADSettings.EquiTrakAppId, Config.ADSettings.EquiTrakClientSecret);
// initialize AuthenticationContext with the token cache of the currently signed in user, as kept in the app's database
AuthenticationContext authenticationContext =
new AuthenticationContext(Config.AzureADInstance + tenantID, new ADALTokenCache(signedInUserID));
Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult authenticationResult =
await authenticationContext
.AcquireTokenSilentAsync(Config.GraphResourceId, clientCredentials, new UserIdentifier(userObjectID, UserIdentifierType.UniqueId));
return authenticationResult.AccessToken;
}