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§

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 type Claims 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§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more