-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Authorization code flow results in "connect ECONNREFUSED 127.0.0.1:443" #158
Comments
Hi @halestock
This error suggests that something is trying to connect to https://localhost, but nothing is running on https://localhost
This suggests that it's being caught by https://github.com/auth0/express-openid-connect/blob/master/middleware/auth.js#L105 which would suggest that the error is being thrown from So if I had to guess I would say that |
That's correct. We actually use a custom localhost domain - and it's run on http, not https (though it's just an alias for localhost, which is still accessible).
Correct, that's exactly the call that ultimately throws (and auth.js#L105 is where it's caught).
|
So, assuming the failure when calling |
I was more thinking along the lines of |
Gotcha. So, I don't think it's a misconfiguration issue, because on fresh start (with no cookies) of the web server, I'm redirected to auth0 for login successfully (and actually, on that first login, i'm redirected back and everything works fine). It's on subsequent auth flows that I start seeing this issue:
If (without restarting the server) I try logging in as a different user on a new private chrome tab, I again get the same error. If I restart the web server, it will start working again for that initial auth flow (both with a new private chrome tab as well as a tab that still has the existing session cookies.) |
Hi @halestock - thanks for sharing that. I'm not able to reproduce the issue following your steps on an app with the configuration you've described. If you can provide an example app where I can reproduce the issue I might be able to help you debug it. Alternatively, you could try putting a breakpoint around here https://github.com/panva/node-openid-client/blob/master/lib/helpers/client.js#L148 and seeing what code exchange request is being made and if it's successful.
The only other thing that stands out is the short absolute duration of your session - you could also try reproducing the issue with a larger number (like 1 hr) |
Sure, I'll try that and let you know. I'll also bump up the session length to rule that out (was only setting it that short for some unrelated session handling code). |
Also, I would expect you to be already logged in - since cookies are shared across private tabs in Chrome |
Ah, sorry, I should have been more clear. In that context I meant that I was clearing session/cookies (by closing the existing private windows) and starting from a clean slate. If I do open a new tab while one is open (which shares the existing session/cookies) after a successful login, it continues to work since it does not go through the auth flow again. |
Alright, I think I'm getting somewhere. If I wrap https://github.com/panva/node-openid-client/blob/master/lib/helpers/client.js#L148 in a try/catch with await, I get the ECONNREFUSED error as above. If I go down a layer, the http call is made at https://github.com/panva/node-openid-client/blob/master/lib/helpers/request.js#L53. If I wrap that call in a try/catch, I still get ECONNREFUSED, which to me means it's likely coming from the This is the (sanitized) request options to {
"form": {
"grant_type": "authorization_code",
"code": "{code}",
"redirect_uri": "http://{localdomain}:14251/auth/callback",
"code_verifier": "{code}"
},
"responseType": "json",
"headers": {
"Authorization": "Basic {token}",
"User-Agent": "express-openid-connect/2.0.0",
"Auth0-Client": "{id}"
},
"method": "POST",
"url": "https://{domain}.us.auth0.com/oauth/token",
"followRedirect": false,
"retry": 0,
"timeout": 5000,
"throwHttpErrors": false
} And this is the request options from a successful call: {
"form": {
"grant_type": "authorization_code",
"code": "{code}",
"redirect_uri": "http://{localdomain}:14251/auth/callback",
"code_verifier": "{code}"
},
"responseType": "json",
"headers": {
"Authorization": "Basic {token}",
"User-Agent": "express-openid-connect/2.0.0",
"Auth0-Client": "{id}"
},
"method": "POST",
"url": "https://{domain}.us.auth0.com/oauth/token",
"followRedirect": false,
"retry": 0,
"timeout": 5000,
"throwHttpErrors": false
} Which matches the failing call exactly (except for the codes/tokens/etc). Is it possible this is at play here? |
Yes, that looks like a likely candidate. Do you have a dependency on |
No, no dependencies on node-agent-base. |
Aha! It looks like I'm running a number of different versions of |
Well spotted, glad you got it sorted @halestock |
Yep, thanks much for the assistance! |
Heads up if anyone else runs into this, its |
Not sure why this is closed, but we fixed this with:
|
where need to put this?? |
|
Description
Hello, I am currently in the process of testing the upgrade path to 2.0.0 of this library using Auth0 as my oauth provider. After logging in to Auth0, the callback endpoint fails with the following error:
BadRequestError: connect ECONNREFUSED 127.0.0.1:443 at /Users/hsostock/code/connect-web/node_modules/express-openid-connect/middleware/auth.js:105:31 at processTicksAndRejections (internal/process/task_queues.js:97:5)
Note: After doing some debugging, it appears that this is the result of an internal call to
https://{auth0-domain}/.well-known/oauth-authorization-server
returning a404 Not Found
error (which, for some reason, is surfaced as the above connection refused error).Reproduction
I am using the following configuration in my express app:
And occurs consistently (as mentioned) when validating the authorization code returned from Auth0.
Environment
The text was updated successfully, but these errors were encountered: