Commit Graph

104 Commits

Author SHA1 Message Date
Kyle Gentle
c76ae18224 feat(Authenticator client): Accept custom connectors
Update Authenticator to accept clients with custom connectors, rather
than depending on the sealed hyper::client::connect::Connect trait, as recommended by hyper: https://docs.rs/hyper/0.13.8/src/hyper/client/connect/mod.rs.html#256-258

Closes #177.
2022-05-22 16:29:02 -04:00
Renar Narubin
aacb97d76c Remove file IO panic in ApplicationDefaultCreds flow
The `from_environment` function in
`ApplicationDefaultCredentialsAuthenticator` had an `unwrap` call on an
io::Result after reading the service account key from file. File
operations are inherently fallible, and panicking on such a failure is
generally a bad convention compared to propagating the IO error.

Propagating that error from the `from_environment` function is not
practical however, because the returned Result type does not include IO
errors, and changing the function signature would be semver
incompatible.

This change instead defers reading the key file to a later function
call. Now `from_environment` only reads the value of the
`GOOGLE_APPLICATION_CREDENTIALS` into a PathBuf, and a later call to
`ServiceAccountFlow::new` will actually read the file. That constructor
already returns an io::Result, so folding the read error into it is
possible, and none of the changes impact public items so it's all
semver-compatible.
2022-05-18 21:05:37 -07:00
David Schmitt
69e3a0289b docs: minor typo in docstring 2022-05-07 16:39:44 +01:00
Lewin Bormann
fb658f6d10 Merge pull request #173 from djc/rustls-0.20
Upgrade rustls and related dependencies
2022-04-18 18:44:18 -07:00
Lewin Bormann
378dca1148 rustls upgrade: supply correct client in test cases 2022-04-18 18:39:57 -07:00
Dirkjan Ochtman
32b6d8fa63 Allow testing without https 2022-04-11 11:38:25 +02:00
Lewin Bormann
bfe622eaaf clean-up: fix most clippy warnings 2022-04-08 23:35:15 -07:00
Lewin Bormann
986bda2465 Merge branch 'pr165'
for #165
2022-04-08 23:27:45 -07:00
Dirkjan Ochtman
f9c59bb743 Upgrade rustls and related dependencies 2022-04-06 11:22:05 +02:00
Lewin Bormann
95d46f53b8 Also feature-gate doc test for #170 2022-03-22 18:31:39 +01:00
Lewin Bormann
35a3117047 Fix feature gating of function for #170 2022-03-22 18:24:31 +01:00
Federico Cergol
e9cb1e43eb fix: service_account feature flag placement 2022-03-09 18:31:10 +01:00
Federico Cergol
b4c5ef8527 feat: add authorized user authenticator 2022-03-05 16:31:12 +01:00
Lewin Bormann
6aca7fbae5 for #169: also fix a doc test 2022-02-24 13:42:09 +01:00
Cameron Taggart
eb2d09870b more #[cfg(feature = "service_account")] 2022-02-24 07:23:09 -05:00
Lewin Bormann
9b81a7183e Make rustls dependency optional by introducing "service_account" feature
Now, service_account code must be (implicitly) enabled.

Asked for in feature #168
2022-02-22 20:10:39 +01:00
Björn Weinehall
6e6579ab59 Add ID token support 2021-12-17 16:25:02 +01:00
Glyn Normington
a1250e1728 Recreate token cache if token refresh fails
Fixes https://github.com/dermesser/yup-oauth2/issues/163
2021-12-15 17:49:14 +00:00
Lukas Winkler
39c712dfab Remove no longer applicatble TODO's 2021-12-01 13:50:16 +01:00
Lukas Winkler
c7793063e4 Add feature gates where required 2021-11-25 20:01:59 +01:00
Lukas Winkler
cd821f575d Make doc tests pass 2021-11-25 19:45:08 +01:00
Lukas Winkler
169e5ff1c0 Allow overriding metadata url used during testing 2021-11-25 19:37:11 +01:00
Lukas Winkler
792cc04694 Extend to provide with_client as well 2021-11-25 17:36:39 +01:00
Lukas Winkler
7818c6a460 Make work with new structure after rebase 2021-11-25 16:45:26 +01:00
Antti Peltonen
921f1c7190 builder pattern for adc struct 2021-11-21 09:57:07 +01:00
Antti Peltonen
7638946508 work started on adc implementation 2021-11-21 09:57:06 +01:00
Simonas Kazlauskas
469f045247 Use a test matrix to test feature combinations 2021-06-29 14:07:53 +03:00
Simonas Kazlauskas
dd004fed3c Implement an ability to work without default client 2021-06-29 13:30:40 +03:00
Simonas Kazlauskas
d385601433 --all-features and --no-default-features
This adjusts the code and documentation for `--all-features` and
`--no-default-features` to work correctly. With `--no-default-features`
no `DefaultAuthenticator` is made available. Users are in control of
picking the `Connector` they want to use, and are not forced to stomach
a dependency on `rustls` or `hyper-tls` if their TLS implementation of
choice doesn't happen to match one of the two.

To indicate this, the unstable `doc_cfg` feature is used to build
documentation on docs.rs. That way the generated documentation has
notices on these types that look as such:

> This is supported on crate features hyper-rustls or hyper-tls only.

