Skip to content

Commit

Permalink
Merge pull request #3 from shuttle-hq/refactor/re_export
Browse files Browse the repository at this point in the history
refactor: re-export `jsonwebtoken` structs
  • Loading branch information
chesedo committed Mar 25, 2024
2 parents f8822ad + b394096 commit 338bf77
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tower-jwt"
description = "Tower middleware to parse JWTs on Authorization Bearers"
version = "0.2.0"
version = "0.2.1"
license = "Apache-2.0"
repository = "https://github.com/shuttle-hq/tower-jwt"
documentation = "https://docs.rs/tower-jwt"
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ This is build on top of the [jsonwebtoken](https://docs.rs/jsonwebtoken) crate a
Since this is a Tower middleware it can be used on any framework like Axum, Tonic, etc.

# Symmetric example using Hyper
This example show how to use the re-exported `DecodingKey` and `Validation` from `jsonwebtoken` to parse and validate a JWT setup with a simple symmetric secret. It also show how to customize the default validator and how to extract both registered and public fields on a claim.

``` rust
use chrono::{DateTime, Utc};
use http::{header::AUTHORIZATION, Request, Response, StatusCode};
use http_body_util::Empty;
use jsonwebtoken::{DecodingKey, Validation};
use serde::Deserialize;
use std::convert::Infallible;
use tower::{Service, ServiceBuilder, ServiceExt};
use tower_jwt::{JwtLayer, RequestClaim};
use tower_jwt::{DecodingKey, JwtLayer, RequestClaim, Validation};

// Setup your claim with the fields you want to extract
#[derive(Clone, Deserialize, Debug)]
Expand Down Expand Up @@ -101,14 +101,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
use axum::{routing::get, Extension, Router};
use http::{Request, StatusCode};
use http_body_util::Empty;
use jsonwebtoken::{DecodingKey, Validation};
use ring::{
rand,
signature::{self, Ed25519KeyPair, KeyPair},
};
use serde::Deserialize;
use tower::ServiceExt;
use tower_jwt::{JwtLayer, RequestClaim};
use tower_jwt::{DecodingKey, JwtLayer, RequestClaim, Validation};

// Setup your claim with the fields you want to extract
#[derive(Deserialize, Clone)]
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use std::{convert::Infallible, future::Future, marker::PhantomData, pin::Pin, ta
use async_trait::async_trait;
use headers::{authorization::Bearer, Authorization, HeaderMapExt};
use http::{Request, Response, StatusCode};
use jsonwebtoken::{decode, DecodingKey, Validation};
use jsonwebtoken::decode;
pub use jsonwebtoken::{DecodingKey, Validation};
use pin_project::pin_project;
use serde::Deserialize;
use tower::{Layer, Service};
Expand Down

0 comments on commit 338bf77

Please sign in to comment.