Hi
WPF, VS2017, MSAL 3x version.
I am trying an sample to test function AcquireTokenByUsernamePassword(). Following is the code example.I am getting error
Error Acquiring Token:
Microsoft.Identity.Client.MsalServiceException: AADSTS7000218: The request body must contain the following parameter: 'client_assertion' or 'client_secret'.
{
string[] scopes = new string[] { "<ResourceID XXXXXX>/user_impersonation" };
string targetAPIUrl = string.Format("https://xxxxxxxxx.azurewebsites.net/api/TestFunction1");
string ClientId = "3c278a32-0202-111c-8b03-xxxxxxxxxx";
string Tenant = "xxxxxx-7665-xxxx-8ce2-xxxxxxxxxxxx";
IPublicClientApplication _clientApp;
AuthenticationResult authResult = null;
_clientApp = PublicClientApplicationBuilder.Create(ClientId)
.WithAuthority(AzureCloudInstance.AzurePublic, Tenant)
.Build();
try
{
var securePassword = new SecureString();
foreach (char c in "RealPassword123") // you should fetch the password
securePassword.AppendChar(c); // keystroke by keystroke
authResult = await _clientApp.AcquireTokenByUsernamePassword(scopes, "ADUser@CompanyName.com", securePassword)
.ExecuteAsync();
outputBox.Text = await GetHttpContentWithToken(targetAPIUrl, authResult.AccessToken);
}
catch (MsalException msalex)
{
outputBox.Text = $"Error Acquiring Token:{System.Environment.NewLine}{msalex}";
}
}
Please Advice.
Regards