pub struct StoredToken {
pub access_token: String,
pub refresh_token: String,
pub expires_at: u64,
}Expand description
Stored token data, persisted to the token file.
This is the format written by stoat login and read/updated by
stoat serve. The expires_at field is a Unix timestamp (seconds).
Fields§
§access_token: StringThe current OAuth access token.
refresh_token: StringThe refresh token for obtaining new access tokens.
expires_at: u64Unix timestamp (seconds) when the access token expires.
Implementations§
Source§impl StoredToken
impl StoredToken
Sourcepub fn to_json(&self) -> Result<String, Error>
pub fn to_json(&self) -> Result<String, Error>
Serialize to a JSON string.
§Errors
Returns a serde_json::Error if serialization fails (should not
happen for this type).
Sourcepub fn from_json(s: &str) -> Result<Self, Error>
pub fn from_json(s: &str) -> Result<Self, Error>
Deserialize from a JSON string.
§Errors
Returns a serde_json::Error if the input is not valid JSON or
does not match the expected schema.
Sourcepub const fn is_expired(&self, now_unix: u64) -> bool
pub const fn is_expired(&self, now_unix: u64) -> bool
Check whether the access token has expired.
now_unix is the current Unix timestamp in seconds. Returns true
if the current time is at or past expires_at.
Sourcepub const fn needs_refresh(&self, now_unix: u64, margin_secs: u64) -> bool
pub const fn needs_refresh(&self, now_unix: u64, margin_secs: u64) -> bool
Check whether the access token needs refreshing.
Returns true if the token is expired or will expire within
margin_secs seconds. This allows proactive refresh before the
token actually expires, avoiding 401 errors on forwarded requests.
Use DEFAULT_REFRESH_MARGIN_SECS for the standard margin.
Trait Implementations§
Source§impl Clone for StoredToken
impl Clone for StoredToken
Source§fn clone(&self) -> StoredToken
fn clone(&self) -> StoredToken
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for StoredToken
impl Debug for StoredToken
Source§impl<'de> Deserialize<'de> for StoredToken
impl<'de> Deserialize<'de> for StoredToken
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>,
Source§impl PartialEq for StoredToken
impl PartialEq for StoredToken
Source§impl Serialize for StoredToken
impl Serialize for StoredToken
impl Eq for StoredToken
impl StructuralPartialEq for StoredToken
Auto Trait Implementations§
impl Freeze for StoredToken
impl RefUnwindSafe for StoredToken
impl Send for StoredToken
impl Sync for StoredToken
impl Unpin for StoredToken
impl UnsafeUnpin for StoredToken
impl UnwindSafe for StoredToken
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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.