Since Microsoft has switched from basic auth to bearer auth as of 2023, I cannot perform mail reading operations. I am trying to read with GraphServiceClient, but I am getting the below mentioned errors,can you help?
CS0246-->The type or namespace name 'DelegateAuthenticationProvider' could not be found (are you missing a using directive or an assembly reference?) CS1061--> 'MeRequestBuilder' does not contain a definition for 'Request' and no accessible extension method 'Request' accepting a first argument of type 'MeRequestBuilder' could be found (are you missing a using directive or an assembly reference?)
using Microsoft.Graph;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Net.Http.Headers;
using Microsoft.Identity.Client;
namespace GraphTest.Helpers{
public class GraphHelper{
public static async Task<CachedUser> GetUserDetailsAsync(string accessToken){
var graphClient = new GraphServiceClient(new DelegateAuthenticationProvider(async (requestMessage) =>{
requestMessage.Headers.Authorization =new AuthenticationHeaderValue("Bearer", accessToken);
}));
var user = await graphClient.Me.Request().Select(u =>new{
u.DisplayName,u.Mail,u.UserPrincipalName}).GetAsync();
return new CachedUser {
Avatar = string.Empty,DisplayName = user.DisplayName,Email = string.IsNullOrEmpty(user.Mail)?user.UserPrincipalName : user.Mail};
}
}
}