I have just started with Auth0, got through some videos read the docs and made an small local nodejs client app (localhost:3000) that could authenticate using the forms from Auth0.
Then i took a look howto protect an Api and how to access it from that client.
What i have so far:
Code:
NodeJs Client App on localhost 3000
NodeJs API on localhost 3001 - sample code from Auth0 doc that checks the jwt token
Auth0:
Created an Client called ExpressClient (set the urls; login with id-token works with NodeJS client app)
Created an API called ExpressAPI
Setup M2M and authorized the “ExpressClient”
Code:
Added route “/token” with code to get an accss-token
The result is always an 401.
I expected by the given configuration in Auth0.com, that my client is recognized by client_id and Secret
and so i would get back an access_token.
on “Applications > APIs”, Tab “Machine to Machine Applications” i set client to authorized. I did not expand the client item there and did not set any further information, said “Permissions”.
I have tried two different approaches:
NodeJS Client App
using content-type: application/x-www-form-urlencoded
error.response.status: 403
error.response.data:
[
{"error":"1","error_description":"2","error_uri":"3"},
"unauthorized_client","Grant type 'client_credentials' not allowed for the client.",
"https://auth0.com/docs/clients/client-grant-types"
]
I’ve also tried using Postman with application/json there i got also 403 and it produced an log entry in Dashboard, but not when using the NodeJS Client App.
thanks for your reply. I think that was the problem for the 401 error caused in the client app.
Now i get an 403, and this time it is also shown in the logs.
So the main problem seems to be the grant type and that client_credentials are not allowed for the client. If i now have understood it the right way, this flow is reserved for M2M Applications, and i have configured the client app as “Regular Web Application”. So i need to follow an other kind of flow. I will try these out first.
Thanks again. I will accept your answer as the solving one, because in this case it’s the 401 that misleaded me, and for that you pointed to the solution. The 403 error is the right one, that gives the feedback what really is wrong in the way i try to receive an access-token.