#[non_exhaustive]pub struct DeviceToken {
pub id: i64,
pub device: String,
pub name: String,
pub abilities: Option<Vec<String>>,
pub last_used_at: Option<DateTime>,
pub expires_at: Option<DateTime>,
pub created_at: Option<DateTime>,
}Expand description
A stored API token of a device. Only a SHA-256 hash of the secret is stored.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.id: i64The device_tokens row id, also what follows the d in the plain token.
device: StringThe app’s key for the device that owns the token, e.g. kiosk:3.
name: StringA label chosen at creation.
abilities: Option<Vec<String>>What the token may do (Device::can); None for everything.
last_used_at: Option<DateTime>When a request last authenticated with it; None if never used.
expires_at: Option<DateTime>When it stops working; None for never.
created_at: Option<DateTime>When it was created.
Implementations§
Source§impl DeviceToken
impl DeviceToken
Sourcepub async fn create(
db: &Db,
device: &str,
name: &str,
abilities: Option<&[&str]>,
expires_at: Option<DateTime>,
) -> Result<NewDeviceToken>
pub async fn create( db: &Db, device: &str, name: &str, abilities: Option<&[&str]>, expires_at: Option<DateTime>, ) -> Result<NewDeviceToken>
Creates a token for device (the app’s key, e.g. "kiosk:3").
abilities limits it (Some(&["sales:create"]), "*" allows
everything); None allows everything. It stops working at expires_at.
use renox::auth::DeviceToken;
let made = DeviceToken::create(&db, "kiosk:3", "front desk", Some(&["sales:create"]), None).await?;
println!("give this to the kiosk once: {}", made.plain);Sourcepub async fn for_device(db: &Db, device: &str) -> Result<Vec<DeviceToken>>
pub async fn for_device(db: &Db, device: &str) -> Result<Vec<DeviceToken>>
The tokens of device, newest first.
Sourcepub async fn revoke(db: &Db, device: &str, token_id: i64) -> Result<bool>
pub async fn revoke(db: &Db, device: &str, token_id: i64) -> Result<bool>
Revokes one token of device; returns whether it existed.
Trait Implementations§
Source§impl Clone for DeviceToken
impl Clone for DeviceToken
Source§impl Debug for DeviceToken
impl Debug for DeviceToken
Auto Trait Implementations§
impl Freeze for DeviceToken
impl RefUnwindSafe for DeviceToken
impl Send for DeviceToken
impl Sync for DeviceToken
impl Unpin for DeviceToken
impl UnsafeUnpin for DeviceToken
impl UnwindSafe for DeviceToken
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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