By adding the authed
keyword and an @claim
parameter, you can generate code that uses JWT authentication.
type Token
type Claim
interface API
When you use JWT auth, a JwtValidator
is generated and you are required to implement token verification.
/// Implement this for your server struct.
///
/// ## Example
/// ```
/// impl JwtValidator for YourServerStruct {
/// fn validate<T: serde::de::DeserializeOwned>(token: &str) -> Result<T, ()> {
/// let claim = jsonwebtoken::decode(
/// token,
/// &DecodingKey::from_secret("* your secret key *".as_bytes()),
/// &Validation::default(),
/// )
/// .map_err(|_| ())?
/// .claims;
///
/// Ok(claim)
/// }
/// }
/// ```
After generation, implement it to enable JWT.
(For the Rust implementation, you need the jsonwebtoken
, async-trait
, and tokio(features = ["full"])
crates.)
use ;
use async_trait;
use ;
static SECRET: &'static str = "RUST IS GOOD!";
async
On the client side, authed methods require a token as the first argument.