Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/akshitvadodariya1201/jwt_auth
This repository contains a Rust-based web service that utilizes JSON Web Tokens (JWT) for authentication.
https://github.com/akshitvadodariya1201/jwt_auth
api cargo jwt-authentication jwt-token rust
Last synced: about 1 month ago
JSON representation
This repository contains a Rust-based web service that utilizes JSON Web Tokens (JWT) for authentication.
- Host: GitHub
- URL: https://github.com/akshitvadodariya1201/jwt_auth
- Owner: AkshitVadodariya1201
- License: mit
- Created: 2024-07-23T07:45:24.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-07-23T10:10:59.000Z (5 months ago)
- Last Synced: 2024-07-23T13:56:52.056Z (5 months ago)
- Topics: api, cargo, jwt-authentication, jwt-token, rust
- Language: Rust
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JWT Authentication Service
This repository contains a Rust-based web service that utilizes JSON Web Tokens (JWT) for authentication. The service is built using the Axum framework for creating web applications with Rust. It demonstrates a simple login system where users can log in to receive a JWT token and then use this token to access protected routes.
## Features
- **User Authentication**: Implements a basic user authentication flow where users can log in using their credentials to receive a JWT token.
- **Protected Routes**: Includes examples of protected routes that require a valid JWT token to access.
- **JWT Token Management**: Utilizes the `jsonwebtoken` crate for encoding and decoding JWT tokens, ensuring secure token management.## Dependencies
The project relies on several key Rust crates:
- `tokio`: An asynchronous runtime for Rust, used as the foundation for running the web server and handling asynchronous operations.
- `jsonwebtoken`: A crate for encoding and decoding JWT tokens, providing the core functionality for token management.
- `axum`: A web application framework built on top of Hyper, providing routing and request handling.
- `serde` and `serde_json`: Serialization and deserialization libraries for converting Rust structs to JSON and vice versa.
- `chrono`: A date and time library for Rust, used for handling time-based operations in JWT tokens.## Project Structure
- `src/main.rs`: The entry point of the application, setting up the web server and routes.
- `src/controler.rs`: Contains the route handlers, including the login handler and a handler for retrieving protected information.
- `src/model.rs`: Defines the data models used in the application, including structures for login information and responses.## Getting Started
To run the project, ensure you have Rust and Cargo installed. Then, navigate to the project directory and run:
```sh
cargo run
```This will start the web server on `http://localhost:3000`. You can then use tools like `curl` or Postman or Hoppscotch to interact with the service.
### Routes
- `POST /login`: Logs in a user and returns a JWT token.
- `GET /get_info`: Returns protected information that requires a valid JWT token.