-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix httpauth extraction error handling in middleware (#128)
- Loading branch information
Showing
7 changed files
with
85 additions
and
37 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 |
---|---|---|
|
@@ -10,4 +10,5 @@ members = [ | |
] | ||
|
||
[patch.crates-io] | ||
actix-cors = { path = "actix-cors" } | ||
actix-session = { path = "actix-session" } |
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,33 @@ | ||
use actix_cors::Cors; | ||
use actix_web::{dev::ServiceRequest, get, App, Error, HttpResponse, HttpServer}; | ||
use actix_web_httpauth::{ | ||
extractors::bearer::BearerAuth, middleware::HttpAuthentication, | ||
}; | ||
|
||
async fn ok_validator( | ||
req: ServiceRequest, | ||
credentials: BearerAuth, | ||
) -> Result<ServiceRequest, Error> { | ||
eprintln!("{:?}", credentials); | ||
Ok(req) | ||
} | ||
|
||
#[get("/")] | ||
async fn index() -> HttpResponse { | ||
HttpResponse::Ok().finish() | ||
} | ||
|
||
#[actix_web::main] | ||
async fn main() -> std::io::Result<()> { | ||
HttpServer::new(move || { | ||
App::new() | ||
.wrap(HttpAuthentication::bearer(ok_validator)) | ||
// ensure the CORS middleware is wrapped around the httpauth middleware so it is able to | ||
// add headers to error responses | ||
.wrap(Cors::permissive()) | ||
.service(index) | ||
}) | ||
.bind(("127.0.0.1", 8080))? | ||
.run() | ||
.await | ||
} |
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