Oauth/token api not working if realm is Azure AD connection

running this code will return error:
{ error: ‘invalid_grant’,
error_description: ‘Invalid username or password’ }

CODE:

var request = require(“request”);

var option = {
method: ‘POST’,
url: ‘https://mytenantname.auth0.com/oauth/token’,
headers: {
‘content-type’: content_type
},
body: {
grant_type: ‘http://auth0.com/oauth/grant-type/password-realm’,
realm: ‘test-waad’,
username: username,
password: password,
audience: audience,
scope: scope,
client_id: client_id,
client_secret: client_secret
},
json: true
};

request(options.resourceOwner, function (error, response, body) {
if (error) throw new Error(error);

console.log(body);
});

My application is setup with Azure AD connection.
I want to use API to return the ID Token and Access Token.
If I am using On-Prem AD, it works. Once I switch to AAD, it gives me error of “Invalid username or password”.
But I confirm that username and password are all correct.

Am I doing anything wrong? Is it the right API endpoint?
Please help.

Hey there!

Sorry for such delay in response! We’re doing our best in providing the best developer support experience out there, but sometimes the number of incoming questions is just too big for our bandwidth. Sorry for such inconvenience!

Do you still require further assistance from us?

this had been resolved. please close it. Thanks.

1 Like

Thanks a lot! Glad you have it working!