{"id":15018069,"url":"https://github.com/yaxian/rocket-jwt","last_synced_at":"2025-05-05T03:44:42.059Z","repository":{"id":57672959,"uuid":"480828892","full_name":"Yaxian/rocket-jwt","owner":"Yaxian","description":"jwt authorization for rocket","archived":false,"fork":false,"pushed_at":"2024-07-08T15:39:44.000Z","size":26,"stargazers_count":14,"open_issues_count":2,"forks_count":10,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-05T03:44:15.903Z","etag":null,"topics":["jwt","rocket"],"latest_commit_sha":null,"homepage":"","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/Yaxian.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-MIT","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}},"created_at":"2022-04-12T13:45:45.000Z","updated_at":"2024-07-08T15:41:46.000Z","dependencies_parsed_at":"2024-07-08T19:44:16.692Z","dependency_job_id":null,"html_url":"https://github.com/Yaxian/rocket-jwt","commit_stats":{"total_commits":20,"total_committers":4,"mean_commits":5.0,"dds":"0.30000000000000004","last_synced_commit":"95d15f5a57273b6c93e406592fcd8f2e9f93bb75"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yaxian%2Frocket-jwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yaxian%2Frocket-jwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yaxian%2Frocket-jwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yaxian%2Frocket-jwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Yaxian","download_url":"https://codeload.github.com/Yaxian/rocket-jwt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252436240,"owners_count":21747467,"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","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":["jwt","rocket"],"created_at":"2024-09-24T19:51:23.904Z","updated_at":"2025-05-05T03:44:42.035Z","avatar_url":"https://github.com/Yaxian.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rocket-jwt\n\njwt authorization for rocket@0.5.\n\nrocket@0.4 see [v0.4](https://github.com/Yaxian/rocket-jwt/tree/v0.4).\n\n\n```rust\n#[macro_use]\nextern crate rocket;\n\nuse rocket_jwt::jwt;\n\nstatic SECRET_KEY: \u0026str = \"secret_key\";\n#[jwt(SECRET_KEY)]\npub struct UserClaim {\n    id: String,\n}\n\n#[jwt(\"secret\", exp = 100)]\npub struct UserClaimExp {\n    id: String\n}\n\n#[jwt(\"secret\", leeway = 10)]\npub struct UserClaimLeeway {\n    id: String\n}\n\n// get token from cookie, key is `token`\n#[jwt(\"secret\", cookie = \"token\")]\npub struct UserClaimCookie {\n    id: String\n}\n\n// get token from request query, key is `token`\n#[jwt(\"secret\", query = \"token\")]\npub struct UserClaimQuery {\n    id: String\n}\n\n#[get(\"/\")]\nfn index() -\u003e String {\n    let user_claim = UserClaim {\n        id: format!(\"hello_rocket_jwt\"),\n    };\n    let token = UserClaim::sign(user_claim);\n    println!(\"{:#?}\", UserClaim::decode(token.clone()));\n    token\n}\n\n#[get(\"/user_id\")]\nfn get_uer_id_from_jwt(user: UserClaim) -\u003e String {\n    format!(\"user id is {}\", user.id)\n}\n\n#[launch]\nfn rocket() -\u003e _ {\n    rocket::build().mount(\"/\", routes![index, get_uer_id_from_jwt])\n}\n\n```\n\n\n### API\n\n| attribute | type | description | default |\n|----------|------|-------------|---|\n|  | String | jwt secret key, required | |\n| exp | Int | token expire after seconds | 2592000 *(one month)* |\n| leeway | Int | token expire leeway in seconds | 60 *(one minute)* |\n| cookie | String | get token from cookie key, optional | |\n| query | String | get token from query key, optional | |\n\n\n### Run example\n\n```\ncargo run --example rocket-jwt-demo\n```\n\n1. get `jwt` token\n\n```\ncurl http://localhost:8000\n```\n\n2. use `jwt` token\n\n```\ncurl -H \"Authorization: Bearer YOUR_JWT_TOKEN\" http://localhost:8000/user_id\n```\n\n## License\n\n[MIT](LICENSE-MIT)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyaxian%2Frocket-jwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyaxian%2Frocket-jwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyaxian%2Frocket-jwt/lists"}