{"id":22964808,"url":"https://github.com/michaelvanstraten/actix-jwt-auth-middleware","last_synced_at":"2025-10-08T10:45:45.754Z","repository":{"id":62444584,"uuid":"498872943","full_name":"michaelvanstraten/actix-jwt-auth-middleware","owner":"michaelvanstraten","description":"JSON Webtoken (JWT) middleware for the actix-web framework","archived":false,"fork":false,"pushed_at":"2025-08-12T11:01:07.000Z","size":14688,"stargazers_count":42,"open_issues_count":5,"forks_count":17,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-23T17:57:13.479Z","etag":null,"topics":["actix-web-middleware","jwt","rust"],"latest_commit_sha":null,"homepage":"https://docs.rs/actix-jwt-auth-middleware/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/michaelvanstraten.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-06-01T19:31:31.000Z","updated_at":"2025-06-11T19:54:43.000Z","dependencies_parsed_at":"2024-11-05T23:22:17.426Z","dependency_job_id":"b3ba41b2-e62d-413a-ba7b-51b31e662427","html_url":"https://github.com/michaelvanstraten/actix-jwt-auth-middleware","commit_stats":{"total_commits":62,"total_committers":6,"mean_commits":"10.333333333333334","dds":"0.30645161290322576","last_synced_commit":"6082ea8f423c87333bb5dc3a08d28127c61ff501"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/michaelvanstraten/actix-jwt-auth-middleware","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelvanstraten%2Factix-jwt-auth-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelvanstraten%2Factix-jwt-auth-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelvanstraten%2Factix-jwt-auth-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelvanstraten%2Factix-jwt-auth-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michaelvanstraten","download_url":"https://codeload.github.com/michaelvanstraten/actix-jwt-auth-middleware/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelvanstraten%2Factix-jwt-auth-middleware/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278931651,"owners_count":26070788,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["actix-web-middleware","jwt","rust"],"created_at":"2024-12-14T20:12:29.093Z","updated_at":"2025-10-08T10:45:45.733Z","avatar_url":"https://github.com/michaelvanstraten.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# actix-jwt-auth-middleware\n\nThis crate builds upon the [`jwt-compact`](https://github.com/slowli/jwt-compact) crate\nto provide a jwt authentication middleware for the [`actix-web`](https://github.com/actix/actix-web) framework.\n\nThe jwt implementation supports the revocation for tokens via `access` and `refresh` tokens.\n\nIt provides multiple cryptographic signing and verifying algorithms such as `HS256`, `HS384`, `HS512`, `EdDSA` and `ES256`.\nFor more infos on that mater please refer to the [`Supported algorithms`](https://docs.rs/jwt-compact/latest/jwt_compact/#supported-algorithms) section of the [`jwt-compact`](https://github.com/slowli/jwt-compact) crate.\n\n## Features\n- easy use of custom jwt claims\n- automatic extraction of the custom claims\n- extraction of tokens from `query` parameters, `HTTP` headers, [`Authorization`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization) header and `cookies`\n- verify only mode (`public key` only)\n- automatic renewal of `access` token (very customizable)\n- easy way to set expiration time of `access` and `refresh` tokens\n- simple `UseJWT` trait for protecting a `App` or `Scope` (`Resource` is currently experimental [#91611](https://github.com/rust-lang/rust/issues/91611))\n- refresh authorizer function that has access to application state\n\n## Automatic Extraction of Claims\nThis crate tightly integrates into the actix-web ecosystem,\nthis makes it easy to Automatic extract the jwt claims from a valid token.\n```rust\n#[derive(Serialize, Deserialize, Clone, FromRequest)]\nstruct UserClaims {\n    id: u32,\n    role: Role,\n}\n#[derive(Serialize, Deserialize, Clone, Debug)]\nenum Role {\n    Admin,\n    RegularUser,\n}\n#[get(\"/hello\")]\nasync fn hello(user_claims: UserClaims) -\u003e impl Responder {\n    format!(\n        \"Hello user with id: {}, i see you are a {:?}!\",\n            user_claims.id, user_claims.role\n    )\n}\n```\nFor this your custom claim type has to implement the [`FromRequest`](actix_web::FromRequest) trait\nor it has to be annotated with the `#[derive(actix-jwt-auth-middleware::FromRequest)]` macro which implements this trait for your type.\n\n## Simple Example\n```rust\n#[derive(Serialize, Deserialize, Clone, Debug, FromRequest)]\nstruct User {\n    id: u32,\n}\n\n#[actix_web::main]\nasync fn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    let key_pair = KeyPair::random();\n\n    HttpServer::new(move || {\n        let authority = Authority::\u003cUser, Ed25519, _, _\u003e::new()\n            .refresh_authorizer(|| async move { Ok(()) })\n            .token_signer(Some(\n                TokenSigner::new()\n                    .signing_key(key_pair.secret_key().clone())\n                    .algorithm(Ed25519)\n                    .build()\n                    .expect(\"\"),\n            ))\n            .verifying_key(key_pair.public_key())\n            .build()\n            .expect(\"\");\n\n        App::new()\n            .service(login)\n            .use_jwt(authority, web::scope(\"\").service(hello))\n    })\n    .bind((\"127.0.0.1\", 8080))?\n    .run()\n    .await?;\n\n    Ok(())\n}\n\n#[get(\"/login\")]\nasync fn login(token_signer: web::Data\u003cTokenSigner\u003cUser, Ed25519\u003e\u003e) -\u003e AuthResult\u003cHttpResponse\u003e {\n    let user = User { id: 1 };\n    Ok(HttpResponse::Ok()\n        .cookie(token_signer.create_access_cookie(\u0026user)?)\n        .cookie(token_signer.create_refresh_cookie(\u0026user)?)\n        .body(\"You are now logged in\"))\n}\n\n#[get(\"/hello\")]\nasync fn hello(user: User) -\u003e impl Responder {\n    format!(\"Hello there, i see your user id is {}.\", user.id)\n}\n```\nFor more examples please referee to the `examples` directory.\n\nLicense: MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelvanstraten%2Factix-jwt-auth-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichaelvanstraten%2Factix-jwt-auth-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelvanstraten%2Factix-jwt-auth-middleware/lists"}