Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'Cannot drop a runtime' error #146

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Contributors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ ParisLiakos (Paris Liakos, gotham frontend)
asonix <asonix@asonix.dog> (actix 1.0 update)
Geobert Quach (on behalf of Isode Ltd.)
robjtede <robjtede@icloud.com> (actix-web 3.0 update)
Oleg Chirukhin <oleg@jetstorm.ru>
1 change: 1 addition & 0 deletions oxide-auth-actix/examples/actix-example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ serde = "1.0"
serde_json = "1.0"
url = "2"
serde_urlencoded = "0.7"
tokio = "1.16.1"
30 changes: 25 additions & 5 deletions oxide-auth-actix/examples/actix-example/src/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Client>) -> 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<Client>) -> 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)),
};
Expand All @@ -81,7 +101,7 @@ async fn get_with_token(state: web::Data<Client>) -> impl Responder {
Its contents are:
<article>{}</article>
<form action=\"refresh\" method=\"post\"><button>Refresh token</button></form>
</main></html>", state.as_html(), protected_page);
</main></html>", html, protected_page);

HttpResponse::Ok().content_type("text/html").body(display_page)
}