# JWT Cookie Encoder/Decoder in Rust This Rust module provides functionality to encode and decode JSON Web Tokens (JWT) for user authentication. It uses the `http-scrap`,`jsonwebtoken`, `serde`, and `uuid` crates to handle JWTs securely. ## Table of Contents - [Overview](#overview) - [Dependencies](#dependencies) - [Structs](#structs) - [Claims](#claims) - [Users](#users) - [Cookie](#cookie) - [Functions](#functions) - [encode](#encode) - [decode](#decode) - [Usage](#usage) - [Example](#example) ## Overview This module demonstrates how to encode and decode JWTs, using secret keys stored in environment variables. JWTs are commonly used for user authentication, storing details like user IDs, names, and expiration times. ## Dependencies Make sure to add the following dependencies to your `Cargo.toml`: ```toml [dependencies] serde = { version = "1.0", features = ["derive"] } jsonwebtoken = "8.0" uuid = "1.2" ``` ```rust [encode] //encode token let user = Users { name: String::from("John Doe"), email: String::from("john.doe@example.com"), exp: 3600, // Token expires in 1 hour }; let jwt = Cookie::encode("JWT_SECRET_NAME".to_string(), user).unwrap(); println!("Generated JWT: {}", jwt); ``` ```rust [decode] //decode use http_scrap::Response; let response = Response::new(&response); //use http-scrap let cookie = response.cookie(); let decoded = Cookie::decode("JWT_SECRET_NAME".to_string(), cookie).unwrap(); println!("Decoded Claims: {:?}", decoded.claims); ```