{"id":15091166,"url":"https://github.com/aarambhdevhub/rust_auth","last_synced_at":"2025-08-02T05:41:44.185Z","repository":{"id":252478221,"uuid":"840563701","full_name":"AarambhDevHub/rust_auth","owner":"AarambhDevHub","description":"Welcome to RustSecureAPI, a robust and secure Rust-based API project built with Actix-Web. This repository provides a comprehensive guide and implementation for creating a scalable backend system with JWT-based authentication and PostgreSQL integration.","archived":false,"fork":false,"pushed_at":"2024-08-26T08:45:58.000Z","size":54,"stargazers_count":12,"open_issues_count":1,"forks_count":9,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T06:36:08.453Z","etag":null,"topics":["actix","actix-rs","actix-web","authentication","backend","jwt","jwt-authentication","jwt-token","openapi","postgresql","programming","programming-language","rust","rust-lang","sqlx","sqlx-cli","swagger","swagger-api","swagger-ui"],"latest_commit_sha":null,"homepage":"https://youtu.be/X74uyTr5kk8?feature=shared","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/AarambhDevHub.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}},"created_at":"2024-08-10T03:01:21.000Z","updated_at":"2025-04-11T18:04:46.000Z","dependencies_parsed_at":"2024-08-26T10:36:10.774Z","dependency_job_id":"5c9891db-cedc-40ee-a406-1412788d7b56","html_url":"https://github.com/AarambhDevHub/rust_auth","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"18b280edf492144d05e76b697ec54698dd792db3"},"previous_names":["aarambhdevhub/rust_auth"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AarambhDevHub/rust_auth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AarambhDevHub%2Frust_auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AarambhDevHub%2Frust_auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AarambhDevHub%2Frust_auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AarambhDevHub%2Frust_auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AarambhDevHub","download_url":"https://codeload.github.com/AarambhDevHub/rust_auth/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AarambhDevHub%2Frust_auth/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268339401,"owners_count":24234546,"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-08-02T02:00:12.353Z","response_time":74,"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","actix-rs","actix-web","authentication","backend","jwt","jwt-authentication","jwt-token","openapi","postgresql","programming","programming-language","rust","rust-lang","sqlx","sqlx-cli","swagger","swagger-api","swagger-ui"],"created_at":"2024-09-25T10:36:05.491Z","updated_at":"2025-08-02T05:41:44.118Z","avatar_url":"https://github.com/AarambhDevHub.png","language":"Rust","readme":"# Rust Authentication API with Actix-Web\n\n[![Thumbnail](https://img.youtube.com/vi/X74uyTr5kk8/maxresdefault.jpg)](https://youtu.be/X74uyTr5kk8)\n\nThis repository contains a comprehensive Rust-based API project using Actix-Web. The API includes robust JWT-based authentication, user management, and Swagger UI integration for interactive API documentation.\n\n## Table of Contents\n\n- [Project Overview](#project-overview)\n- [Project Structure](#project-structure)\n- [Setup Instructions](#setup-instructions)\n  - [Prerequisites](#prerequisites)\n  - [Environment Variables](#environment-variables)\n  - [Database Migrations](#database-migrations)\n  - [Running the Server](#running-the-server)\n- [API Endpoints](#api-endpoints)\n  - [Authentication Endpoints](#authentication-endpoints)\n  - [User Endpoints](#user-endpoints)\n- [Swagger UI](#swagger-ui)\n- [Middleware](#middleware)\n- [Unit Testing](#unit-testing)\n- [OpenAPI Documentation](#openapi-documentation)\n- [Contributing](#contributing)\n- [License](#license)\n- [Contact](#contact)\n\n## Project Overview\n\nThis project showcases how to build a complete authentication system with Rust, using Actix-Web. The API is designed to be scalable and secure, integrating PostgreSQL for data storage and JWT for user authentication.\n\n### Key Features:\n\n- **User Authentication:** Secure user registration, login, and logout using JWT.\n- **User Management:** Retrieve user information and list all users.\n- **Database Integration:** PostgreSQL with SQLx for efficient database handling.\n- **Environment Configurations:** Manage configurations via environment variables.\n- **Error Handling:** Comprehensive error handling with custom error types.\n- **API Documentation:** Integrated Swagger UI for interactive API documentation.\n- **Middleware:** Custom middleware for authentication and role-based access control.\n\n## Project Structure\n\n```plaintext\n├── src\n│   ├── handlers           # API route handlers\n│   │   ├── mod.rs         # Utility functions module\n│   │   ├── auth.rs        # Authentication-related handlers\n│   │   ├── users.rs       # User-related handlers\n│   ├── utils              # Utility functions\n│   │   ├── mod.rs         # Utility functions module\n│   │   ├── password.rs    # Password hashing and verification\n│   │   ├── token.rs       # JWT signing and verification\n│   ├── auth.rs            # Middleware implementations\n│   ├── config.rs          # Configuration file for environment variables\n│   ├── db.rs              # Database access layer\n│   ├── dtos.rs            # Data Transfer Objects (DTOs)\n│   ├── error.rs           # Error handling module\n│   ├── main.rs            # Application entry point\n│   ├── models.rs          # Database models\n├── migrations             # Database migrations folder (created by SQLx)\n├── .env                   # Environment variables file\n├── Cargo.toml             # Rust dependencies and project metadata\n├── README.md              # Project documentation\n```\n\n# Setup Instructions\n\n## Prerequisites\n\nEnsure you have the following tools installed:\n\n- [Rust](https://www.rust-lang.org/tools/install)\n- [PostgreSQL](https://www.postgresql.org/download/)\n- [SQLx-CLI](https://github.com/launchbadge/sqlx/tree/master/sqlx-cli) (for database migrations)\n\n## Environment Variables\n\nCreate a `.env` file in the root directory with the following content:\n\n    DATABASE_URL=postgres://username:password@localhost/dbname\n    JWT_SECRET=your_jwt_secret_key\n    JWT_EXPIRATION=60  # JWT expiration time in minutes\n\nReplace the placeholders with your actual database credentials and desired JWT configuration.\n\n## Database Migrations\n\nRun the following command to perform database migrations:\n\n    sqlx migrate run\n\nThis will set up the necessary database schema for the application.\n\n## Running the Server\n\nStart the server using the command:\n\n    cargo run\n    \nThe API will be accessible at http://localhost:8000.\n\n## API Endpoints\n\n### Authentication Endpoints\n\n- **Register User:** `POST /api/auth/register`\n- **Login User:** `POST /api/auth/login`\n- **Logout User:** `POST /api/auth/logout`\n\n### User Endpoints\n\n- **Get Authenticated User:** `GET /api/users/me`\n- **List Users:** `GET /api/users`\n\nEach endpoint is protected by JWT-based authentication, ensuring secure access.\n\n## Swagger UI\n\nSwagger UI is integrated for interactive API exploration and documentation. Access it by navigating to:\n\nhttp://localhost:8000/swagger-ui\n\nHere, you can view all the available endpoints, along with detailed information on request and response formats.\n\n## Middleware\n\n### Authentication Middleware Guard\n\nThe custom authentication middleware guards routes by verifying the presence and validity of JWT tokens. It ensures that only authenticated users can access certain endpoints.\n\n### Role-Based Access Control\n\nIn addition to authentication, some routes enforce role-based access control (RBAC) using the `RequireAuth` middleware, which checks user roles like `Admin`, `Moderator`, or `User`.\n\n## OpenAPI Documentation\n\nThe project supports OpenAPI 3.0, with schema generation and endpoint documentation provided through the `utoipa` crate.\n\n### Adding and Customizing OpenAPI Documentation\n\n- **Register the OpenAPI Schema:** The `openapi` object is configured in `main.rs`.\n- **Register the API Handler as OpenAPI Path:** Each handler is registered as an OpenAPI path with detailed descriptions.\n- **Serving the Swagger UI:** The OpenAPI object is served via a web server, accessible through Swagger UI.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n## Donations\n\nIf you find this project useful and would like to support its continued development, you can make a donation via [Buy Me a Coffee](https://buymeacoffee.com/aarambhdevhub).\n\nThank you for your support!\n","funding_links":["https://buymeacoffee.com/aarambhdevhub"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faarambhdevhub%2Frust_auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faarambhdevhub%2Frust_auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faarambhdevhub%2Frust_auth/lists"}