-
-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to futures 0.3.0 and async await syntax (#71)
Add `futures-01` and `futures-03` feature flags. The `futures-03` feature flag adds a dependency on `reqwest` 0.10 (currently unstable), while the default `reqwest` feature flag continues to rely on `reqwest` 0.9, which doesn't support async/await.
- Loading branch information
1 parent
405f6b3
commit e51417e
Showing
15 changed files
with
543 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,33 @@ | ||
language: rust | ||
rust: | ||
- 1.34.0 | ||
- stable | ||
- beta | ||
- nightly | ||
sudo: false | ||
cache: cargo | ||
branches: | ||
only: | ||
- master | ||
- support/1.x | ||
- support/2.x | ||
before_script: | ||
- cargo install --force cargo-audit | ||
- cargo install --force cargo-when | ||
- cargo when -v ^1.39 install --force cargo-audit | ||
script: | ||
- cargo test | ||
- cargo test --example google | ||
- cargo test --example github | ||
- cargo test --example msgraph | ||
- cargo audit | ||
# Tests should run on all supported rustc versions | ||
- cargo test --tests --examples | ||
# Docs rely on async/await and only work on rustc >= 1.39.0 | ||
- cargo when -v ^1.39 -- test --doc | ||
# Enabling all features (including async/await) requires rustc >= 1.39.0 | ||
- cargo when -v ^1.39 -- test --all-features | ||
- cargo when -v ^1.39 -- test --tests --examples --no-default-features --features futures-03 | ||
# Blocking reqwest using reqwest 0.9 | ||
- cargo test --tests --examples --features reqwest --no-default-features | ||
# Futures 0.1 without reqwest (examples will not build) | ||
- cargo test --tests --features futures-01 --no-default-features | ||
# Futures 0.3 without reqwest 0.9 (but includes reqwest 0.10) | ||
- cargo when -v ^1.39 -- test --tests --examples --features futures-03 --no-default-features | ||
# Futures 0.1 with reqwest 0.9 | ||
- cargo test --tests --examples --features reqwest,futures-01 --no-default-features | ||
# Futures 0.3 with reqwest 0.9 (included by default) | ||
- cargo when -v ^1.39 -- test --tests --examples --features futures-03 | ||
- cargo when -v ^1.39 audit | ||
notifications: | ||
email: | ||
on_success: never |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
use crate::{ | ||
token_response, ClientCredentialsTokenRequest, CodeTokenRequest, ErrorResponse, HttpRequest, | ||
HttpResponse, PasswordTokenRequest, RefreshTokenRequest, RequestTokenError, TokenResponse, | ||
TokenType, | ||
}; | ||
use async_trait::async_trait; | ||
use failure::Fail; | ||
use futures_0_3::Future; | ||
|
||
/// | ||
/// Asynchronous request to exchange an authorization code for an access token. | ||
/// | ||
#[async_trait] | ||
pub trait AsyncCodeTokenRequest<TE, TR, TT> | ||
where | ||
TE: ErrorResponse + 'static, | ||
TR: TokenResponse<TT> + Send, | ||
TT: TokenType + Send, | ||
{ | ||
/// | ||
/// Asynchronously sends the request to the authorization server. | ||
/// | ||
async fn request_async<C, F, RE>(self, http_client: C) -> Result<TR, RequestTokenError<RE, TE>> | ||
where | ||
C: FnOnce(HttpRequest) -> F + Send, | ||
F: Future<Output = Result<HttpResponse, RE>> + Send, | ||
RE: Fail; | ||
} | ||
|
||
#[async_trait] | ||
impl<TE, TR, TT> AsyncCodeTokenRequest<TE, TR, TT> for CodeTokenRequest<'_, TE, TR, TT> | ||
where | ||
TE: ErrorResponse + 'static, | ||
TR: TokenResponse<TT> + Send, | ||
TT: TokenType + Send, | ||
{ | ||
/// | ||
/// Asynchronously sends the request to the authorization server and returns a Future. | ||
/// | ||
async fn request_async<C, F, RE>(self, http_client: C) -> Result<TR, RequestTokenError<RE, TE>> | ||
where | ||
C: FnOnce(HttpRequest) -> F + Send, | ||
F: Future<Output = Result<HttpResponse, RE>> + Send, | ||
RE: Fail, | ||
{ | ||
let http_request = self.prepare_request()?; | ||
let http_response = http_client(http_request) | ||
.await | ||
.map_err(RequestTokenError::Request)?; | ||
token_response(http_response) | ||
} | ||
} | ||
|
||
/// | ||
/// Asynchronous request to exchange a refresh token for an access token. | ||
/// | ||
#[async_trait] | ||
pub trait AsyncRefreshTokenRequest<TE, TR, TT> | ||
where | ||
TE: ErrorResponse + 'static, | ||
TR: TokenResponse<TT> + Send, | ||
TT: TokenType + Send, | ||
{ | ||
/// | ||
/// Asynchronously sends the request to the authorization server and awaits a response. | ||
/// | ||
async fn request_async<C, F, RE>(self, http_client: C) -> Result<TR, RequestTokenError<RE, TE>> | ||
where | ||
C: FnOnce(HttpRequest) -> F + Send, | ||
F: Future<Output = Result<HttpResponse, RE>> + Send, | ||
RE: Fail; | ||
} | ||
|
||
#[async_trait] | ||
impl<TE, TR, TT> AsyncRefreshTokenRequest<TE, TR, TT> for RefreshTokenRequest<'_, TE, TR, TT> | ||
where | ||
TE: ErrorResponse + 'static, | ||
TR: TokenResponse<TT> + Send, | ||
TT: TokenType + Send, | ||
{ | ||
/// | ||
/// Asynchronously sends the request to the authorization server and awaits a response. | ||
/// | ||
async fn request_async<C, F, RE>(self, http_client: C) -> Result<TR, RequestTokenError<RE, TE>> | ||
where | ||
C: FnOnce(HttpRequest) -> F + Send, | ||
F: Future<Output = Result<HttpResponse, RE>> + Send, | ||
RE: Fail, | ||
{ | ||
let http_request = self.prepare_request()?; | ||
let http_response = http_client(http_request) | ||
.await | ||
.map_err(RequestTokenError::Request)?; | ||
token_response(http_response) | ||
} | ||
} | ||
|
||
/// | ||
/// Asynchronous request to exchange resource owner credentials for an access token. | ||
/// | ||
#[async_trait] | ||
pub trait AsyncPasswordTokenRequest<TE, TR, TT> | ||
where | ||
TE: ErrorResponse + 'static, | ||
TR: TokenResponse<TT> + Send, | ||
TT: TokenType + Send, | ||
{ | ||
/// | ||
/// Asynchronously sends the request to the authorization server and awaits a response. | ||
/// | ||
async fn request_async<C, F, RE>(self, http_client: C) -> Result<TR, RequestTokenError<RE, TE>> | ||
where | ||
C: FnOnce(HttpRequest) -> F + Send, | ||
F: Future<Output = Result<HttpResponse, RE>> + Send, | ||
RE: Fail; | ||
} | ||
|
||
#[async_trait] | ||
impl<TE, TR, TT> AsyncPasswordTokenRequest<TE, TR, TT> for PasswordTokenRequest<'_, TE, TR, TT> | ||
where | ||
TE: ErrorResponse + 'static, | ||
TR: TokenResponse<TT> + Send, | ||
TT: TokenType + Send, | ||
{ | ||
/// | ||
/// Asynchronously sends the request to the authorization server and awaits a response. | ||
/// | ||
async fn request_async<C, F, RE>(self, http_client: C) -> Result<TR, RequestTokenError<RE, TE>> | ||
where | ||
C: FnOnce(HttpRequest) -> F + Send, | ||
F: Future<Output = Result<HttpResponse, RE>> + Send, | ||
RE: Fail, | ||
{ | ||
let http_request = self.prepare_request()?; | ||
let http_response = http_client(http_request) | ||
.await | ||
.map_err(RequestTokenError::Request)?; | ||
token_response(http_response) | ||
} | ||
} | ||
|
||
/// | ||
/// Asynchronous request to exchange client credentials for an access token. | ||
/// | ||
#[async_trait] | ||
pub trait AsyncClientCredentialsTokenRequest<TE, TR, TT> | ||
where | ||
TE: ErrorResponse + 'static, | ||
TR: TokenResponse<TT> + Send, | ||
TT: TokenType + Send, | ||
{ | ||
/// | ||
/// Asynchronously sends the request to the authorization server and awaits a response. | ||
/// | ||
async fn request_async<C, F, RE>(self, http_client: C) -> Result<TR, RequestTokenError<RE, TE>> | ||
where | ||
C: FnOnce(HttpRequest) -> F + Send, | ||
F: Future<Output = Result<HttpResponse, RE>> + Send, | ||
RE: Fail; | ||
} | ||
|
||
#[async_trait] | ||
impl<TE, TR, TT> AsyncClientCredentialsTokenRequest<TE, TR, TT> | ||
for ClientCredentialsTokenRequest<'_, TE, TR, TT> | ||
where | ||
TE: ErrorResponse + 'static, | ||
TR: TokenResponse<TT> + Send, | ||
TT: TokenType + Send, | ||
{ | ||
/// | ||
/// Asynchronously sends the request to the authorization server and awaits a response. | ||
/// | ||
async fn request_async<C, F, RE>(self, http_client: C) -> Result<TR, RequestTokenError<RE, TE>> | ||
where | ||
C: FnOnce(HttpRequest) -> F + Send, | ||
F: Future<Output = Result<HttpResponse, RE>> + Send, | ||
RE: Fail, | ||
{ | ||
let http_request = self.prepare_request()?; | ||
let http_response = http_client(http_request) | ||
.await | ||
.map_err(RequestTokenError::Request)?; | ||
token_response(http_response) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.