Additionally this functionality is tested via additional coverage in the
Actions' CI.
2021-06-29 12:57:57 +03:00
Lewin Bormann
e63aa4b843 Merge pull request #146 from djrodgerspryor/custom_storage_options
Custom token storage
2021-04-01 22:53:36 +02:00
Daniel Rodgers-Pryor
6e4503f55e Simplify with_storage interface
By only allowing a custom storage. To use one of the built-in storage mechanism, there is already a special-purpose `persist_tokens_to_disk` method available.
2021-03-25 21:20:21 +11:00
Lewin Bormann
83296afc83 Run rustfmt on authenticator.rs 2021-03-04 19:33:08 +01:00
Lewin Bormann
010668cc62 Make Authenticator Clone 2021-03-04 19:32:20 +01:00
Daniel Rodgers-Pryor
384963e091 Revert mutable authenticator interface change
Instead, suggest using interior mutability (and RwLock in the example) to manage storage of token states. This makes it easier to share authenticators between threads.
2021-02-06 22:59:00 +11:00
Daniel Rodgers-Pryor
5ef498f801 Custom token storage
Allow users to build their own token storage system by implementing the `TokenStorage` trait. This allows use of more secure storage mechanisms like OS keychains, encrypted files, or secret-management tools.

Custom storage providers are Box-ed to avoid adding more generics to the API — the indirection cost will only apply if using a custom store.

I've added `anyhow` to allow easy handling of a wide range of errors from custom storage providers.
2021-02-06 22:59:00 +11:00
Lyon Beckers
26db4b6efc introduced a feature which allows the use of hyper-tls instead of hyper-rustls 2021-01-29 16:58:06 -07:00
Maxime Bedard
07bc4803c0 update hyper-rustls to 0.22 2020-12-26 19:30:43 -05:00
Lewin Bormann
9bf40bef5b Authenticator: Switch from keep_alive to pool_max_idle_per_host 2020-10-27 11:10:57 +01:00
Lewin Bormann
4660676073 Revert "Upgrade tokio -> 0.3: Bump version to v5.0.0"
This reverts commit e07bc6f471.

Hyper and tokio 0.3 don't work together yet.
2020-10-20 17:47:39 +02:00
Lewin Bormann
e07bc6f471 Upgrade tokio -> 0.3: Bump version to v5.0.0 2020-10-20 16:28:46 +02:00
George Hahn
b891e9e670 Expose default authenticator type
This allows downstream users to avoid a dependency on hyper
2020-05-01 11:25:25 -05:00
Abdul Rehman
09d1f05a00 feat: Use futures-aware mutex 2020-04-06 15:31:49 +05:00
Lewin Bormann
35157400ad chore(rustfmt): Run rustfmt 2020-03-16 19:15:14 +01:00
Lewin Bormann
1e492c7393 feat(refresh): Allow forcing Authenticator to refresh a token
On #125
2020-03-16 18:33:15 +01:00
Glenn Griffin
9238153723 Move to hyper 0.13.1!!!! 2019-12-18 09:07:45 -08:00
Glenn Griffin
5c0334ee6f Add debug logging.
Could be helpful when troubleshooting issues with various providers if
the user is able to turn on debug logging. The most critical logging
provided is the request and responses sent and received from the oauth
servers.
2019-12-18 09:07:45 -08:00
Glenn Griffin
36d186deb4 Authenticator now returns an AccessToken.
What was previously called Token is now TokenInfo and is merely an
internal implementation detail. The publicly visible type is now called
AccessToken and differs from TokenInfo by not including the refresh
token. This makes it a smaller type for users to pass around as well as
reducing the ways that a refresh token may be leaked. Since the
Authenticator is responsible for refreshing the tokens there isn't any
reason users should need to concern themselves with refresh tokens.
2019-12-18 09:07:45 -08:00
Glenn Griffin
5e39a81894 Go back to waiting for disk writes on every token set.
Defering disk writes is still probably a good idea, but unfortunately
there are some tradeoffs with rust's async story that make it non-ideal.
Ideally we would defer writes, but have a Drop impl on DiskStorage that
waited for all the deferred writes to complete. While it's trival to
create a future that waits for all deferred writes to finish it's not
currently possible to write a Drop impl that waits on a future.

It would be possible to write an inherent async fn that takes self by
value and waits for the writes, but that method would need to be
propogated up all the way to users of the library and they would need to
remember to invoke it before dropping the Authenticator.
2019-12-18 09:07:45 -08:00
Glenn Griffin
497ebf61c5 Add a test to ensure that Authenticator is Send+Sync 2019-12-18 09:07:45 -08:00
Glenn Griffin
635bd5e21a Fix a bug introduced in the storage layer.
When bloom filters were added the btreemap values changed to be a
vector of tokens to accomodate the possibility of bloom filter
collisions. The implementation naively just pushed new tokens onto the
vec even if they were replacing previous tokens meaning old tokens were
still kept around even after a refresh has replaced it. To fix this
efficiently the storage layer now tracks both a hash value and a bloom
filter along with each token. Their is a map keyed by hash for every
token that points to a reference counted version of the token, and each
token also exists in a separate vector. Updates to existing tokens
happens in place, when new entries are added they are added to both data
structures.
2019-12-18 09:07:45 -08:00