We are trying to authenticate the users for our Web App & Mobile App using Azure Active Directory via MS Graph API. We are created users and given required access rights for the app. Even for the admin user, we are getting the exception AADSTS50034: The user account {EmailHidden} does not exist in the ab6d6a8a-83ea-4650-a631-5cb43442842b directory.
To sign into this application, the account must be added to the directory.\r\nTrace ID: 68d6f664-6d50-4c1f-9ae8-42f3aa497c00\r\n
Correlation ID: 3d30e47d-b2ac-42cd-bfd5-069dbd8f5c67\r\nTimestamp: 2021-02-08 13:56:51Z"}
.net code to authenticate the username and password is
public async Task<string> GetValidAD(JObject jsonResult)
{
try
{
var scopes = new string[] { "https://graph.microsoft.com/.default" };
dynamic Item = JObject.Parse(jsonResult.ToString());
String clientId = Item.clientId.ToString();
String tenantID = Item.tenantID.ToString();
String email = Item.email.ToString();
String password = Item.password.ToString();
System.Security.SecureString pword = new NetworkCredential(email,password).SecurePassword;
string pwordstr = new NetworkCredential(email, pword).Password;
IPublicClientApplication publicClientApplication = PublicClientApplicationBuilder
.Create(clientId)
.WithTenantId(tenantID)
.Build();
try
{
var result = await publicClientApplication.AcquireTokenByUsernamePassword(scopes, email, pword).ExecuteAsync();
return result.ToString();
}
catch (MsalUiRequiredException ex)
{
return ex.InnerException.ToString();
// error handling omited here (see sample for details)
}
}
catch (Exception ex)
{
return ex.ToString();
}
}
Please help me to resolve the issue. Thanks in advance