Apologies as this is my first day trying out Auth0 and I must be doing something fairly silly. My issue is that I can’t get a token for a user based on their username/password .
What I did:
- Created a new database connection
MyDB
. - Created a new user
henry.green@erewhon.com
, gave them a passwordHelloWorld
and assigned them to that database connection. - Created a new API
Test Auth0 API
- Created a web app client
My App
and ensured thePassword
grant type was set. Also ensuredMyDb
was one of its connections.
From javascript (node.js) I then issue the following call (AUTH0_DOMAIN is my Auth0 assigned domain, AUTH0_CLIENT_ID and AUTH0_CLIENT_SECRET are set from MyApp’s config, and AUTH0_AUDIENCE is set from my test API’s config):
app.get('/api/getToken', function(req, res) {
var options = { method: 'POST',
url: `https://${process.env.AUTH0_DOMAIN}/oauth/token`,
headers: { 'content-type': 'application/json' },
json: true,
body: {
username: 'henry.green@erewhon.com',
password: 'HelloWorld',
client_id: `${process.env.AUTH0_CLIENT_ID}`,
client_secret: `${process.env.AUTH0_CLIENT_SECRET}`,
audience: `${process.env.AUTH0_AUDIENCE}`,
grant_type: 'http://auth0.com/oauth/grant-type/password-realm',
realm: 'MyDB'
}
};
The response I get is:
{
"error": "unauthorized",
"error_description": "Access denied."
}
which I presume either means my nodeapp didn’t have the rights to request this token, or my new user was unauthorised. At this point I’m a bit stuck, and would appreciate any assistance.