Auth0 Home Blog Docs

Create User then Login returns 401

token
api
oauth
login

#1

I am just playing around with adding Auth0 into an existing app. Since we are going through our own backend I was using the management API to create a user. Then I turn around and log them in using the authentication API oauth/token route but I get a 401 even though I just created the user. If I go to the connection try in the backend that user I just created can login there but the oauth/token route is still return 401. This is what my request is passing:
{
method: ‘POST’,
url: ${auth0Settings.url}/oauth/token,
headers: {
Accept: ‘application/json’
},
body: {
grant_type: ‘password’,
username: username,
password: password,
client_id: auth0Settings.authentication.clientId
}
}

Am I missing something?


#2

To give more information this is the curl I use to create the user (removing token and password:

curl -X POST -H ‘Content-Type: application/json’ -H ‘Accept: application/json’ -H ‘Authorization: Bearer ******’ -d ‘{“connection”:“Username-Password-Authentication”,“email”:“mrotter+rider1530835685615@mailinator.com”,“password”:"******",“user_metadata”:{“first_name”:“Skip”,“last_name”:“Tester Rotter”,“mobile”:“5035551212”,“password_updated_at”:“2018-07-06T00:08:07.132Z”},“app_metadata”:{“source_ref”:“mobileTicket”}}’ https://bart-integration-tests.auth0.com/api/v2/users

Here is the login curl I used:
curl -X POST -H ‘Accept: application/json’ -H ‘content-type: application/json’ -d ‘{“grant_type”:“password”,“username”:“mrotter+rider1530836081539@mailinator.com”,“password”:"********",“client_id”:"*******"}’ https://bart-integration-tests.auth0.com/oauth/token


#3

Ok after trying 100’s things I came to using http://auth0.com/oauth/grant-type/password-realm and setting the realm value to the name of the connection.