nov / openid_connect

OpenID Connect Server & Client Library
MIT License
417 stars 122 forks source link

HTTP reconfiguration #84

Open fmang opened 1 year ago

fmang commented 1 year ago

Greetings,

Thank you for all the gems.

In order to reconfigure the Faraday client OpenIDConnect uses, I have tried the following:

OpenIDConnect.http_config { |faraday| … }
# Do something.

OpenIDConnect.http_config { |faraday| … }
# Do something with different settings.

However, this doesn’t work because OpenIDConnect.http_config only accepts the first configuration, and so do the gems for the sub-protocols. https://github.com/nov/openid_connect/blob/2fdafc3802aca1967790b079cb4e58ce5c4e9c93/lib/openid_connect.rb#L78-L83

I believe calling http_config multiple times should instead either sum the configurations (by storing the blocks in an array, for instance), or overwrite the configuration each time it is called. In the latter case, an explicit setter would be more intuitive, though slightly more verbose:

OpenIDConnect.http_config = ->(faraday) { … }

As a workaround, I have resorted to setting @@http_config directly instead, but that feels pretty hacky. I have noticed that Rack::OAuth2 provides a reset_http_config! method instead, but the other gems don’t, and a setter would feel more natural anyway.

Alternatively, I wish I could pass my HTTP configuration every time I instantiate a class that performs HTTP requests rather than rely on a global state.

Best regards.

gl-johnson commented 1 year ago

We have a need for this as well. Would like to be able to define a custom SSL config on a per-connection basis. We'd like to to support multiple OIDC providers where some of them may have custom CA certs and/or proxies that need to be able to pass TLS verification, with the user being able to configure the needed CA certs in the app.

Any plans to implement or accept contributions around this enhancement? Thanks!

nov commented 11 months ago

understood the needs, but no good idea at this time. I want to limit the scope of http_config like

OpenIDConnect.debug do
  # in debugging mode
end

# not in debugging mode