Skip to main content

Jwt

Struct Jwt 

Source
pub struct Jwt { /* private fields */ }
Expand description

Struct representing the JWT configuration and operations.

Implementations§

Source§

impl Jwt

Source

pub fn new(cfg: JwtCfg) -> Self

Creates a new Jwt instance from the given configuration.

§Arguments
  • cfg - A JwtCfg struct containing the JWT configuration.
§Returns
  • A new Jwt instance.
Source

pub fn generate_token_pair(&self, sub: String) -> Result<(String, String)>

Generates a pair of access and refresh tokens.

§Arguments
  • sub - The subject for which the tokens are generated.
§Returns
  • A Result containing a tuple of the access token and the refresh token, or an Error.
Source

pub fn generate_access_token(&self, sub: String) -> Result<String>

Generates an access token.

§Arguments
  • sub - The subject for which the access token is generated.
§Returns
  • A Result containing the generated access token as a string, or an Error.
Source

pub fn refresh_access_token(&self, refresh_token: &str) -> Result<String>

Refreshes an access token using a refresh token.

§Arguments
  • refresh_token - The refresh token used to generate a new access token.
§Returns
  • A Result containing the new access token, or an Error.
Source

pub fn validate_access_token(&self, token: &str) -> Result<Claims>

Validates an access token.

§Arguments
  • token - The access token to validate.
§Returns
  • A Result containing the Claims if validation is successful, or an Error.
Source

pub fn validate_refresh_token(&self, token: &str) -> Result<Claims>

Validates a refresh token.

§Arguments
  • token - The refresh token to validate.
§Returns
  • A Result containing the Claims if validation is successful, or an Error.

Trait Implementations§

Source§

impl Clone for Jwt

Source§

fn clone(&self) -> Jwt

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for Jwt

§

impl RefUnwindSafe for Jwt

§

impl Send for Jwt

§

impl Sync for Jwt

§

impl Unpin for Jwt

§

impl UnsafeUnpin for Jwt

§

impl UnwindSafe for Jwt

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.