{"id":21334818,"url":"https://github.com/j03-dev/rocket_security","last_synced_at":"2025-09-06T00:41:45.003Z","repository":{"id":254343981,"uuid":"815692862","full_name":"j03-dev/rocket_security","owner":"j03-dev","description":null,"archived":false,"fork":false,"pushed_at":"2025-01-17T22:51:17.000Z","size":21,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-24T11:59:12.861Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/j03-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-06-15T21:20:10.000Z","updated_at":"2025-01-17T22:51:18.000Z","dependencies_parsed_at":"2025-03-16T06:15:21.815Z","dependency_job_id":null,"html_url":"https://github.com/j03-dev/rocket_security","commit_stats":null,"previous_names":["j03-dev/rocket_security"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/j03-dev/rocket_security","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j03-dev%2Frocket_security","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j03-dev%2Frocket_security/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j03-dev%2Frocket_security/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j03-dev%2Frocket_security/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/j03-dev","download_url":"https://codeload.github.com/j03-dev/rocket_security/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j03-dev%2Frocket_security/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273842860,"owners_count":25177920,"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-09-05T02:00:09.113Z","response_time":402,"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":[],"created_at":"2024-11-21T23:34:32.325Z","updated_at":"2025-09-06T00:41:44.974Z","avatar_url":"https://github.com/j03-dev.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rocket Security\nJwt implementation for rocket\n\n### Example\n```rust\nuse crate::AppState;\n\nuse super::custome_response::*;\n\nuse models::User as UserModel;\nuse rocket_security::{create_new_token, hash, Auth, RegisteredClaims};\n\nuse rocket::State;\nuse rusql_alchemy::prelude::*;\nuse serde::Deserialize;\n\nconst ONE_WEEK: u64 = ((3600 * 24) * 7) as u64;\n\n#[derive(Deserialize, Clone)]\npub struct NewUser {\n    pub username: String,\n    pub email: String,\n    pub password: String,\n    pub verification: String,\n}\n\n#[post(\"/\", format = \"json\", data = \"\u003cnew_user\u003e\")]\npub async fn register(new_user: Json\u003cNewUser\u003e, app_state: \u0026State\u003cAppState\u003e) -\u003e Response {\n    let conn = app_state.conn.clone();\n    if new_user.password == new_user.verification\n        \u0026\u0026 UserModel::create(\n            kwargs!(\n                username = new_user.username,\n                email = new_user.email,\n                password = hash(\u0026new_user.password)\n            ),\n            \u0026conn,\n        )\n        .await\n    {\n        Ok(Custom(\n            Status::Created,\n            json!({ \"message\": \"User created successfully\" }),\n        ))\n    } else {\n        Err(Custom(\n            Status::BadRequest,\n            json!({ \"message\": \"User is alredy exist or password is not match\" }),\n        ))\n    }\n}\n\n#[derive(Deserialize)]\npub struct Credential {\n    pub email: String,\n    pub password: String,\n}\n\n#[post(\"/auth\", format = \"json\", data = \"\u003ccred\u003e\")]\npub async fn authentication(cred: Json\u003cCredential\u003e, app_state: \u0026State\u003cAppState\u003e) -\u003e Response {\n    let conn = app_state.conn.clone();\n    if let Some(user) = UserModel::get(\n        kwargs!(email = cred.email, password = hash(\u0026cred.password)),\n        \u0026conn,\n    )\n    .await\n    {\n        let claims = RegisteredClaims {\n            subject: Some(user.id.to_string()),\n            expiration: Some(ONE_WEEK),\n            ..Default::default()\n        };\n        let token = create_new_token(claims).unwrap();\n        Ok(Custom(Status::Ok, json!({\"user\": user, \"token\": token})))\n    } else {\n        Err(Custom(\n            Status::Unauthorized,\n            json!({ \"message\": \"email or password is invalid\" }),\n        ))\n    }\n}\n\n#[get(\"/\")]\npub async fn retrieve(auth: Auth, app_state: \u0026State\u003cAppState\u003e) -\u003e Response {\n    let conn = app_state.conn.clone();\n    let id: i32 = auth.subject.parse().unwrap();\n    if let Some(user) = UserModel::get(kwargs!(id = id), \u0026conn).await {\n        Ok(Custom(Status::Ok, json!(user)))\n    } else {\n        Err(Custom(\n            Status::NotFound,\n            json!({ \"message\": \"User not found\" }),\n        ))\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj03-dev%2Frocket_security","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fj03-dev%2Frocket_security","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj03-dev%2Frocket_security/lists"}