pub struct ApiKeyService<S> { /* private fields */ }Implementations§
Source§impl<S> ApiKeyService<S>
impl<S> ApiKeyService<S>
pub fn new(storage: S) -> Self
Sourcepub async fn create(
&self,
user_id: Uuid,
org_id: Option<Uuid>,
name: String,
scopes: Vec<String>,
expires_at: DateTime<Utc>,
) -> Result<ApiKeyResponse>
pub async fn create( &self, user_id: Uuid, org_id: Option<Uuid>, name: String, scopes: Vec<String>, expires_at: DateTime<Utc>, ) -> Result<ApiKeyResponse>
Create a new API key for user_id. Returns the ApiKey row and the
raw key (hex-encoded 32 random bytes). The raw key is never stored;
only the SHA-256 hash is persisted.
expires_at is required and must be at most [MAX_KEY_TTL] (365 days) in the future.
Sourcepub async fn list(&self, user_id: Uuid) -> Result<Vec<ApiKey>>
pub async fn list(&self, user_id: Uuid) -> Result<Vec<ApiKey>>
List all API keys belonging to user_id.
Sourcepub async fn revoke(&self, user_id: Uuid, key_id: Uuid) -> Result<()>
pub async fn revoke(&self, user_id: Uuid, key_id: Uuid) -> Result<()>
Revoke (delete) an API key. Enforces that the key belongs to user_id.
Sourcepub async fn authenticate(&self, raw_key: &str) -> Result<ApiKey>
pub async fn authenticate(&self, raw_key: &str) -> Result<ApiKey>
Authenticate using a raw API key string.
Returns Err(AuthError::InvalidToken) if the key is unknown, expired,
or otherwise invalid. On success, updates last_used_at.
Auto Trait Implementations§
impl<S> Freeze for ApiKeyService<S>where
S: Freeze,
impl<S> RefUnwindSafe for ApiKeyService<S>where
S: RefUnwindSafe,
impl<S> Send for ApiKeyService<S>where
S: Send,
impl<S> Sync for ApiKeyService<S>where
S: Sync,
impl<S> Unpin for ApiKeyService<S>where
S: Unpin,
impl<S> UnsafeUnpin for ApiKeyService<S>where
S: UnsafeUnpin,
impl<S> UnwindSafe for ApiKeyService<S>where
S: UnwindSafe,
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