Commit Graph

197 Commits

Author SHA1 Message Date
Glenn Griffin
fa121d41b2 Delegates no longer need to implement Clone. 2019-12-18 08:53:22 -08:00
Glenn Griffin
7446200421 Remove unnecessary trait bounds on hyper connector.
Send+Sync is implied by the trait, and Clone is no longer necessary.
2019-12-18 08:53:22 -08:00
Glenn Griffin
0e9cf512ba Remove the HTTPRedirectEphemeral variant.
In favor of making it the default and removing the option to specify a
port to listen on. If needed a variant can be added to specify a port
explicitly, but most users should want an ephemeral port chosen so
making it the default makes sense while other breaking changes are in
flight.
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
2cf2e465d1 Add JsonErrorOr enum to make json error handling more concise/consistent.
JsonErrorOr is an untagged enum that is generic over arbitrary data.
This means that when deserializing JsonErrorOr<T> it will first check
the json field for an 'error' attribute. If one exists it will
deserialize into the JsonErrorOr::Err variant that contains a JsonError.
If the message doesn't contain an 'error' field it will attempt to
deserialize T into he JsonErrorOr::Data variant.
2019-12-18 08:53:22 -08:00
Glenn Griffin
29f800ba7f Some more improvements to reduce unnecessary allocations. 2019-12-18 08:53:22 -08:00
Glenn Griffin
bf0136067f Make some of the helpers a bit more idiomatic. 2019-12-18 08:53:22 -08:00
Glenn Griffin
e9b2a3a076 The inner GetToken on Authenticator no longer needs to be reference counted. 2019-12-18 08:53:22 -08:00
Glenn Griffin
a0c73d6087 No need to clone the hyper::Client
The ownership behavior is straightforward and more clear when not
cloning arbitrary handles.
2019-12-18 08:53:22 -08:00
Glenn Griffin
916aaa84e9 Authenticator.store no longer needs to be reference counted. 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
696577aa01 Accept scopes as a slice of anything that can produce a &str.
Along with the public facing change the implementation has been modified
to no longer clone the scopes instead using the pointer to the scopes
the user provided. This greatly reduces the number of allocations on
each token() call.

Note that this also changes the hashing method used for token storage in
an incompatible way with the previous implementation. The previous
implementation pre-sorted the vector and hashed the contents to make the
result independent of the ordering of the scopes. Instead we now combine
the hash values of each scope together with XOR, thus producing a hash
value that does not depend on order without needing to allocate another
vector and sort.
2019-12-18 08:53:22 -08:00
Glenn Griffin
7e210a22c5 Have TokenStorage take scopes by iterator rather than Vec.
This reduces the number of allocations needed.
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
Murph Murphy
a52625a071 fix(storage): storage clears all matching tokens
Change Storage to clear all existing JSONTokens with the current `hash` on set if at least one exists.

Fixes #117 if it's a real issue.
2019-12-16 14:50:24 -07:00
Cameron Taggart
d9bb9b7232 cargo fmt --all 2019-11-12 15:58:31 +01:00
Cameron Taggart
cce1a03f76 unwrap options in asert_eq 2019-11-12 14:41:40 +00:00
Cameron Taggart
b7703d40b4 make refresh_token an option 2019-11-11 22:44:31 +00:00
Lewin Bormann
09af50132a chore(fmt): rustfmt 2019-09-29 09:41:19 +02:00
Lewin Bormann
fbd38002fa chore(lint): Make clippy happy 2019-09-29 08:45:12 +02:00
Lewin Bormann
778e5afa8f Merge pull request #106 from ggriffiniii/master
Make RequestError Sync
2019-08-31 19:38:08 +02:00
Glenn Griffin
c33d0b8481 Make RequestError Sync
This requires enforcing that errors returned from TokenStorage
implementations are Send, which the ones in this crate are, but is a
breaking change because any external implementations may be returning
errors that are !Sync currently.

The motivation for this change is that Box<dyn Error + Send> is not as fully
supported within the rust stdlib as Box<dyn Error + Send + Sync>. In
particular there exists these two From impls:

impl<'a, E: Error + 'a> From<E> for Box<dyn Error + 'a>
impl<'a, E: Error + Send + Sync + 'a> From<E> for Box<dyn Error + Send + Sync + 'a>

but no corresponding impl for

impl<'a, E: Error + Send + 'a> From<E> for Box<dyn Error + Send + 'a>

This may just be an oversight in the rust stdlib that could be fixed,
but in practice it means that dealing with 'Error + Send' types is not
the most ergonomic because the '?' operator can't be used to convert
from a Box<dyn Error + Send> to a Box<dyn Error>.

