I'm using the Tutorial found at the following location:
Tutorial: Call the Microsoft Graph API from a Universal Windows Platform (UWP) application
Using the program as written, I'm getting a frequent error where the Connect To Service/ Login box hangs after entering the password. I have changed the ClientID and used multiple Nuget lib versions for both the Microsoft.Graph and Microsoft.Identity.Client.
Like I said, this error condition is inconsistent and does not happen all the time, but a majority of times.
I've used multiple machines and the results are the same. And I have been strugling with this problem for some time. I am not getting an "error" because the app just "hangs".
Here is some additional information.
The first snippet is from a WinForms app...It works as expected. 1. Signin 2. password 3. Shows a success connection and displays the Access Token (Here is that code with the ClientId hidden)
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
private static string ClientId = "xxxx....xxxxx";
private AuthenticationResult authResult = null;
private string[] scopes = { "Notes.ReadWrite" };
// The MSAL Public client app
private static IPublicClientApplication PublicClientApp;
private static PublicClientApplicationBuilder app;
private static string MSGraphURL = "https://graph.microsoft.com/v1.0/";
private IEnumerable<IAccount> accounts = null;
private IAccount firstAccount = null;
public Form1()
{
InitializeComponent();
SignInBtn_Click(null, null);
}
private async void SignInBtn_Click(object sender, EventArgs e)
{
var app = PublicClientApplicationBuilder.Create(ClientId).Build();
var result = await app.AcquireTokenInteractive(scopes).ExecuteAsync();
authResult = result;
accounts = await app.GetAccountsAsync();
firstAccount = accounts.FirstOrDefault();
string userName = firstAccount.Username.ToString();
string homeaccountId = firstAccount.HomeAccountId.ToString();
string objectId = firstAccount.HomeAccountId.ObjectId.ToString();
MessageBox.Show(result.AccessToken);
}
The second snippet that is pretty much identical to the first snippet from a UWP app that will work sometimes. But most of the time it hangs after the password is entered. Just a flashing "blue dot" in the upper left hand corner.
using Microsoft.Identity.Client;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using Windows.UI.Xaml.Controls;
namespace SOAPV2.Views
{
public sealed partial class MainPage : Page, INotifyPropertyChanged
{
private static string ClientId = "2c7ea4af-a717-4141-a147-77eb4bd96869";
private AuthenticationResult authResult = null;
private string[] scopes = { "Notes.ReadWrite" };
// The MSAL Public client app
private static IPublicClientApplication PublicClientApp;
private static PublicClientApplicationBuilder app;
private static string MSGraphURL = "https://graph.microsoft.com/v1.0/";
private IEnumerable<IAccount> accounts = null;
private IAccount firstAccount = null;
public MainPage()
{
InitializeComponent();
SignIn();
}
private async void SignIn()
{
var app = PublicClientApplicationBuilder.Create(ClientId).Build();
var result = await app.AcquireTokenInteractive(scopes).ExecuteAsync();
accounts = await app.GetAccountsAsync();
firstAccount = accounts.FirstOrDefault();
//MessageBox.Show(result.AccessToken);
}
I am using the latest Microsoft.Identity.client from NuGet
I have struggled to find a solution to this problem. Looking forward to your answer.