Oauth/token responds with error": "invalid_grant", "error_description": "Invalid username or password" for Azure AD

I’m trying to evaluate a possible solution using auth0, most likely to be converted in business for auth0.

To achieve a common auth from AD and a user database, for which the database seems connection seems to be working fine, however when I try to use Azure AD auth, I get a response as below, though I’m using realm to specify connection name. Mu concern is that the sample connection using ‘try’ from connection works just fine, but not from API calls.

This is what I could get

    "error": "invalid_grant",
    "error_description": "Invalid username or password"

Here’s a sample code which I’m using.

json_request_parms = {
    "username": username,
    "password": password,
    "scope": scope,
    "client_id": client_id,
    "client_secret": client_secret,
    "realm": realm,
    "grant_type": "http://auth0.com/oauth/grant-type/password-realm",
    "audience": audience,
headers = {
    'Content-type': 'application/json'
requests.post(url=url, json=json_request_parms, headers=headers)

which return in the mentioned error.

Any help would be grateful.

@jmangelo Can you help me out here.

I am having the same problem. Can someone help?

have you found a solution for this yet?

Hey there!

Sorry for such huge delay in response! We’re doing our best in providing you with best developer support experience out there, but sometimes our bandwidth is not enough comparing to the number of incoming questions.

Wanted to reach out to know if you still require further assistance?

I have not used Azure AD with realm myself, but looking at your code snippet, and comparing to the example on:

Have you tried using a different content-type?

headers: {'content-type': 'application/x-www-form-urlencoded'},

and respective body. Not sure if json is accepted or not.
I assume your realm value is set correctly.

1 Like

Let us know if you have any questions about that down the road!