pub fn gen_jwt_auth<T: Send + Sync + DeserializeOwned + 'static>(
secret_key: String,
finders: Vec<Box<dyn JwtTokenFinder>>,
) -> JwtAuth<T, ConstDecoder>
Expand description
Generate a jwt middleware with the provided parameters
Examples found in repository?
examples/hello.rs (lines 97-100)
95async fn main() -> anyhow::Result<()> {
96 let config = Config::from_config_file("./config.toml").expect("config file not found");
97 let jwt = authorization::gen_jwt_auth::<JwtClaim>(
98 config.secret_key.clone(),
99 vec![Box::new(HeaderFinder::new())],
100 );
101
102 webserver_rs::serve_routes! {
103 config => [
104 // http://localhost:8080/hello
105 router!([get, post] => @hello)
106 .hoop(authorization::AuthGuard::new(|_e| html_err!("unauthorized"))),
107 // http://localhost:8080/user/login
108 router!([get] => /user/@login),
109 // http://localhost:8080/a/b/show
110 router!([get, post] => a/b/@ab::show),
111 // http://localhost:8080/b/c/show/*
112 router!([get, post, put] => /b/c/@ab::show/<**path>),
113 // http://localhost:8080/test_json
114 router!([get, post] => @text_json).hoop(build_cros("*")),
115 // http://localhost:8080/ab/shop/show
116 router!([get, post] => ...@ab::shop::show).hoop(build_cros("*")),
117 ] & [jwt, /*Middlewares*/]
118 };
119 Ok(())
120}