Skip to content

Commit

Permalink
fixup/dist: Construct auth hyper server in Tokio 0.2 context
Browse files Browse the repository at this point in the history
This fixes a run-time error otherwise encountered in tests/oauth.rs
  • Loading branch information
Xanewok committed Nov 9, 2021
1 parent 87e0b64 commit ccab162
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/dist/client_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,10 @@ pub fn get_token_oauth2_code_grant_pkce(
mut auth_url: Url,
token_url: &str,
) -> Result<String> {
let server = try_bind()?.serve(make_service!(code_grant_pkce::serve));
let mut runtime = Runtime::new()?;
let server = runtime
.enter(try_bind)?
.serve(make_service!(code_grant_pkce::serve));
let port = server.local_addr().port();

let redirect_uri = format!("http://localhost:{}/redirect", port);
Expand Down Expand Up @@ -532,7 +535,6 @@ pub fn get_token_oauth2_code_grant_pkce(
};
*code_grant_pkce::STATE.lock().unwrap() = Some(state);

let mut runtime = Runtime::new()?;
runtime.block_on(server.with_graceful_shutdown(async move {
if let Err(e) = shutdown_rx.await {
warn!(
Expand All @@ -552,7 +554,10 @@ pub fn get_token_oauth2_code_grant_pkce(

// https://auth0.com/docs/api-auth/tutorials/implicit-grant
pub fn get_token_oauth2_implicit(client_id: &str, mut auth_url: Url) -> Result<String> {
let server = try_bind()?.serve(make_service!(implicit::serve));
let mut runtime = Runtime::new()?;
let server = runtime
.enter(try_bind)?
.serve(make_service!(implicit::serve));

let port = server.local_addr().port();

Expand All @@ -575,7 +580,6 @@ pub fn get_token_oauth2_implicit(client_id: &str, mut auth_url: Url) -> Result<S
};
*implicit::STATE.lock().unwrap() = Some(state);

let mut runtime = Runtime::new()?;
runtime.block_on(server.with_graceful_shutdown(async move {
if let Err(e) = shutdown_rx.await {
warn!(
Expand Down

0 comments on commit ccab162

Please sign in to comment.