Adding header to actix web request via Swagger

121 Views Asked by At

I'm currently using utoipa for my Swagger UI and actix_web_httpauth to authorize my requests. I added ("authorization" = String, Header, description = "JWT") to my Swagger params but if I check the header of ServiceRequest there is no authorization: Bearer <token>. What do I miss?

#[utoipa::path(
    context_path = "/tools",
    tag = "tools",
    params(
        ("url", 
            description = "URL that should be scanned for fingerprints.", 
            example = "https://example.com"
        ),
        ("authorization" = String, Header, description = "JWT")
    ),
    responses(
        (status = 200, description = "JSON output of the blacklight collector.", body = String),
        (status = 400, description = "Wrong URL.", body = String)
    )
)]
#[get("/blacklight/{url}")]
pub async fn blacklight(
    path: web::Path<String>, 
    claims: Option<web::ReqData<Claims>>
) -> impl Responder {
    let url: String = path.into_inner();

    match url_check::is_url(url.as_str()) {
        true => {
            if let Some(claims) = claims {
                publish_service::publisher(claims.sub.clone(), &url);
            }

            HttpResponse::Ok().json("Ok")
        },
        false => HttpResponse::BadRequest().body("ProtocolError: Cannot navigate to invalid URL")
    }
}
0

There are 0 best solutions below