token-in-address
This commit is contained in:
parent
bfeb474748
commit
0443ebd486
10
src/main.rs
10
src/main.rs
|
@ -28,10 +28,18 @@ async fn connect_handler(
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
state: web::Data<AppState>,
|
state: web::Data<AppState>,
|
||||||
) -> Result<HttpResponse, actix_web::Error> {
|
) -> Result<HttpResponse, actix_web::Error> {
|
||||||
|
/*
|
||||||
let token = match req.headers().get("Authorization") {
|
let token = match req.headers().get("Authorization") {
|
||||||
Some(val) => val.to_str().unwrap_or("").split(" ").last().unwrap_or(""),
|
Some(val) => val.to_str().unwrap_or("").split(" ").last().unwrap_or(""),
|
||||||
None => return Err(ErrorUnauthorized("Unauthorized")),
|
None => return Err(ErrorUnauthorized("Unauthorized")),
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
let token = match req.match_info().get("token") {
|
||||||
|
Some(val) => val,
|
||||||
|
None => return Err(ErrorUnauthorized("Unauthorized")),
|
||||||
|
};
|
||||||
|
|
||||||
let listener_id = data::get_auth_id(&token).await.map_err(|e| {
|
let listener_id = data::get_auth_id(&token).await.map_err(|e| {
|
||||||
eprintln!("TOKEN check failed: {}", e);
|
eprintln!("TOKEN check failed: {}", e);
|
||||||
ErrorUnauthorized("Unauthorized")
|
ErrorUnauthorized("Unauthorized")
|
||||||
|
@ -143,7 +151,7 @@ async fn main() -> std::io::Result<()> {
|
||||||
App::new()
|
App::new()
|
||||||
.wrap(Logger::default())
|
.wrap(Logger::default())
|
||||||
.app_data(web::Data::new(state.clone()))
|
.app_data(web::Data::new(state.clone()))
|
||||||
.route("/", web::get().to(connect_handler))
|
.route("/{token}", web::get().to(connect_handler))
|
||||||
})
|
})
|
||||||
.bind("0.0.0.0:8080")?
|
.bind("0.0.0.0:8080")?
|
||||||
.run()
|
.run()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user