simov / grant

OAuth Proxy
MIT License
4.08k stars 257 forks source link

getting { error: 'read ECONNRESET' } in callback for no reason #248

Closed venkateshgopalakrishnan closed 3 years ago

venkateshgopalakrishnan commented 3 years ago

Hi, I am not sure if this is a problem with Grant. But I just wanted help on this.

I can see that I am being redirected from the IdP with a code in the URL like this - /connect/provider/callback?code=<>. But from here when we enter the callback route I get { error: 'read ECONNRESET' } in req.session.grant.response. Not sure why this happens in the first place. Can anyone help me on this?

simov commented 3 years ago

Can you run your server using:

npm i --save-dev request-logs
DEBUG=req,res,json node app.js

This will print out the full request/response logs for the internal HTTP request that Grant is doing.

venkateshgopalakrishnan commented 3 years ago

While the same application gives me the full set of logs including the JWT in my local, I am only getting half of that in my remote server. It just gave me this when I ran it on my remote server...

req POST https://dev-83090317.okta.com/oauth2/default/v1/token
    user-agent:     simov/grant/5.4.12
    content-type:   application/x-www-form-urlencoded
    content-length: 254
    Host:           dev-83090317.okta.com
form
    grant_type:    authorization_code
    code:          <some random string>
    client_id:     ********************
    client_secret: *******************************************
    redirect_uri:  https://something.somethingelse.com:3000/api/connect/provider/callback
(node:1648461) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headerNames is deprecated
(Use `node --trace-deprecation ...` to show where the warning was created)
simov commented 3 years ago

So in case you run your server correctly with all of the debug flags DEBUG=req,res,json, then that means that for some reason the token exchange request fails, and you never really receive any response. Otherwise you would have seen the response as well.

venkateshgopalakrishnan commented 3 years ago

Seems the issue was with a server-side security policy applied, which prevented the token exchange from happening. Thanks for the help! I will close the issue.