I have an API which takes username and password and generate the access_token using MSAL.Net as shown in the code snippet below. It is working fine on my local machine, however I'm getting error when it is deployed to Azure App Service.
public async Task<TokenResponse> GenerateToken(string username, string password)
{
var scopes = jwtConfig.Value.Scopes;
var result = await publicClientApplication.AcquireTokenByUsernamePassword(
scopes,
username,
ConvertToSecureString(password)
).ExecuteAsync();
return new TokenResponse()
{
Access_token = result.AccessToken
};
}
private SecureString ConvertToSecureString(string password)
{
var securePassword = new SecureString();
foreach (char c in password)
securePassword.AppendChar(c);
securePassword.MakeReadOnly();
return securePassword;
}
Error:
There was an error parsing WS-Trust response from the endpoint. This may occur if there is an issue with your ADFS configuration. See https://aka.ms/msal-net-iwa-troubleshooting for more details.
Error Message: Object reference not set to an instance of an object