microsoftgraph / microsoft-graph-toolkit

Authentication Providers and UI components for Microsoft Graph 🦒
https://docs.microsoft.com/graph/toolkit/overview
Other
939 stars 298 forks source link

GraphServiceClient returns only user email and name. #3219

Closed DmitryBorodiy closed 3 months ago

DmitryBorodiy commented 3 months ago
using Azure.Core;
using Azure.Identity;
using Microsoft.Graph;
using SampleWpf;
using System.Net.Http.Headers;
using System.Net.Http;
using System.Threading.Tasks;
using System.Diagnostics;

namespace QuickFind.Services.Account
{
    public static class MsalUserProvider
    {
        #region Consts
        private const string MsalClientId = "...";
        private const string MsalTenantId = "...";
        #endregion

        #region Props
        public static GraphServiceClient UserClient { get; set; }
        private static InteractiveBrowserCredential _deviceCodeCredential;
        private static InteractiveBrowserCredential _interactiveBrowserCredential;
        private const string CacheFile = "Properties/temp.bin";

        private static string[] Scopes =>
        [
            "User.Read",
            "User.Read.All",
            "Mail.ReadBasic",
            "Mail.Read",
            "Tasks.Read",
            "Tasks.ReadWrite",
            "Tasks.Read.Shared",
            "Tasks.ReadWrite.Shared",
        ];
        #endregion

        #region Methods

        public static async Task InitializeGraphForUserAuth()
        {
            var options = new DeviceCodeCredentialOptions
            {
                AuthorityHost = AzureAuthorityHosts.AzurePublicCloud,
                ClientId = MsalClientId,
                TenantId = MsalTenantId,
                DeviceCodeCallback = (code, cancellation) =>
                {
                    Console.WriteLine(code.Message);
                    return Task.FromResult(0);
                },
            };

            var deviceCodeCredential = new DeviceCodeCredential(options);
            UserClient = new GraphServiceClient(deviceCodeCredential, Scopes);

            if(UserClient != null)
            {
                var user = await UserClient.Me.GetAsync();
                var todo = await UserClient.Me.Todo.Lists.GetAsync();

                Debug.WriteLine(user);
            }
        }

        public static async void InitializeGraph()
        {
            await InitializeGraphForUserAuth();
        }

        #endregion
    }
}

If I try to get something else, like inbox or todo, but it throws an ODataError.

DmitryBorodiy commented 3 months ago

ItemNotFound error message. Show me a tutorial or video on how to properly configure Microsoft Graph for a WPF or Avalonia app. Because after the release of version 5, I don't know how to do it.

gavinbarron commented 3 months ago

This looks like an issue with the Microsoft Graph .NET SDK and not Microsoft Graph Toolkit.

gavinbarron commented 3 months ago

@sebastienlevert can you please transfer to microsoftgraph/msgraph-sdk-dotnet I don't have write access to that repo so can't transfer to there.

baywet commented 3 months ago

@gavinbarron I can't transfer it because I don't have permissions in this specific repo. @DmitryBorodiy can you re-open an issue here please?

DmitryBorodiy commented 3 months ago

@gavinbarron I can't transfer it because I don't have permissions in this specific repo. @DmitryBorodiy can you re-open an issue here please?

Where your link was, I created a new issue.

sebastienlevert commented 3 months ago

The issue was created here https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/2550

I'll be closing this one in favor of the one in the dotnet repo. Thanks!