Error ECONNREFUSED every time I try to hit an API endpoint

This is pretty much my entire request

await axios.get(
            {
                url: process.env.AUTH0_AUDIENCE + `users/${user.sub}`,
                headers: {
                    'Authorization': `Bearer ${process.env.AUTH0_TOKEN}`,
                    'Content-Type': 'application/json'
                }
            }
        )

I’ve made sure the following information is correct

The user.sub is literally the user object’s sub property
the auth0_token is correct (copied from the test page and was working previously)
AUTH0_AUDIENCE is the address of my api

every time I try to make this request I get a very long network error that amounts to

cause: AggregateError
       at internalConnectMultiple (node:net:1114:18)
       at afterConnectMultiple (node:net:1667:5) {
     code: 'ECONNREFUSED',
     [errors]: [
       Error: connect ECONNREFUSED ::1:80
           at createConnectionError (node:net:1634:14)
           at afterConnectMultiple (node:net:1664:40) {
         errno: -111,
         code: 'ECONNREFUSED',
         syscall: 'connect',
         address: '::1',
         port: 80
       },
       Error: connect ECONNREFUSED 127.0.0.1:80
           at createConnectionError (node:net:1634:14)
           at afterConnectMultiple (node:net:1664:40) {
         errno: -111,
         code: 'ECONNREFUSED',
         syscall: 'connect',
         address: '127.0.0.1',
         port: 80
       }
     ]
   }

I’ve tried adding the auth0 api domain to my allowed CORs origins and I added http://127.0.0.1:80 and http://localhost:5000 to my allowed Cors and allowed web origins in my auth0 application (not sure if that would do anything because 127.0.0.1 is an internal address) there doesn’t seem to be any option to update the CORs origins in the API config for auth0.

It seems to me this isn’t an authentication issue or an error in my code auth0’s firewall is just straight up throwing out the request and I’m not sure what I can do to fix it

Hi @snakebite-382,

Welcome to the Auth0 Community!

This error indicates the request is timing out. This is usually because you are trying a URL that can’t resolve and is often because of a typo or misconfig in your env variables. Please double check the URL you are trying and confirm that it exists.

Feel free to DM it to me if you want me to take a look.

Thanks!

1 Like

Did some digging, found that I can hit the following url with a 401 error “https://{tenant}.us.auth0.com/api/v2/user” and that works fine, directly copy pasted that into the url and still the refused to connect error

1 Like

What do you see from the axios response.request object? (I think) This should include the request URL.

I looked through the error I got again (won’t paste the whole thing here it’s insanely long and includes some sensitive information like auth keys that I don’t trust myself to edit out completely), found the URL param, and if I just copy paste that right into the address bar I get a 401 error returned which makes sense because I’m not authorized but I still get a connection refused error if I try to do it programmatically

It sounds like there is something between your application and Auth0 that is blocking the connection. Maybe a firewall or some security software on your machine.

1 Like

I checked my computer’s firewall config, made a rule to allow all traffic in and out on port 80 (not a great idea but something), and allowed incoming traffic. No change what else could be blocking the request on my end?

The other weird thing is I’m not having any trouble doing things like connecting to my database, or authenticating auth0 issued JWTs

Alright, found a temporary solution, setting the CORS allowed origins to “*” in my server config seems to work. So I would assume it’s CORS. I’m not sure what origin to allow to stop this.

CORS was not the issue, that did not actually resolve my issue

What did work, oddly enough, was switching to the auth0 npm package and making requests using the ManagementClient instead of axios

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.