So I’ve found a way to validate Auth0 tokens using JWKS URI but this solution only works on self-hosted n8n. This is because you need access to jsonwebtoken and jwks-rsa libraries.
jsonwebtoken is already installed in n8n so you just need to make sure your env vars allow it to be used in workflow
jwks-rsa needs to be manually installed. Recommendation would be to build a custom docker image but you could ssh into the container as root and npm i -g jwks-rsa for instant satisfaction!
I also came across an alternative solution using the signing certificate. This solution doesn’t require installing additional dependencies.
How it works
Use JWT libraries to validate the token
Invalid tokens cause the libraries to throw errors
The code node settings are configured so that errors don’t stop the workflow but are instead redirected to the error branch
This means we can redirect invalid requests to the respond to webhook node
Valid requests will forward the webhook json with additional jwtPayload property which includes the decoded token value.
“Cannot find module ‘jwks-rsa’ [line 2, for item 0]”
You may need to restart the container after the install.
re: always getting invalid token, this is a bit tricky to debug but just so you know, I used the “Application > APIs > Auth0 Management API > Test” to generate the token I tested with. You might want to do the same just to validate the template.
Some things you could try
make sure the issuer and audience are the same for token and verify code. If you have a JWT token, stick it in jwt.io to take a look at what these values are.
The alternative I was testing, in order to get if the user had the email validated and which email, was to pass the JWT to a HTTP Request node
GET
https://mysite.us.auth0.com/userinfo
With the token in the Authorization header, so if the JWT is valid you get back the full user info, but you can’t check permissions for your specific app I assume.
Hmm your install steps seem fine and it should persist after you restart the container. Perhaps try setting both N8N_FUNCTION_ALLOW_BUILTIN and N8N_FUNCTION_ALLOW_EXTERNAL and set them to * (wildcard)?
Regarding the token’s actual contents, I think you can add custom scopes but I’ve never used Auth0 long enough to figure it out Maybe someone with more Auth0 experience can chip in here?