Hi @Wasi Hyder
In v5, you can obtain an access token using the TokenCredential
method. This method is more flexible and supports various authentication schemes (including user-based authentication, client credentials, etc.).
After that, pass the tokenCredential object to the GraphServiceClient
class to instantiate the graphServiceClient object.
using Microsoft.Graph;
using Microsoft.Graph.Auth;
using Microsoft.Identity.Client;
// Your existing code to extract the access token from the request headers
var authorizationHeader = HttpContext.Request.Headers["Authorization"].FirstOrDefault();
var accessToken = authorizationHeader.Substring("Bearer ".Length);
// Create a TokenCredential using the access token
var tokenCredential = new AccessTokenCredential(accessToken);
// Initialize the GraphServiceClient with the TokenCredential
var graphServiceClient = new GraphServiceClient(tokenCredential);
Hope this helps.
If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.