public async void GetUserDetailsAsync() { Task auth = GetTokenForUser(); auth.Wait(); var token = auth.Result.AccessToken; GraphServiceClient graphClient = new GraphServiceClient( "https://graph.microsoft.com/v1.0", new DelegateAuthenticationProvider( async (requestMessage) => { requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", token); })); var user =await graphClient.Me.Request().GetAsync(); } public Task GetTokenForUser() { var tenantId = "000000-0000-0000-0000-0000000000"; var clientId = "000000-0000-0000-0000-0000000000"; var clientSecret ="000000-0000-0000-0000-0000000000"; // Configure app builder var authority = $"https://login.microsoftonline.com/{tenantId}"; var app = ConfidentialClientApplicationBuilder .Create(clientId) .WithClientSecret(clientSecret) .WithAuthority(new Uri(authority)) .Build(); // Acquire tokens for Graph API string[] scopes = { ".default" }; Task authenticationResult = app.AcquireTokenForClient(scopes).ExecuteAsync(); return authenticationResult; }