httpyac icon indicating copy to clipboard operation
httpyac copied to clipboard

Allow self-signed certificates for oauth2 flows.

Open arturomonge opened this issue 2 years ago • 3 comments

Hi,

I've just started to use httpyac, and everything is working great (thank you for the great work on this tool!). I started implementing oauth2 flows, and I found that I cannot use our IdentityServer dev container (which uses a self-signed certificate) as we always get the following error from Node.js: DEPTH_ZERO_SELF_SIGNED_CERT. In the authorization code flow, for example, the first call to IdentityServer works, the browser is opened, and the authentication process is completed in the browser. However, when the code is received and httpyac tries to exchange it for a token, I get the error.

I tried the following settings:

In the HTTP file:

# @no-reject-unauthorized

In the VS code settings.json file:

"httpyac.requestGotOptions": {
	"rejectUnauthorized": false
}

In the httpyac.config.js file:

module.exports = {
    request: {
        https: {
            rejectUnauthorized: false
        }
    }
}	

This happens with both httpyac and vscode-httpyac. With httpyac, it is easier to solve the problem, because I can set the NODE_TLS_REJECT_UNAUTHORIZED=0 env var during the terminal session. For vscode-httpyac, however, the only solution is to set it globally for Node.js, which is not a recommended practice.

Is there any way to disable the validation of SSL certificates in the oauth2 flows? Could this be added? I see that the request is created here (for example, for the Authentication Code Flow), but from what I see, none of the options provided in the docs are used in these flows to disable SSL validation.

Thank you.

arturomonge avatar Dec 22 '23 03:12 arturomonge

I have to admit that I hadn't really thought of such an application. OAuth2 server with a non-valid certificate, there are such things:-) Now rejectUnauthorized should be supported. I have also added a way to change the request itself using a function.

{{
  exports.oauth2_interceptRequest = function(request, context) {
    console.info(request);
  }
}}
GET https://httpbin.org/anything
Authorization: oauth2 password

AnWeber avatar Dec 22 '23 20:12 AnWeber

@AnWeber Yes, we use docker-compose for quickly creating service-specific dev environments when working on each of our services, and one of the containers in the stack is our identity provider, which uses a self-signed certificate, 😄. We could use the production IdP and create dev accounts there, but it's so much easier to create it as part of the dev stack with pre-configured test data. Thank you for adding this change!

arturomonge avatar Dec 23 '23 18:12 arturomonge

@arturomonge I find it interesting how the different development setups are structured. And yes, my development setup is more like the second one you described. And locally I only run dev tools or fake servers and mock certain error cases. I'll release the updates over the next few days. I just wanted to have a look because I wanted to include another small change. But let's see how that goes.

AnWeber avatar Dec 23 '23 19:12 AnWeber