Crates.io | cataclysm-jwt |
lib.rs | cataclysm-jwt |
version | 0.1.3 |
source | src |
created_at | 2024-07-24 17:49:12.59366 |
updated_at | 2024-07-24 17:49:12.59366 |
description | Simple session creator for JWT handling in cataclysm |
homepage | |
repository | https://github.com/Arthur-phys/cataclysm-jwt |
max_upload_size | |
id | 1314196 |
size | 99,743 |
Simple session builder for JWT with support for RS256 and HS256 for Cataclysm.
Simply add the dependecy to Cargo.toml
file:
cataclysm-jwt = { git = "https://github.com/Arthur-phys/cataclysm-jwt.git" }
The crate has three optional features:
Two examples can be found under the examples
folder. One is provided here for completeness:
const aud: &str = "AUDIENCE";
const iss: &str = "ISSUER";
const jwks_url: &str = "URL";
// Function requires a session as argument
async fn index(session: Session) -> Response {
// Parameters on JWT Payload can be obtained easily:
let iat = session.get("iat").unwrap();
let name = session.get("name").unwrap();
println!("Token issued at: {}",iat);
println!("Name of person: {}",name);
Response::ok().body("Hello, World!")
}
#[tokio::main]
async fn main() -> Result<(),Error> {
let server = Server::builder(
Branch::<()>::new("/").with(Method::Get.to(index))
).session_creator(
// Builder requires a session
// Assymmetric session built in this case
JWTSessionBuilder::with_rs256().aud(aud)
.iss(iss)
// Used url for JWKs
.add_from_jwks(jwks_url)
.await?
.build()?
)
.build().unwrap();
server.run("127.0.0.1:8000").await.unwrap();
Ok(())
}