-
Notifications
You must be signed in to change notification settings - Fork 111
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
Consider making Authenticator
a Clone
#133
Comments
Previous API would consume instances of the Authenticator and therefore prevent users from enabling token reuse between publishers or other oauth-enabled applications. This is likely something that can be removed again once/if dermesser/yup-oauth2#133 is resolved.
Previous API would consume instances of the Authenticator and therefore prevent users from enabling token reuse between publishers or other oauth-enabled applications. This is likely something that can be removed again once/if dermesser/yup-oauth2#133 is resolved.
Previous API would consume instances of the Authenticator and therefore prevent users from enabling token reuse between publishers or other oauth-enabled applications. This is likely something that can be removed again once/if dermesser/yup-oauth2#133 is resolved.
I'll chime in with my thought, but leave it up to @dermesser to see if he's interested in pursuing this. I would like to leave it up to the user of the library to choose what they need. I tend to avoid wrapping Arc's in the internal implementation unless the implementation requires the cloning. For one it's not obvious without looking at the implementation how efficient the |
I agree with @ggriffiniii although mostly with the last sentence. Given we are dealing with API interactions here, the overall performance impact is usually negligible. But wrapping Authenticator objects in your code seems like the right level of abstraction. Making everything thread-safe would also restrict the kinds of caches we could implement, I believe. |
Consider probably the most obvious way to write down a crate using // in banana_crate
struct Banana<C> { authenticator: Authenticator<C>, ... }
impl<C> Banana<C> {
fn new(auth: Authenticator<C>, ...) -> ... { ... }
} And this is, broadly, fine. Until some application depends on both // in peach_crate
struct Peach<C> { authenticator: Arc<Authenticator<C>>, ... }
impl<C> Peach<C> {
fn new(auth: Authenticator<C>, ...) -> ... { ... }
} There is nothing user of both of these crates can do then to make both We could go and recommend every crate accepting |
Why wouldn't the clients accept a shared reference to the Authenticator? Why do they need to take ownership? |
That’s a good question. Historically none of the generated google API bindings took See e.g. PubSub, which takes anything implementing As far as users of modern yup-oauth2 are concerned, I could only find 3 crates in the list of reverse dependencies:
|
Strongly agreed on this point, however. I recently filled hyperium/hyper#2239 for a similar reason. |
Chiming in here to say that having |
we can take a look again... some things have changed since this issue was created. Looking at the code, I believe the main reason making (aa) Cloning it is not always trivial, especially with new custom storage providers, but also with existing ones (#146), although I guess it could be done. (b) Storage is supposed to be shared among all clients. It is not that useful to refresh a token a dozen times just because you have cloned |
I personally have been swayed by the arguments in favor of adding Clone, but again it's up to you @dermesser. Like mentioned above since the authenticator is designed to be shared its already using internal locking and shared references for everything. Throwing all of the Authenticator implementation inside an Arc should be pretty straightforward if we wanted to do it. |
@ggriffiniii I will trust your expertise, then :) If this is only about moving the internals to a separate struct inside an Arc, then I don't see a problem indeed. |
In many instances the libraries based on yup_oauth2 will take the
Authenticator
by value. This, however, prevents reuse of the tokens between different libraries or even instances of whatever type represents some sort of behaviour of a single library.It seems like the primary reason
Authenticator
currently cannot beClone
is its implementation ofStorage
, which internally stores aMutex<HashMap<_, _>>
. A trivial solution would be to wrap that into anArc
, however, using some lock-free thread-safe storage would likely be a more lasting solution.The text was updated successfully, but these errors were encountered: