diff --git a/Contributors.txt b/Contributors.txt index e8f814d7..5dd6230b 100644 --- a/Contributors.txt +++ b/Contributors.txt @@ -6,3 +6,4 @@ ParisLiakos (Paris Liakos, gotham frontend) asonix (actix 1.0 update) Geobert Quach (on behalf of Isode Ltd.) robjtede (actix-web 3.0 update) +Oleg Chirukhin diff --git a/oxide-auth-actix/examples/actix-example/Cargo.toml b/oxide-auth-actix/examples/actix-example/Cargo.toml index 2fca9f3d..5f542171 100644 --- a/oxide-auth-actix/examples/actix-example/Cargo.toml +++ b/oxide-auth-actix/examples/actix-example/Cargo.toml @@ -16,3 +16,4 @@ serde = "1.0" serde_json = "1.0" url = "2" serde_urlencoded = "0.7" +tokio = "1.16.1" diff --git a/oxide-auth-actix/examples/actix-example/src/support.rs b/oxide-auth-actix/examples/actix-example/src/support.rs index 3337b925..1ffb36a1 100644 --- a/oxide-auth-actix/examples/actix-example/src/support.rs +++ b/oxide-auth-actix/examples/actix-example/src/support.rs @@ -50,21 +50,41 @@ async fn endpoint_impl( Some(code) => code.clone(), }; - match state.authorize(&code) { - Ok(()) => HttpResponse::Found().append_header(("Location", "/")).finish(), + let auth_handle = tokio::task::spawn_blocking(move || { + let res = state.authorize(&code); + res + }); + let auth_result = auth_handle.await.unwrap(); + + match auth_result { + Ok(()) => {HttpResponse::Found().append_header(("Location", "/")).finish()}, Err(err) => HttpResponse::InternalServerError().body(format!("{}", err)), } } async fn refresh(state: web::Data) -> impl Responder { - match state.refresh() { + let refresh_handle = tokio::task::spawn_blocking(move || { + let res = state.refresh(); + res + }); + let refresh_result = refresh_handle.await.unwrap(); + + match refresh_result { Ok(()) => HttpResponse::Found().append_header(("Location", "/")).finish(), Err(err) => HttpResponse::InternalServerError().body(format!("{}", err)), } } async fn get_with_token(state: web::Data) -> impl Responder { - let protected_page = match state.retrieve_protected_page() { + let html = state.as_html(); + + let protected_page_handle = tokio::task::spawn_blocking(move || { + let res = state.retrieve_protected_page(); + res + }); + let protected_page_result = protected_page_handle.await.unwrap(); + + let protected_page = match protected_page_result { Ok(page) => page, Err(err) => return HttpResponse::InternalServerError().body(format!("{}", err)), }; @@ -81,7 +101,7 @@ async fn get_with_token(state: web::Data) -> impl Responder { Its contents are:
{}
- ", state.as_html(), protected_page); + ", html, protected_page); HttpResponse::Ok().content_type("text/html").body(display_page) }