Skip to content

Commit

Permalink
feat: Derive OperationIo for Jwt struct (#311)
Browse files Browse the repository at this point in the history
This will allow Jwt to be used in responses as well.

Also, derive serialize/deserialize
  • Loading branch information
spencewenski authored Aug 4, 2024
1 parent 0c758fc commit 32bbdaf
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/middleware/http/auth/jwt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ use crate::middleware::http::auth::jwt::ietf::Claims;
#[cfg(all(feature = "jwt-openid", not(feature = "jwt-ietf")))]
use crate::middleware::http::auth::jwt::openid::Claims;
use crate::util::serde::{deserialize_from_str, serialize_to_str};
#[cfg(feature = "open-api")]
use aide::OperationInput;
use async_trait::async_trait;
use axum::extract::{FromRef, FromRequestParts};
use axum::http::request::Parts;
Expand All @@ -35,19 +33,15 @@ type BearerAuthHeader = TypedHeader<Authorization<Bearer>>;
/// to the claims from `jwt-ietf`. If neither feature is enabled (but `jwt` is enabled), then
/// the default will simply be a [serde_json::Value]. In all cases, the type can be overridden
/// by the consumer.
#[cfg_attr(feature = "open-api", derive(aide::OperationIo))]
// #[derive(Deserialize)]
#[derive(Deserialize, Serialize)]
#[non_exhaustive]
pub struct Jwt<C = Claims>
where
C: for<'de> serde::Deserialize<'de>,
{
pub struct Jwt<C = Claims> {
pub header: Header,
pub claims: C,
}

// Required in order to use `Jwt` in an Aide route.
#[cfg(feature = "open-api")]
impl OperationInput for Jwt {}

#[async_trait]
impl<S, C> FromRequestParts<S> for Jwt<C>
where
Expand Down

0 comments on commit 32bbdaf

Please sign in to comment.