feat: ToAuthorizationLayer

This commit is contained in:
cduvray 2023-08-14 08:02:56 +02:00
parent 57fbc6e399
commit d7d945c075
5 changed files with 124 additions and 28 deletions

View file

@ -1,5 +1,7 @@
use axum::{routing::get, Router};
use jwt_authorizer::{error::InitError, AuthError, JwtAuthorizer, JwtClaims, Refresh, RefreshStrategy};
use jwt_authorizer::{
error::InitError, AuthError, JwtAuthorizer, JwtClaims, Refresh, RefreshStrategy, ToAuthorizationLayer,
};
use serde::Deserialize;
use std::net::SocketAddr;
use tower_http::trace::TraceLayer;
@ -49,7 +51,7 @@ async fn main() -> Result<(), InitError> {
let api = Router::new()
.route("/protected", get(protected))
// adding the authorizer layer
.layer(jwt_auth.layer().await?);
.layer(jwt_auth.to_layer().await?);
let app = Router::new()
// public endpoint