Skip to main content

Crate webgates_codecs

Crate webgates_codecs 

Source
Expand description

§webgates-codecs

JWT encoding, decoding, validation, and JWKS helpers for webgates applications.

This crate is the codec layer of the workspace. It gives you the building blocks for encoding, decoding, and validating JWT payloads without pulling in HTTP, cookies, middleware, or framework-specific integration.

§When to use this crate

Use webgates-codecs when you want:

  • a small codec abstraction via Codec
  • JWT claim types and a JWT codec in jwt
  • issuer-aware token validation helpers
  • ES384 JWKS key modeling in jwt::jwks
  • structured codec and JWT error types

The crate depends only on shared core types from webgates-core and keeps transport concerns out of scope.

§Quick start

use std::sync::Arc;
use webgates_codecs::jsonwebtoken::crypto::rust_crypto::DEFAULT_PROVIDER as JWT_CRYPTO_PROVIDER;
use webgates_codecs::jwt::{JsonWebToken, JwtClaims, RegisteredClaims};
use webgates_codecs::jwt::validation_service::JwtValidationService;
use webgates_codecs::Codec;
use webgates_core::accounts::Account;
use webgates_core::groups::Group;
use webgates_core::roles::Role;

type Claims = JwtClaims<Account<Role, Group>>;

let _ = JWT_CRYPTO_PROVIDER.install_default();
let codec = Arc::new(JsonWebToken::<Claims>::default());
let claims = JwtClaims::new(
    Account::<Role, Group>::new("user@example.com"),
    RegisteredClaims::new("my-app", 4_102_444_800),
);

let token = codec.encode(&claims)?;
let decoded = codec.decode(&token)?;
assert!(decoded.has_issuer("my-app"));

let validator = JwtValidationService::new(Arc::clone(&codec), "my-app");
let _ = validator.validate_token(std::str::from_utf8(&token)?);

§Getting started on docs.rs

A good reading order is:

  1. Codec
  2. jwt::RegisteredClaims
  3. jwt::JwtClaims
  4. jwt::JsonWebToken
  5. jwt::validation_service::JwtValidationService
  6. jwt::jwks

Re-exports§

pub use jsonwebtoken;

Modules§

errors
Error types for codec and JWT processing.
jwt
JWT claim types, codecs, validation helpers, and JWKS support.

Enums§

Error
Root error type for webgates-codecs.

Traits§

Codec
Encodes and decodes typed payloads.

Type Aliases§

Result
Result alias used by codec implementations in this crate.