cduvray / jwt-authorizer

JWT authorization layer for Axum.
MIT License
69 stars 21 forks source link

Allow usage of variables within `check` (closures can only be coerced to `fn` types if they do not capture any variables) #32

Closed lcmgh closed 1 year ago

lcmgh commented 1 year ago

Hi!

I want to check my custom claim against a predefined config. Therefore I have to move a variable into the closure of `fn check.

https://docs.rs/jwt-authorizer/latest/jwt_authorizer/layer/struct.JwtAuthorizer.html#method.check

But when trying to use a variable within the check callback I am facing closures can only be coerced tofntypes if they do not capture any variables

cduvray commented 1 year ago

Hi, the PR #36, replacing a function pointer by a Fn() trait should fix you problem,

https://github.com/cduvray/jwt-authorizer/blob/20b604e2c8d7a6ac9c210dcb075a6bb89b3f3dc6/jwt-authorizer/src/builder.rs#L157-L159