{"id":29541227,"url":"https://github.com/densumesh/actix-passport","last_synced_at":"2026-01-26T19:07:58.134Z","repository":{"id":302383672,"uuid":"1012251951","full_name":"densumesh/actix-passport","owner":"densumesh","description":"A comprehensive, flexible authentication framework for actix-web applications in Rust.","archived":false,"fork":false,"pushed_at":"2025-07-08T10:37:16.000Z","size":554,"stargazers_count":17,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-16T00:06:53.810Z","etag":null,"topics":["actix-web","actix-web-middleware","authentication","rust"],"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/densumesh.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,"zenodo":null}},"created_at":"2025-07-02T04:01:54.000Z","updated_at":"2025-09-22T11:33:10.000Z","dependencies_parsed_at":"2025-07-02T05:41:36.434Z","dependency_job_id":null,"html_url":"https://github.com/densumesh/actix-passport","commit_stats":null,"previous_names":["densumesh/actix-passport"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/densumesh/actix-passport","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/densumesh%2Factix-passport","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/densumesh%2Factix-passport/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/densumesh%2Factix-passport/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/densumesh%2Factix-passport/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/densumesh","download_url":"https://codeload.github.com/densumesh/actix-passport/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/densumesh%2Factix-passport/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279397684,"owners_count":26162715,"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-17T02:00:07.504Z","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","actix-web-middleware","authentication","rust"],"created_at":"2025-07-17T09:06:34.169Z","updated_at":"2025-10-19T23:32:56.252Z","avatar_url":"https://github.com/densumesh.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Actix Passport\n\n[![Crates.io](https://img.shields.io/crates/v/actix-passport.svg)](https://crates.io/crates/actix-passport)\n[![Documentation](https://docs.rs/actix-passport/badge.svg)](https://docs.rs/actix-passport)\n[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)\n\nA comprehensive, flexible authentication framework for [actix-web](https://actix.rs/) applications in Rust.\n\n## Features\n\n- **Multiple Authentication Methods**\n  - Username/password authentication with secure Argon2 hashing\n  - OAuth 2.0 support (Google, GitHub, and custom providers)\n  - Session-based authentication\n\n- **Flexible Architecture**\n  - Pluggable user stores (database-agnostic)\n  - Extensible OAuth provider system\n  - Builder pattern for easy configuration\n  - Type-safe authentication extractors\n\n- **Developer Friendly**\n  - Minimal boilerplate with sensible defaults\n  - Comprehensive documentation and examples\n  - Feature flags for optional functionality\n  - Built-in authentication routes\n\n- **Security First**\n  - CSRF protection for OAuth flows\n  - Secure session management\n  - Configurable CORS policies\n  - Password strength validation\n\n## Quick Start\n\nAdd to your `Cargo.toml`:\n\n```toml\n[dependencies]\nactix-passport = \"0.1\"\nactix-web = \"4.4\"\nactix-session = \"0.8\"\ntokio = { version = \"1.0\", features = [\"full\"] }\n```\n\n### Basic Setup\n\n```rust\nuse actix_passport::prelude::*;\nuse actix_session::{SessionMiddleware, storage::CookieSessionStore};\nuse actix_web::{get, web, App, HttpResponse, HttpServer, Responder, cookie::Key};\n\n#[get(\"/\")]\nasync fn home(user: OptionalAuthedUser) -\u003e impl Responder {\n    match user.0 {\n        Some(user) =\u003e HttpResponse::Ok().json(format!(\"Welcome, {}!\", user.id)),\n        None =\u003e HttpResponse::Ok().json(\"Welcome! Please log in.\"),\n    }\n}\n\n#[get(\"/dashboard\")]\nasync fn dashboard(user: AuthedUser) -\u003e impl Responder {\n    HttpResponse::Ok().json(format!(\"Dashboard for user: {}\", user.id))\n}\n\n#[actix_web::main]\nasync fn main() -\u003e std::io::Result\u003c()\u003e {\n    // Simple setup with in-memory store (for development)\n    let auth_framework = ActixPassportBuilder::with_in_memory_store()\n        .enable_password_auth()\n        .build();\n\n    HttpServer::new(move || {\n        App::new()\n            // Session middleware is required\n            .wrap(SessionMiddleware::builder(\n                CookieSessionStore::default(),\n                Key::generate()\n            ).build())\n            .service(home)\n            .service(dashboard)\n            .configure(|cfg| auth_framework.configure_routes(cfg, RouteConfig::default()))\n    })\n    .bind(\"127.0.0.1:8080\")?\n    .run()\n    .await\n}\n```\n\n### Production Setup with PostgreSQL\n\n```rust\nuse actix_passport::prelude::*;\nuse actix_session::{SessionMiddleware, storage::CookieSessionStore};\nuse actix_web::{web, App, HttpServer, cookie::Key};\n\n#[actix_web::main]\nasync fn main() -\u003e std::io::Result\u003c()\u003e {\n    let auth_framework = ActixPassportBuilder::with_postgres_store(\n            \"postgres://user:password@localhost/myapp\"\n        )\n        .await\n        .unwrap()\n        .enable_password_auth()\n        .with_google_oauth(\n            \"your_google_client_id\".to_string(),\n            \"your_google_client_secret\".to_string()\n        )\n        .build();\n\n    HttpServer::new(move || {\n        App::new()\n            .wrap(SessionMiddleware::builder(\n                CookieSessionStore::default(),\n                Key::generate()\n            ).build())\n            .configure(|cfg| auth_framework.configure_routes(cfg, RouteConfig::default()))\n    })\n    .bind(\"127.0.0.1:8080\")?\n    .run()\n    .await\n}\n```\n\n### Available Endpoints\n\nOnce configured, your app automatically gets these authentication endpoints:\n\n- `POST /auth/login` - Login with email/password\n- `POST /auth/register` - Register new user\n- `POST /auth/logout` - Logout current user\n- `GET /auth/me` - Get current user info\n- `GET /auth/{provider}` - OAuth login (e.g., `/auth/google`)\n- `GET /auth/{provider}/callback` - OAuth callback\n\n### Custom User Store\n\nImplement the `UserStore` trait for your database:\n\n```rust\nuse actix_passport::{user_store::UserStore, types::{AuthUser, AuthResult}};\nuse async_trait::async_trait;\n\npub struct DatabaseUserStore {\n    // Your database connection\n}\n\n#[async_trait]\nimpl UserStore for DatabaseUserStore {\n    async fn find_by_id(\u0026self, id: \u0026str) -\u003e AuthResult\u003cOption\u003cAuthUser\u003e\u003e {\n        // Your database query logic\n        todo!()\n    }\n\n    async fn find_by_email(\u0026self, email: \u0026str) -\u003e AuthResult\u003cOption\u003cAuthUser\u003e\u003e {\n        // Your database query logic\n        todo!()\n    }\n\n    async fn find_by_username(\u0026self, username: \u0026str) -\u003e AuthResult\u003cOption\u003cAuthUser\u003e\u003e {\n        // Your database query logic\n        todo!()\n    }\n\n    async fn create_user(\u0026self, user: AuthUser) -\u003e AuthResult\u003cAuthUser\u003e {\n        // Your user creation logic\n        todo!()\n    }\n\n    async fn update_user(\u0026self, user: AuthUser) -\u003e AuthResult\u003cAuthUser\u003e {\n        // Your user update logic\n        todo!()\n    }\n\n    async fn delete_user(\u0026self, id: \u0026str) -\u003e AuthResult\u003c()\u003e {\n        // Your user deletion logic\n        todo!()\n    }\n}\n```\n\n### Custom OAuth Provider\n\n```rust\nuse actix_passport::{oauth::{OAuthProvider, OAuthUser}, types::AuthResult};\nuse async_trait::async_trait;\n\npub struct CustomOAuthProvider {\n    client_id: String,\n    client_secret: String,\n}\n\n#[async_trait]\nimpl OAuthProvider for CustomOAuthProvider {\n    fn name(\u0026self) -\u003e \u0026str {\n        \"custom\"\n    }\n\n    fn authorize_url(\u0026self, state: \u0026str, redirect_uri: \u0026str) -\u003e AuthResult\u003cString\u003e {\n        // Generate OAuth authorization URL\n        todo!()\n    }\n\n    async fn exchange_code(\u0026self, code: \u0026str, redirect_uri: \u0026str) -\u003e AuthResult\u003cOAuthUser\u003e {\n        // Exchange code for user info\n        todo!()\n    }\n}\n```\n\n## Examples\n\nSee the [`examples/`](examples/) directory for complete working examples:\n\n- [`basic_example/`](examples/basic_example/) - Basic password authentication\n- [`oauth_example/`](examples/oauth_example/) - OAuth with Google and GitHub\n- [`postgres_example/`](examples/postgres_example/) - Example with PostgreSQL user store\n- [`advanced_example/`](examples/advanced_example/) - Advanced example with SQLite and Bearer token authentication\n\n## Feature Flags\n\nControl which features to include:\n\n```toml\n[dependencies]\nactix-passport = { version = \"0.1\", features = [\"password\", \"oauth\"] }\n```\n\nAvailable features:\n- `password` (default) - Username/password authentication\n- `oauth` (default) - OAuth 2.0 providers\n- `postgres` - PostgreSQL user store\n\n## Architecture\n\n### Core Components\n\n- **`UserStore`** - Interface for user persistence (database, file, etc.)\n- **`ActixPassport`** - Main framework object containing all configured services\n- **`AuthStrategy`** - Interface for authentication strategies\n\n### Extractors\n- **`AuthedUser`** - Requires authentication, returns user or 401\n- **`OptionalAuthedUser`** - Optional authentication, returns `Option\u003cUser\u003e`\n\n\n## Testing\n\nRun the test suite:\n\n```bash\ncargo test\n```\n\nRun the example servers:\n\n```bash\ncd examples/basic_example \u0026\u0026 cargo run\n# or for OAuth example\ncd examples/oauth_example \u0026\u0026 cargo run\n```\n\nThen test the endpoints:\n\n```bash\n# Register a new user\ncurl -X POST http://localhost:8080/auth/register \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"email\": \"user@example.com\", \"password\": \"secure_password\", \"username\": \"testuser\"}'\n\n# Login\ncurl -X POST http://localhost:8080/auth/login \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"identifier\": \"user@example.com\", \"password\": \"secure_password\"}'\n\n# Access protected endpoint (session cookie is set automatically after login)\ncurl http://localhost:8080/dashboard \\\n  --cookie-jar cookies.txt --cookie cookies.txt\n```\n\n## License\n\nThis project is licensed under either of\n\n- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdensumesh%2Factix-passport","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdensumesh%2Factix-passport","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdensumesh%2Factix-passport/lists"}