DEV Community

Alexander248365
Alexander248365

Posted on

Modern authentication with Azure AD for WinForms (native) apps - Question to Christos

Hi Christos,

You published a great tutorial on accessing Azure through MSAL authentication,

https://cmatskas.com/modern-authentication-with-azure-ad-for-winforms-native-apps-2/

It would be great if you could clarify additional two points:

  1. Is there an option to store user ID/pwd and to access Azure Graph in Windows Forms Desktop applicatin?

  2. I tried to follow up steps that you've posted and got an issue: FirstAccount is null, even though accounts is not null:

        AuthenticationResult authResult = null;
        var accounts = await Program.PublicClientApp.GetAccountsAsync();
    

// AW: accounts != null was always true

        if (accounts != null)
        { label2.Text += $"GetAccountsAsync passed!"; }
        else
        { label2.Text += "PublicClientApp.GetAccountsAsync returned an empty list"; }


        var firstAccount = accounts.FirstOrDefault();
Enter fullscreen mode Exit fullscreen mode

//AW: firstAccount is NULL

        if (firstAccount != null)
        { label2.Text += firstAccount.Username; }
        else
        { label2.Text += "firstAccount is null"; }
Enter fullscreen mode Exit fullscreen mode

This NULL shows before the login screen to MS shows up.

Any ideas on what could go wrong?

Thank you.
Alexander

Top comments (0)