#jwt #middleware #validation #actix-web #bearer #token #actix-middleware

actix-jwt-validator-middleware

Middleware and extractor for JWT bearer tokens for the actix-web framework

3 releases (breaking)

0.3.0 Sep 15, 2021
0.2.0 Sep 15, 2021
0.1.0 Apr 10, 2021

#1397 in HTTP server

Download history 43/week @ 2024-04-01 12/week @ 2024-04-08 2/week @ 2024-04-15 21/week @ 2024-04-22 18/week @ 2024-04-29 1/week @ 2024-05-20 23/week @ 2024-06-10 15/week @ 2024-06-17 25/week @ 2024-06-24

63 downloads per month

MIT license

8KB
143 lines

Actix JWT Validator Middleware

Simple actix middleware that takes a JWT bearer token from the authorization HTTP header and validates it against some JWKS.

Example

use actix_web::{HttpServer, App};

use actix_jwt_validator_middleware::{jwt_validator, init_key_set};

async fn index() -> &'static str {
  "Welcome!"
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
  let key_set = init_key_set("url-to-your-certification-endpoint")
    .await
    .unwrap();

  HttpServer::new(move || {
    App::new()
      .data(key_set.clone())
      .wrap(jwt_validator())
      .route("/index.html", web::get().to(index))
  })
  .bind("0.0.0.0:8080")?
  .run()
  .await
}

TODO

  • Own KeyStore wrapped around the jwk_client one with Arc to make referencing thread-safe

Dependencies

~32–43MB
~856K SLoC