Skip to content

Commit

Permalink
Authorization middleware supports cookie or authorization header (#594)
Browse files Browse the repository at this point in the history
* Authorization middleware supports cookie or authorization header

* fix typo for 'message' in error response
  • Loading branch information
niamu authored Dec 29, 2023
1 parent 19e68e0 commit 3ccb4ab
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 48 deletions.
155 changes: 135 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dim-web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ nightfall = { git = "https://github.com/Dusk-Labs/nightfall", tag = "0.3.12-rc4"
] }

axum = { version = "0.6.20", features = ["ws", "http2", "macros", "multipart"] }
axum-extra = { version = "0.9.0", features = ["cookie"] }
cfg-if = "1.0.0"
chrono = { version = "0.4.19", features = ["serde"] }
displaydoc = "0.2.3"
Expand Down
2 changes: 1 addition & 1 deletion dim-web/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl IntoResponse for DimErrorWrapper {

let resp = serde_json::json!({
"error": serde_json::json!(&self.0)["error"],
"messsage": self.0.to_string(),
"message": self.0.to_string(),
});
(status, serde_json::to_string(&resp).unwrap()).into_response()
}
Expand Down
4 changes: 2 additions & 2 deletions dim-web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub mod error;
pub use error::DimErrorWrapper;

pub mod middleware;
pub use middleware::verify_cookie_token;
pub use middleware::verify_token;

#[derive(Debug, Clone)]
pub struct AppState {
Expand Down Expand Up @@ -385,7 +385,7 @@ pub async fn start_webserver(
.merge(stream_routes())
.route_layer(axum::middleware::from_fn_with_state(
app.clone(),
verify_cookie_token,
verify_token,
))
// --- End of routes authenticated by Axum middleware ---
.merge(public_auth_routes())
Expand Down
Loading

0 comments on commit 3ccb4ab

Please sign in to comment.