# Create User then Login returns 401

**URL:** <https://community.auth0.com/t/create-user-then-login-returns-401/12862>\
**Category:** Get Help\
**Tags:** api, token, oauth, login\
**Created:** [July 5, 2018, 6:45pm UTC](https://community.auth0.com/t/create-user-then-login-returns-401/12862 "2018-07-05T18:45:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jt.turner](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jt.turner/32/8215_2.png) [@jt.turner](https://community.auth0.com/u/jt.turner)\
**Post date:** [July 5, 2018, 6:45pm UTC](https://community.auth0.com/t/create-user-then-login-returns-401/12862/1 "2018-07-05T18:45:12Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jt.turner](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jt.turner/32/8215_2.png) [@jt.turner](https://community.auth0.com/u/jt.turner)\
**Post date:** [July 6, 2018, 12:16am UTC](https://community.auth0.com/t/create-user-then-login-returns-401/12862/2 "2018-07-06T00:16:25Z")

</div>

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](mailto:connection%22:%22Username-Password-Authentication%22,%22email%22:%22mrotter+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](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](mailto:grant_type%22:%22password%22,%22username%22:%22mrotter+rider1530836081539@mailinator.com)”,“password”:“\*\*\*\*\*\*\*\*”,“client\_id”:“\*\*\*\*\*\*\*”}’ [https://bart-integration-tests.auth0.com/oauth/token](https://bart-integration-tests.auth0.com/oauth/token)

---

<div class="post-metadata">

**Author:** ![jt.turner](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jt.turner/32/8215_2.png) [@jt.turner](https://community.auth0.com/u/jt.turner)\
**Post date:** [July 6, 2018, 4:26pm UTC](https://community.auth0.com/t/create-user-then-login-returns-401/12862/3 "2018-07-06T16:26:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 17, 2018, 11:15am UTC](https://community.auth0.com/t/create-user-then-login-returns-401/12862/4 "2018-12-17T11:15:14Z")

</div>


