rusty-jwt

Crates.iorusty-jwt
lib.rsrusty-jwt
version0.1.14
sourcesrc
created_at2024-10-16 16:48:37.397301
updated_at2024-10-17 06:17:28.507741
descriptionA simple Rust library for encoding and decoding JSON Web Tokens (JWT).
homepagehttps://github.com/HashiramaSenjuhari/http_jwt
repositoryhttps://github.com/HashiramaSenjuhari/http_jwt
max_upload_size
id1412010
size10,415
Hariprasath (HashiramaSenjuhari)

documentation

README

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

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:

[dependencies]
serde = { version = "1.0", features = ["derive"] }
jsonwebtoken = "8.0"
uuid = "1.2"
[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);

[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);

Commit count: 0

cargo fmt