Crate rjwt[−][src]
Provides an Actor
and (de)serializable Token
struct which support authenticating
Javascript Web Tokens with a custom payload. See jwt.io for more information
on the JWT spec.
The provided Actor
uses the
ECDSA
algorithm to sign tokens (using the ed25519_dalek
crate).
Example:
struct Resolver { actors: HashMap<String, Actor<String>>, } #[async_trait] impl Resolve for Resolver { type Host = String; type ActorId = String; type Claims = (); async fn resolve( &self, _host: &Self::Host, actor_id: &Self::ActorId ) -> Result<Actor<Self::ActorId>> { self .actors .get(actor_id) .cloned() .ok_or_else(|| Error::new(ErrorKind::Fetch, actor_id)) } } let actor = Actor::new("actor1".to_string()); let resolver = Resolver { actors: vec![("actor1".to_string(), actor.clone())].into_iter().collect() }; let token = Token::new( "example.com".to_string(), SystemTime::now(), Duration::from_secs(30), actor.id().to_string(), ()); let encoded = actor.sign_token(&token).unwrap(); let decoded = block_on(resolver.validate(&encoded)).unwrap(); assert_eq!(token, decoded);
Structs
Actor | An actor with an identifier of type |
Error | An error encountered while handling a |
Keypair | An ed25519 keypair. |
PublicKey | An ed25519 public key. |
Signature | Ed25519 signature. |
Token | A Javascript Web Token. |
Enums
ErrorKind | The type of error encountered.
|
Traits
Resolve |
Type Definitions
Result | The result of a |