Commit Graph

47 Commits

Author SHA1 Message Date
Sarah Bird
2128772d88 Replace chrono with time 2022-03-11 19:39:11 -06:00
Glenn Griffin
9238153723 Move to hyper 0.13.1!!!! 2019-12-18 09:07:45 -08:00
Glenn Griffin
0a4c1e79d2 Make DeviceFlowDelegate::present_user_code return a Future.
This is to allow for implementations to use async code. The returned
Future will be awaited before polling for the token begins.
2019-12-18 09:07:45 -08:00
Glenn Griffin
4521e2f246 Rename PollInformation DeviceAuthResponse.
Have it correctly handle either verification_uri or verification_url and
deserialize into a struct that has the data types desired.
2019-12-18 09:07:45 -08:00
Glenn Griffin
d0880d07db Refactor error handling and as a consequence delegates.
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.
2019-12-18 09:07:45 -08:00
Glenn Griffin
2253c60b89 InstalledFlowDelegate::present_user_url should return a String error.
Prior to this change the only place present_user_url is called overwrote
the error with a static string. After this change the error returned is
appended to the message. No need to make the signature more complicated
when the error is always going to be flattened to a string anyway.
2019-12-18 09:07:45 -08:00
Glenn Griffin
8030d31da9 Reconsider Error variants
BadServerResponse didn't seem to be adequately different from
NegativeServerResponse so it's been removed. NegativeServerResponse is
now a struct variant with field names 'error' and 'error_description' to
self document what it contains.

InvalidClient and InvalidScope were only ever created based on string
parsing of the returned error message from the server. This seemed
overly specific to a particular implementation and didn't provide much
value to callers. Printing a NegativeServerResponse would provide users
the same information.

The caching layer never returns errors anymore so remove that variant.
2019-12-18 09:07:45 -08:00
Glenn Griffin
25ba7f0b1f Move the impls for PollError into error.rs
These should have been moved when error.rs was created but were missed.
2019-12-18 09:07:45 -08:00
Glenn Griffin
d63396a740 Split FlowDelegate into DeviceFlowDelegate and InstalledFlowDelegate.
Each flow invokes a non-overlapping set of methods. There doesn't appear
to be any benefit in having both flows use a common trait. The benefit
of splitting the traits is that it makes it clear which methods need to
be updated for each flow type where previously comments were required to
communicate that information.
2019-12-18 09:07:45 -08:00
Glenn Griffin
1d25341c66 Remove AuthenticatorDelegate::{client_error, request_failure}
These methods are never called.
2019-12-18 09:07:45 -08:00
Glenn Griffin
ca453c056c Improve documentation 2019-12-18 08:59:43 -08:00
Glenn Griffin
e5aa32b3cf Tidy up some imports.
No more need to macro_use serde. Order the imports consistently (albeit
somewhat arbitrary), starting with items from this crate, followed by
std, followed by external crates.
2019-12-18 08:59:43 -08:00
Glenn Griffin
ba0b8f366a Rename RequestError to Error
RequestError is the error value that encompasses all errors from the
authenticators. Their is an established convention of using Error as the
name for those types.
2019-12-18 08:57:24 -08:00
Glenn Griffin
0fe66619dd Minimize the number of items on the rustdoc landing page.
Restructure the modules and imports to increase the signal to noise
ration on the cargo doc landing page. This includes exposing some
modules as public so that they can contain things that need to be public
but that users will rarely need to interact with. Most items from
types.rs were moved into an error.rs module that is now exposed
publicly.
2019-12-18 08:57:24 -08:00
Glenn Griffin
911fec82f1 Make FlowDelegate object safe. 2019-12-18 08:57:24 -08:00
Glenn Griffin
88a8f74406 Refactor token storage.
The current code uses standard blocking i/o operations (std::fs::*) this
is problematic as it would block the entire futures executor waiting for
i/o.

This change is a major refactoring to make the token storage mechansim
async i/o friendly. The first major decision was to abandon the GetToken
trait. The trait is only implemented internally and there was no
mechanism for users to provide their own, but async fn's are not
currently supported in trait impls so keeping the trait would have
required Boxing futures. This probably would have been fine, but seemed
unnecessary. Instead of a trait the storage mechanism is just an enum
with a choice between Memory and Disk storage.

