pub struct AccessToken {
pub hash: String,
pub principal_id: String,
pub label: String,
pub created: UnixMillis,
pub last_used: Option<UnixMillis>,
pub expires: Option<UnixMillis>,
}Expand description
A registered access token: the credential smart HTTP authenticates with
§Why this is not a second identity model
It is a second authentication method for the identity model that already
exists. A token names a Principal and nothing else. It carries no grant,
no level and no scope, so every authorisation question it can produce is
still answered by AuthTable::may against that
principal’s grants — the same call, on the same table, that an SSH key
produces. Revoking the token removes a way in; it changes nobody’s access.
§The secret is not here, and cannot be
Self::hash is the SHA-256 of the token secret, hex, and it is also the
key this record is stored under. That is deliberate on both counts:
- the stored table never holds a usable credential, so a leaked auth
document (it is a git blob, and every version of it is kept — see
doc) does not hand anybody a login; - a lookup is hash the presented secret, probe once, which is O(1) and does not walk the token list. A table keyed by anything else would either scan on every HTTP request or need a second index to avoid it.
The hash is therefore also the token’s public id: it is what
gunnar admin token list prints and what revocation names. Printing a hash
is safe; printing the secret again is not possible, which is the point.
Fields§
§hash: StringSHA-256 of the secret, lowercase hex. The primary key, and the id an operator sees.
principal_id: StringWhich principal this token authenticates.
label: StringAn operator-supplied label: which laptop, which CI job. Never part of the credential.
created: UnixMillisWhen it was created.
last_used: Option<UnixMillis>When it last authenticated, if ever.
expires: Option<UnixMillis>When it stops being accepted, if ever.
Implementations§
Source§impl AccessToken
impl AccessToken
Sourcepub fn is_valid_at(&self, now: UnixMillis) -> bool
pub fn is_valid_at(&self, now: UnixMillis) -> bool
Is this token still valid at now?
Same shape as PublicKey::is_valid_at and deliberately so: expiry is
one rule, and two credentials that expired by different arithmetic would
be two rules (one implementation).
Trait Implementations§
Source§impl Clone for AccessToken
impl Clone for AccessToken
Source§impl Debug for AccessToken
impl Debug for AccessToken
Source§impl<'de> Deserialize<'de> for AccessToken
impl<'de> Deserialize<'de> for AccessToken
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for AccessToken
Source§impl PartialEq for AccessToken
impl PartialEq for AccessToken
Source§impl Serialize for AccessToken
impl Serialize for AccessToken
impl StructuralPartialEq for AccessToken
Auto Trait Implementations§
impl Freeze for AccessToken
impl RefUnwindSafe for AccessToken
impl Send for AccessToken
impl Sync for AccessToken
impl Unpin for AccessToken
impl UnsafeUnpin for AccessToken
impl UnwindSafe for AccessToken
Blanket Implementations§
impl<T> Allocation for T
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
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<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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
key and return true if they are equal.