This Removes RefreshError and PollError. Both those types can be fully represented within Error and there seems little value in distinguishing that they were resulting from device polling or refreshes. In either case the user will need to handle the response from token() calls similarly. This also removes the AuthenticatorDelegate since it only served to notify users when refreshes failed, which can already be done by looking at the return code from token. DeviceFlow no longer has the ability to set a wait_timeout. This is trivial to do by wrapping the token() call in a tokio::Timeout future so there's little benefit for users specifying this value. The DeviceFlowDelegate also no longer has the ability to specify when to abort, or alter the interval polling happens on, but it does gain understanding of the 'slow_down' response as documented in the oauth rfc. It seemed very unlikely the delegate was going to do anything other that timeout after a given time and that's already possible using tokio::Timeout so it needlessly complicated the implementation.
yup-oauth2 is a utility library which implements several OAuth 2.0 flows. It's mainly used by google-apis-rs, to authenticate against Google services. (However, you're able to use it with raw HTTP requests as well; the flows are implemented as token sources yielding HTTP Bearer tokens).
The provider we have been testing the code against is also Google. However, the code itself is generic, and any OAuth provider behaving like Google will work as well. If you find one that doesn't, please let us know and/or contribute a fix!
Supported authorization types
- Device flow (user enters code on authorization page)
- Installed application flow (user visits URL, copies code to application, application uses code to obtain token). Used for services like GMail, Drive, ...
- Service account flow: Non-interactive authorization of server-to-server communication based on public key cryptography. Used for services like Cloud Pubsub, Cloud Storage, ...
Usage
Please have a look at the API landing page for all the examples you will ever need.
A simple commandline program which authenticates any scope and prints token information can be found in the examples directory.
The video below shows the auth example in action. It's meant to be used as utility to record all server communication and improve protocol compliance.
Versions
Version 1.x for Hyper versions bellow 12 Version 2.x for Hyper versions 12 and above
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