The DiskStorage works primarily as it did before, rewriting the entire
contents of the file on every set() invocation. The only difference is
that we now defer the actual writing to a separate task so that it does
not block the return of the Token to the user. If disk i/o is too slow
to keep up with the rate of incoming writes it will push back and
will eventually block the return of tokens, this is to prevent a buildup
of in-flight requests. One major drawback to this approach is that any
errors that happen on write are simply logged and no delegate function
is invoked on error because the delegate no longer has the ability to
say to sleep, retry, etc.
2019-12-18 08:57:24 -08:00
Glenn Griffin
ef23eef31d Remove more unnecessary clones. 2019-12-18 08:53:22 -08:00
Glenn Griffin
fa121d41b2 Delegates no longer need to implement Clone. 2019-12-18 08:53:22 -08:00
Glenn Griffin
8489f470a4 cargo clippy fixes 2019-12-18 08:53:22 -08:00
Glenn Griffin
4bd81c3263 cargo fmt 2019-12-18 08:53:22 -08:00
Glenn Griffin
9542e3a9f1 Remove instances of cloning ApplicationSecret
ApplicationSecret is not a small struct. This removes the instances
where it's cloned in favor of passing a shared reference.
2019-12-18 08:53:22 -08:00
Glenn Griffin
0f29c258c6 FlowType isn't used for anything. Remove it. 2019-12-18 08:53:22 -08:00
Glenn Griffin
a4c9b6034e Require trait implementations to be Send + Sync.
Tidy up some of the trait bounds on types and methods.
2019-12-18 08:53:22 -08:00
Glenn Griffin
93cbd91341 Move to std::futures to support async/await. 2019-12-18 08:53:22 -08:00
Lewin Bormann
4beb0e68e2 Merge branch 'futures'
This is #94.
2019-06-22 22:13:26 +02:00
Lewin Bormann
2d94e043d8 doc(misc): Add some small missing pieces. 2019-06-22 22:03:26 +02:00
Lewin Bormann
602ea1565d refactor(errors): Move almost everything to RequestError.
This is nicer than stupid Box<dyn Error+Send> everywhere.
2019-06-22 21:53:55 +02:00
Lewin Bormann
ff015daf2d chore(fmt): Make rustfmt on Travis happy. 2019-06-22 12:33:38 +02:00
Lewin Bormann
45431d83ff test(Device): Add tests for Device flow 2019-06-22 12:17:23 +02:00
Lewin Bormann
4cfbc6e5fc imp(Device): Honor FlowDelegate's opinion on pending authorization. 2019-06-13 16:07:32 +02:00
Lewin Bormann
86e71cca5d feat(DefaultFlowDelegate): Introduce DefaultFlowDelegate type.
This was necessary after splitting traits.
2019-06-13 15:28:25 +02:00
Lewin Bormann
71a45f059e refactor(delegate): Split AuthenticatorDelegate to have FlowDelegate 2019-06-12 21:16:28 +02:00
Lewin Bormann
58383f9a03 refactor(DeviceFlow): Make DeviceFlow work with Futures 2019-06-12 18:43:30 +02:00
Lewin Bormann
732e594962 refactor(InstalledFlow): Implement GetToken for InstalledFlow 2019-06-12 14:40:08 +02:00
Lewin Bormann
56e2edd4fd chore(syntax): Use dyn everywhere to prepare for deprecation. 2019-06-11 23:49:41 +02:00
Lewin Bormann
7c1731cac9 chore(rustfmt): cargo fmt 2019-06-11 23:41:55 +02:00
Lewin Bormann
c2fbee4dc8 rewrite(installed): Make the InstalledFlow asynchronous with futures. 2019-06-11 23:29:12 +02:00
Guy Taylor
9f7f3c3b95 Upgrade to Hyper v0.12
This upgrade Hyper to v0.12 and updats to code to work for it. It has
being done with the minimum code change and so the logic is still
aukward for the futures model. This should be addressed in later commits
but I did not want to compilcate an already large commit.
2019-05-26 11:08:32 +02:00
Lyle Mantooth
108162fcf8 imp: accept any string-like parameter
Use the power of the `AsRef` trait to take generic parameters for
several API functions. This makes the API more ergonomic because the
callers may pass in static `str` slices or references to owned `String`s
or even more exotic things like a `Cow`, all based on their particular
situation.

Update the tests and examples to use the most natural types they have
available.

Fixes #77. No existing code should break, as `&String` implements
`AsRef<str>` and `AsRef<Path>`
2019-04-03 09:01:28 -04:00
Guy Taylor
b96cfcd66a Format to fustfmt defaults and force lint check in Travis 2019-02-21 20:46:00 +00:00
Lewin Bormann
39e6baa9c0 Merge pull request #84 from mashedcode/nit-weird-return-value-required
imp(flows) don't require present_user_url to return an additional char
2019-02-15 17:37:32 +01:00
mash
a7d5c40f5b imp(flows) don't require present_user_url to return an additional char
For custom AuthenticatorDelegate implementations it may be very weird to
be required to return an additional character after the code from
present_user_url.

One may find himself chasing the bug which is bad UX for the user.

Improve this behavior and therefore introduce a breaking change that
will hopefully not break existing implementations nevertheless.
2019-02-15 16:24:12 +00:00
mash
4497eeb31a feat(flows): allow custom redirect uri
When implementing AuthenticatorDelegate one might want to change the
redirect_uri to use an authorized domain or just change the way
InstalledFlow works.

Add a redirect_uri method to AuthenticatorDelegate that may be
implemented to define a custom redirect uri if needed.
2019-02-12 16:48:08 +00:00
Jamie Turner
ab4b2c2fd4 Rust 2018 edition modifications. 2019-01-04 12:43:19 -08:00
Igor Gnatenko
e634d3f139 deps: update chrono to 0.4
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
2018-07-25 22:47:52 +02:00
Lewin Bormann
85b12dd3e8 refactor(common): Rename common -> types 2016-08-31 20:01:24 +02:00
Lewin Bormann
9e59bf0496 refactor(all): More flows demand for a different structure
I mainly resolved some circular dependencies that had crept in, and
moved code around. I renamed helper.rs because that was not really an
appropriate name anymore, and moved the delegate code into a new module.
2016-08-31 19:48:38 +02:00