pub struct TokenOperations<'a> { /* private fields */ }Expand description
Focused token-management operations exposed from AuthFramework::tokens.
§Example
// Issue a JWT token
let token = auth.tokens().create("user-123", &["read"], "jwt", None).await?;
// Validate
assert!(auth.tokens().validate(&token).await?);
// Refresh
let new_token = auth.tokens().refresh(&token).await?;
// Revoke
auth.tokens().revoke(&new_token).await?;Implementations§
Source§impl TokenOperations<'_>
impl TokenOperations<'_>
Sourcepub async fn create<I, S>(
&self,
user_id: impl Into<String>,
scopes: I,
method_name: impl Into<String>,
lifetime: Option<Duration>,
) -> Result<AuthToken>
pub async fn create<I, S>( &self, user_id: impl Into<String>, scopes: I, method_name: impl Into<String>, lifetime: Option<Duration>, ) -> Result<AuthToken>
Create a new authentication token for a user.
scopes accepts any iterator of string-like values, so all of these
work:
ⓘ
// Vec<String>
tokens.create("uid", vec!["read".into()], "jwt", None).await?;
// Slice of &str
tokens.create("uid", &["read", "write"], "jwt", None).await?;
// Empty
tokens.create("uid", std::iter::empty::<&str>(), "jwt", None).await?;§Arguments
user_id— the user to issue a token forscopes— permission scopes to embed in the tokenmethod_name— the auth method that authenticated the user (e.g."jwt")lifetime— custom lifetime, orNonefor the configured default
Sourcepub async fn create_token(&self, req: TokenCreateRequest) -> Result<AuthToken>
pub async fn create_token(&self, req: TokenCreateRequest) -> Result<AuthToken>
Create a token from a TokenCreateRequest.
This is the preferred entry point — it replaces positional Option
parameters with a self-documenting builder.
§Example
let token = auth.tokens().create_token(
TokenCreateRequest::new("user-123", "jwt")
.scope("read")
.scope("write")
).await?;Sourcepub async fn validate(&self, token: &AuthToken) -> Result<bool>
pub async fn validate(&self, token: &AuthToken) -> Result<bool>
Validate an authentication token.
Sourcepub async fn refresh(&self, token: &AuthToken) -> Result<AuthToken>
pub async fn refresh(&self, token: &AuthToken) -> Result<AuthToken>
Refresh an authentication token.
Sourcepub async fn list_for_user(&self, user_id: &str) -> Result<Vec<AuthToken>>
pub async fn list_for_user(&self, user_id: &str) -> Result<Vec<AuthToken>>
List all tokens belonging to a user.
Sourcepub async fn create_api_key(
&self,
user_id: &str,
expires_in: Option<Duration>,
) -> Result<String>
pub async fn create_api_key( &self, user_id: &str, expires_in: Option<Duration>, ) -> Result<String>
Create an API key for a user.
Sourcepub async fn validate_api_key(&self, api_key: &str) -> Result<UserInfo>
pub async fn validate_api_key(&self, api_key: &str) -> Result<UserInfo>
Validate an API key and return the associated user info.
Sourcepub async fn revoke_api_key(&self, api_key: &str) -> Result<()>
pub async fn revoke_api_key(&self, api_key: &str) -> Result<()>
Revoke an API key.
Auto Trait Implementations§
impl<'a> Freeze for TokenOperations<'a>
impl<'a> !RefUnwindSafe for TokenOperations<'a>
impl<'a> Send for TokenOperations<'a>
impl<'a> Sync for TokenOperations<'a>
impl<'a> Unpin for TokenOperations<'a>
impl<'a> UnsafeUnpin for TokenOperations<'a>
impl<'a> !UnwindSafe for TokenOperations<'a>
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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