Authenticating to Microsoft Dynamics/Azure AD using username and password in .net 5.0

Solution for Authenticating to Microsoft Dynamics/Azure AD using username and password in .net 5.0
is Given Below:

I’m new to trying to access the Microsoft Dynamics API and I’m working my way through the tutorial here: https://docs.microsoft.com/en-us/powerapps/developer/data-platform/webapi/quick-start-console-app-csharp. The tutorial works great, but only in .net 4.6.2 and we are on .net 5.0. For the life of me I cannot find an example of how to replicate this functionality in .net 5.0. Specifically, the section of code here

var authParameters = AuthenticationParameters.CreateFromResourceUrlAsync(new Uri(webApiUrl)).Result;
var authContext = new AuthenticationContext(authParameters.Authority, false);
var authResult = authContext.AcquireToken(url, clientId, userCredential);

throws an error on the AcquireToken method. Does anyone know how to login to Azure AD using a username and password in .net 5.0 as shown in this example?

You may need to switch your code to use MSAL.NET (from ADAL.NET used in example).
Here is tutorial (not mine) specifically addressing acquiring tokens for Microsoft Dynamics API using MSAL library:
https://medium.com/capgemini-microsoft-team/access-tokens-for-dynamics-365-using-microsoft-authentication-library-2b16c9f794b