-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Make "use" return a middleware creation proc #2346
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
Conversation
|
I'm okay with this, but I do wonder if it's exposing too much of our internals. However, that ship has probably already sailed, so being more defined with the return value is probably okay. @jeremyevans wdyt? |
|
Thanks Samuel for the comment. I think a proc that just returns an instantiator for the requested class with the given arguments is what the user would expect and want, and does't expose anything likely to change. The This change isn't needed for OmniAuth, but without it it would have to create its own procs. |
|
If we are considering making a backwards incompatible change to the return value of In general, I don't think It's probably better if Omniauth creates it's own procs. |
|
Thanks Jeremy. Isn't the advantage of using procs that it doesn't waste time and memory creating a middleware until it's needed on a request, especially valuable in development mode. To do the same in OmniAuth I was planning something close to There's also a need for Rack itself to allow middleware lookups, which would be an alternative to the above, and could be done even if |
|
IMHO, you shouldn't be using global state for this. It would be better to create a container of strategies (e.g. |
|
I think you're right Samuel that aggregation of strategies is the better way, allowing individual strategy instances to be cached and looked-up internally. Unlike some middleware, strategies don't need to be continually re-instantiated/reset. I was trying to get away with minimal changes to more easily sell them to OmniAuth. But it looks again like half-arseing just defers the pain. |
I know your pain. |
I don't believe so. I think procs are only used here to combine the handling of maps and middleware. The procs are only supposed to be used by
This would be even easier if |
|
After discussion, it looks like we aren't going to merge this change. Thanks for your effort. |
OmniAuth uses Rack to add a middleware for each of its configured authentication strategies. At the moment, when one wants to use a strategy to create a properly-configured OAuth2 client for that strategy to refresh an access token and/or make endpoint calls, one must initialize one's own instance of that strategy, duplicating the Omniauth config with its
idandsecretclient keys (these can be nil if no token refreshing is needed).This duplication could be avoided if either Omniauth's
providerdeclarations returned a strategy creation proc (that is a closure for its arguments) or Omniauth provided anOmniauth::Strategy.get(name)method.The best way to do either is for Rack's
usemethod to return the middleware initialisation proc instead of the current array of middleware. This directly supplies what Omniauth'sprovidermethod returns, plus OmniAuth (or Rack) can store these procs in a Hash for lookup by name.Yes, a solution without any change is for Omniauth to return
use(...).last, but this makes it dependent on Rack's internals.So this PR changes
useto return the proc rather than the current array of procs. I don't see this as breaking any reasonable code.