Macro auth

Source
macro_rules! auth {
    ($T: ty) => { ... };
}
Expand description

The ncryptf::auth!() macro provides the appropriate generic implementation details of FromRequest to allow User entities to be returned as a Rocket request guard (FromRequest). The core features of ncryptf authorization verification are implemented through this macro. If you wish to utilize ncryptf’s authorization features you must perform the following.

§Usage

  1. Attach the ncryptf::Fairing to your Rocket configuration:
let rocket = rocket::custom(config)
    .attach(NcryptfFairing);
  1. Define your User entity, and have to implement AuthorizationTrait.
  2. At the end of your User entity struct file, bind the macro FromRequest to your User entity.
ncryptf::auth!(User);
  1. Your User is now available as part of the request guard:
#[get("/auth_info")]
fn auth_echo(_user: User){
    dbg!(_user);
}

NOTE: The Authorization Features of ncryptf are exclusively available if and only if you set the appropriate Content-Type to either application/json, or application/vnd.ncryptf+json, even for GET requests, and other requests that don’t have a body. The FromRequest functionality is only available for these content types. Additionally, ncryptf::rocket::Json will handle all JSON + Ncryptf+JSON content types when this is in use. ncryptf::rocket::Json is mostly compatible with rocket::serde::Json, but shares the same limitations, features, and particularities.