Struct actix_jwt_auth_middleware::CookieSigner
source · pub struct CookieSigner<Claims, Algorithm>where
Algorithm: Algorithm,
Algorithm::SigningKey: Clone,{ /* private fields */ }
Expand description
Used in the creation process of access and refresh tokens.
The crate::Authority
uses it to automatically refresh the auth token.
It holds the private key as well as configuration option.
Example
use actix_jwt_auth_middleware::CookieSigner;
use serde::Serialize;
use exonum_crypto::KeyPair;
use jwt_compact::{alg::Ed25519, TimeOptions};
use chrono::Duration;
#[derive(Serialize, Clone)]
struct User {
id: u32
}
let key_pair = KeyPair::random();
let cookie_signer = CookieSigner::<User, _>::new()
.signing_key(key_pair.secret_key().clone())
.access_token_name("my_access_token")
// makes the refresh token be valid for 2 hours
.refresh_token_lifetime(Duration::minutes(120))
// the access token can still be used up to 10 seconds after it expired
.time_options(TimeOptions::from_leeway(Duration::seconds(10)))
.algorithm(Ed25519)
.build()
.unwrap();
let cookie = cookie_signer.create_access_token_cookie(&User{
id: 1
}).unwrap();
Please referee to the CookieSignerBuilder
for a detailed description of Options available on this struct.
Implementations§
source§impl<Claims, Algorithm> CookieSigner<Claims, Algorithm>where
Algorithm: Algorithm + Clone,
Algorithm::SigningKey: Clone,
Claims: Serialize + Clone,
impl<Claims, Algorithm> CookieSigner<Claims, Algorithm>where
Algorithm: Algorithm + Clone,
Algorithm::SigningKey: Clone,
Claims: Serialize + Clone,
sourcepub fn new() -> CookieSignerBuilder<Claims, Algorithm>
pub fn new() -> CookieSignerBuilder<Claims, Algorithm>
Returns a new CookieSignerBuilder
A shorthand for creating a access token.
Internally it calls Self::create_signed_cookie
while
passing the access_token_name
as well as the access_token_lifetime
.
A shorthand for creating a refresh token.
Internally it calls Self::create_signed_cookie
while
passing the refresh_token_name
as well as the refresh_token_lifetime
.
Creates a cookie containing a jwt token.
-
claims
reference to an object of the generic typeClaims
which will be incorporated inside of the jwt string -
token_name
the name of the resulting cookie -
token_lifetime
how long the token is valid for
Trait Implementations§
source§impl<Claims: Clone, Algorithm> Clone for CookieSigner<Claims, Algorithm>where
Algorithm: Algorithm + Clone,
Algorithm::SigningKey: Clone + Clone,
impl<Claims: Clone, Algorithm> Clone for CookieSigner<Claims, Algorithm>where
Algorithm: Algorithm + Clone,
Algorithm::SigningKey: Clone + Clone,
source§fn clone(&self) -> CookieSigner<Claims, Algorithm>
fn clone(&self) -> CookieSigner<Claims, Algorithm>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more