Since the current implementations (not counting any external ones that
may exist) implement Sync this seems like a good tradeoff to make it a
little easier to use in an ergonomic way.
2019-08-30 11:53:45 -07:00
Glenn Griffin
fbb8c69efb Change the name of TokenGetterBuilder to AuthFlow.
I believe AuthFlow more succinctly describes the purpose of the type to
users reading documentation.
2019-08-29 11:48:29 -07:00
Glenn Griffin
ccc6601ff3 Use the builder pattern to create authenticators.
Beyond simply moving to the builder pattern for intialization this has a
few other effects.

The DeviceFlow and InstalledFlow can no longer be used without an
associated Authenticator. This is becaus they no longer have any
publicly accessible constructor. All initialization goes through the
Authenticator. This also means that the flows are always initialized
with a clone of the hyper client used by the Authenticator.

The authenticator uses the builder pattern which allows omitting
optional fields. This means that if users simply want a default hyper
client, they don't need to create one explicitly. One will be created
automatically. If users want to specify a hyper client (maybe to allow
sharing a single client between different libraries) they can still do so
by using the hyper_client method on the builder. Additionally for both
AuthenticatorDelegate's and FlowDelegate's if the user does not specify
an override the default ones will be used.

The builders are now exposed publicly with the names of Authenicator,
InstalledFlow, and DeviceFlow. The structs that actually implement those
behaviors are now hidden and only expose the GetToken trait. This means
some methods that were previously publicly accessible are no longer
available, but the methods appeared to be implementation details that
probably shouldn't have been exposed anyway.
2019-08-29 11:47:15 -07:00
Glenn Griffin
eb2a82f685 Make listening on an ephemeral port an option rather than the default. 2019-08-29 09:59:10 -07:00
Glenn Griffin
e83ec7e25e Have the installed flow http server always listen on an ephemeral port.
Specifying a port of zero has the server listen on an ephemeral port.
Many users may not be aware of that unless they have a background in
networking where that's common practice. I'm also not able to think of
any use cases where listening on a hardcoded port would be beneficial,
so with this change I've opted to remove the ability entirely rather
than simply documenting that almost everybody should specify zero.
2019-08-09 13:59:03 -07:00
Glenn Griffin
e0e955b2f6 Make fixes to support rust 1.35.0
Apparently 1.36.0 added From<&String> for String.
2019-08-08 15:01:01 -07:00
Glenn Griffin
2b18f3679e Modify GetToken::token.
Change it to accept an iterator of items that can be converted to
`String`s rather than an iterator of items that can be referenced as
`&str`s.

Primarily this allows it to be called with a larger variety of inputs.
For example ::std::env::args().skip(1) can now be passed directly to
token, where before it would first need to be collected into a vector.

Since all implementations unconditionally collected the iterator into a
vector this shouldn't have any negative impact on performance and should
actually reduce the number of allocations in some uses.

It simplifies the signature since the lifetime bounds are no longer
required.
2019-08-08 14:32:24 -07:00
Andrey Cizov
4ad59897c3 newly refreshed tokens forget to remove previous ones 2019-08-02 15:27:49 +01:00
Lewin Bormann
97d5355927 Merge branch '#100' 2019-08-01 21:38:17 +02:00
Lewin Bormann
58af9fc36b refactor(deps): Remove dependency on openssl. 2019-08-01 21:32:22 +02:00
Andrey Cizov
9b4a3ad3f4 rustfmt not passing 2019-08-01 19:56:28 +01:00
Andrey Cizov
6cac8f5a06 enable storage to only partially reference namespaces available for tokens 2019-08-01 17:52:42 +01:00
Lewin Bormann
ac08ac2da2 chore(fmt): rustfmt 2019-07-10 14:06:30 +02:00
Lewin Bormann
b6ed5c812e Merge pull request #97 from markcatley/salesforce-device-flow-updates
Updates to allow retrieving a token using the device flow on Salesforce.
2019-07-10 14:05:37 +02:00
Mark Catley
2ee218be55 Adding error logging to the Device Flow. 2019-06-28 09:49:56 +12:00
Mark Catley
ff8b3ede30 Updates to allow retrieving a token using the device flow on Salesforce. 2019-06-28 09:49:52 +12:00
Mark Catley
7459f167c5 Fixing typos and spelling in comments. 2019-06-28 09:46:59 +12:00
Lewin Bormann
57c84263c0 chore(syntax): Run rustfmt. 2019-06-22 22:49:39 +02:00
Lewin Bormann
b064129f77 fix(ServiceAccount): Fix left-over Box<Error> 2019-06-22 22:30:54 +02: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
8d6085375f doc(Installed): More documentation about InstalledFlow and new example 2019-06-22 20:25:47 +02:00
Lewin Bormann
ff015daf2d chore(fmt): Make rustfmt on Travis happy. 2019-06-22 12:33:38 +02:00
Lewin Bormann
d1952e9d67 test(Refresh): Properly process panics in RefreshFlow test. 2019-06-22 12:17:42 +02:00
Lewin Bormann
45431d83ff test(Device): Add tests for Device flow 2019-06-22 12:17:23 +02:00