Auth0 Home Blog Docs

How to authorize user with email/password from server code?

authorization-code-f
serverside

#1

I am trying to use Auth0 to validate a user’s email and password, calling it from server code using simple HTTP calls. What I am doing is equivalent to

 curl --request POST \
  --url 'https://me.auth0.com/oauth/token' \
  --header 'content-type: application/json' \
  --data '{"grant_type":"password", "username": "mark@me.com", "password": "not this", "audience": "https://demo.me.com/auth0", "client_id": "client string", "client_secret": "secret string", "connection": "Username-Password-Authentication", "scope": "openid"}'

The login works from the test link on my management page, but both the curl command and my server code elicit this message:

Authorization server not configured with default connection.

The docs don’t really go into this case. I do have a connection of the name given above, and I can’t find any place to set a “default” connection.

Can anyone spot my problem?


#2

The docs for the resource owner password credentials (ROPC) grant available at /oauth/token do not indicate the support for a parameter named connection so that explains why passing it does not have any effect.

You can configure you account to have a default connection by navigating to your account settings and providing the connection name in the Default Directory field.

As an alternative, if you read further on the ROPC docs you’ll find that the endpoint supports an additional grant where you can specific the connection to be used in the request body itself using the realm parameter name. See:

https://auth0.com/docs/api-auth/tutorials/password-grant#realm-support


#3

Thank you, @jmangelo, that got me over the hump. With a little more struggling with poor docs and error messages I have managed to get registration and login working. I hope that password reset will be simple!


Using the Request Owner Password Endpoint on a new dev account
#4

Thank you, @jmangelo, that got me over the hump. With a little more struggling with poor docs and error messages I have managed to get registration and login working. I hope that password reset will be simple!


#5

where is the Default Directory field, pls?


#6

In your account settings accessible at the dropdown in the top right corner of your dashboard.


#7

What value do I use for the connection name?


#8

When you configure a database connection in the dashboard you will be asked to provide a name; anywhere that a connection name is required you should use the value you provided there. You can also check the name of existing connections through the dashboard.


#9

Hey @jmangelo ,

What if you want to use multiple Passwordless Auth Connections?
You can’t use realm cause it doesn’t allow passwordless
authentication and you can’t use the Default Directory cause
it accepts only one connection.
Is there any other solution?

Thank You!


#10

Hey @jmangelo ,

What if you want to use multiple Passwordless Auth Connections? You can’t use realm cause it doesn’t allow passwordless authentication and you can’t use the Default Directory cause it accepts only one connection. Is there any other solution?

Thank You!


#11