marcoow / rust_rest

MIT License
5 stars 1 forks source link

Load current user from bearer token #13

Closed marcoow closed 10 months ago

marcoow commented 11 months ago

A typical authorization mechanism for APIs is to identify the authenticated users based on a bearer token (and load the respective user for that token from the DB). Axum provides a way to register a middleware that does just that and makes the loaded user available to all handlers: https://docs.rs/axum/0.6.20/axum/middleware/index.html#passing-state-from-middleware-to-handlers.