Enum mas_data_model::TokenType
source · pub enum TokenType {
AccessToken,
RefreshToken,
CompatAccessToken,
CompatRefreshToken,
}Expand description
Type of token to generate or validate
Variants§
AccessToken
An access token, used by Relying Parties to authenticate requests
RefreshToken
A refresh token, used by the refresh token grant
CompatAccessToken
A legacy access token
CompatRefreshToken
A legacy refresh token
Implementations§
source§impl TokenType
impl TokenType
sourcepub fn generate(self, rng: &mut (impl RngCore + ?Sized)) -> String
pub fn generate(self, rng: &mut (impl RngCore + ?Sized)) -> String
Generate a token for the given type
extern crate rand;
use rand::thread_rng;
use mas_data_model::TokenType::{AccessToken, RefreshToken};
AccessToken.generate(&mut thread_rng());
RefreshToken.generate(&mut thread_rng());sourcepub fn check(token: &str) -> Result<TokenType, TokenFormatError>
pub fn check(token: &str) -> Result<TokenType, TokenFormatError>
Check the format of a token and determine its type
use mas_data_model::TokenType;
assert_eq!(
TokenType::check("mat_kkLSacJDpek22jKWw4AcXG68b7U3W6_0Lg9yb"),
Ok(TokenType::AccessToken)
);
assert_eq!(
TokenType::check("mar_PkpplxPkfjsqvtdfUlYR1Afg2TpaHF_GaTQd2"),
Ok(TokenType::RefreshToken)
);
assert_eq!(
TokenType::check("syt_PkpplxPkfjsqvtdfUlYR1Afg2TpaHF_GaTQd2"),
Ok(TokenType::CompatAccessToken)
);§Errors
Returns an error if the token is not valid
Trait Implementations§
impl Copy for TokenType
impl Eq for TokenType
impl StructuralPartialEq for TokenType
Auto Trait Implementations§
impl Freeze for TokenType
impl RefUnwindSafe for TokenType
impl Send for TokenType
impl Sync for TokenType
impl Unpin for TokenType
impl UnwindSafe for TokenType
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more