Byron / google-apis-rs

A binding and CLI generator for all Google APIs
http://byron.github.io/google-apis-rs
Other
1.01k stars 131 forks source link

Use generic Authy trait in place of yup_oauth2 #363

Closed philippeitis closed 1 year ago

philippeitis commented 1 year ago

I decided to give the "decouple" approach a try, as it fits my needs better.

I took the approach of creating an Authenticator trait which allows tokens to be generated asynchronously (as approached to the delegate, which requires sync). I believe the crates should still work as before for anyone not using a custom Delegate trait, as Hub::new accepts an instance of Authenticator, which is implemented for yup_oauth2::authenticator::Authenticator.

yup-oauth2 is no longer a required dependency, and can be disabled if a user should choose to do so by using default-features = false.

The only breaking change introduced is err parameter from the Delegate::token method. Given that the Authenticator implementation can handle any yup-oauth2 errors internally, it doesn't seem necessary for Delegate::token to also handle this.

There's a default implementation of Authenticator for String (user-provided oauth tokens) and () (no token at all - this seems like a good idea for APIs which do not use need oauth2)