Hi Ken Smith,
Thanks for reaching out.
There exists a constructor which takes an object of a type derived from IAuthenticationProvider, even the class used in your code ("Custom Token Credential") above is also derived from IAuthenticationProvider Interface.
The way you are creating a GraphServiceClient is also a good way from already acquired token.
Another elegant way to do the same with some less lines of code is as below.
public GraphServiceClient GetAppGraphClient(string accessToken)
{
var authProvider = new DelegateAuthenticationProvider(async (requestMessage) =>
{
// Set the Authorization header with the access token
requestMessage.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken);
});
var appGraphClient = new GraphServiceClient(authProvider);
return appGraphClient;
}
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".