Skip to content
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

Invalid IncomingMessage method when 'neonctl auth' #180

Closed
frankievalentine opened this issue Mar 4, 2024 · 10 comments · Fixed by #189
Closed

Invalid IncomingMessage method when 'neonctl auth' #180

frankievalentine opened this issue Mar 4, 2024 · 10 comments · Fixed by #189
Labels

Comments

@frankievalentine
Copy link

Steps to reproduce

neonctl auth opens browser correctly, but upon hitting Authorize the command fails to redirect browser shows localhost IP http://127.0.0.1:54310/

Expected result

Authenticate and redirect successfully

Actual result

Not authenticated

Environment

Node 20.11.1 and Node 18.18.0 same result

Logs, links

/opt/homebrew/Cellar/neonctl/1.27.3/libexec/lib/node_modules/neonctl/node_modules/openid-client/lib/client.js:373
          throw new TypeError('invalid IncomingMessage method');
                ^

TypeError: invalid IncomingMessage method
    at Client.callbackParams (/opt/homebrew/Cellar/neonctl/1.27.3/libexec/lib/node_modules/neonctl/node_modules/openid-client/lib/client.js:373:17)
    at Server.<anonymous> (file:///opt/homebrew/Cellar/neonctl/1.27.3/libexec/lib/node_modules/neonctl/auth.js:69:44)
    at Server.emit (node:events:518:28)
    at parserOnIncoming (node:_http_server:1151:12)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17)

Node.js v20.11.1
- 
@duskpoet
Copy link
Member

duskpoet commented Mar 5, 2024

Is this behavior constant for you? I can't seem to reproduce this

@frankievalentine
Copy link
Author

Is this behavior constant for you? I can't seem to reproduce this

Yes the behavior is constant. Maybe I am missing something because it's trying to connect to my localhost? Am I supposed to be actively connected to a newly created db in Neon before trying to authenticate?

@duskpoet
Copy link
Member

duskpoet commented Mar 6, 2024

No, only an account on Neon is required to use neonctl auth.
Localhost is expected, the flow is following:
neonctl auth -> cli starts a local server and opens request to the Neon auth provider in the browser, with redirect URL set to the local server URL -> you press "OK, auth" -> Neon auth provider redirects to the provided URL - 127.0.0.1: with query params containing necessary tokens -> cli gets tokens through this redirect, saves them and finishes the process

I see that error happens in the "OpenID" client and you do seem to have the latest cli version... I am a bit out of guesses. Maybe you could record a video and that will hopefully shine some light?

@johnowennixon
Copy link

johnowennixon commented Mar 21, 2024

I also am getting this error - but only on my second laptop. It worked fine on my almost identically configured main laptop. Both laptops are running Linux and have Chrome as the default browser - with a synchronised profile.

I had installed the latest version of neonctl and openid-client. But I tried earlier versions of both and got the same error.

Having added a console.log(input.method) in client.js, the invalid method is OPTIONS, which clearly is not a GET or PUT. I suspect the OPTIONS request is coming from my browser in a CORS pre-flight request. Why this has started happening on this browser, I have no idea.

I got the auth to work by temporarily switching from Chrome to Firefox as the default browser.

@duskpoet
Copy link
Member

Quick googling didn't give any results. Maybe you can provide more details?

@frankievalentine frankievalentine closed this as not planned Won't fix, can't repro, duplicate, stale Mar 23, 2024
@shin-hama
Copy link

I faced the same problem.

$ neonctl auth
/usr/local/Cellar/neonctl/1.27.5/libexec/lib/node_modules/neonctl/node_modules/openid-client/lib/client.js:373
          throw new TypeError('invalid IncomingMessage method');
                ^

TypeError: invalid IncomingMessage method
    at Client.callbackParams (/usr/local/Cellar/neonctl/1.27.5/libexec/lib/node_modules/neonctl/node_modules/openid-client/lib/client.js:373:17)
    at Server.<anonymous> (file:///usr/local/Cellar/neonctl/1.27.5/libexec/lib/node_modules/neonctl/auth.js:69:44)
    at Server.emit (node:events:511:28)
    at parserOnIncoming (node:_http_server:1121:12)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17)

Node.js v20.3.0

Changing my browser from chrome to safari worked around the problem.

@duskpoet duskpoet reopened this Mar 25, 2024
duskpoet added a commit that referenced this issue Mar 25, 2024
github-merge-queue bot pushed a commit that referenced this issue Mar 25, 2024
duskpoet pushed a commit that referenced this issue Mar 25, 2024
## [1.27.6](v1.27.5...v1.27.6) (2024-03-25)

### Bug Fixes

* process OPTIONS request in auth ([#189](#189)) ([61fc432](61fc432)), closes [#180](#180)
@duskpoet
Copy link
Member

🎉 This issue has been resolved in version 1.27.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

@duskpoet
Copy link
Member

Hey! I did an honest attempt :D
Can you please validate if it helped?

@frankievalentine
Copy link
Author

Fixed. Thank you @duskpoet. Curious, what was the issue?

@duskpoet
Copy link
Member

Some browsers went for OPTIONS request in front of normal GET request and such request was passed to the openid library, which was not tolerated and caused an error.
I've added some code to properly process an OPTIONS request with CORS headers in response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants