pub struct Token {
pub access_token: String,
pub token_type: String,
pub scope: String,
pub expires_at: u64,
pub refresh_token: Option<String>,
}Expand description
OAuth token with expiry tracking.
Stores both access and refresh tokens, along with the absolute expiry timestamp.
Fields§
§access_token: StringBearer token for API requests.
token_type: StringToken type (always “Bearer” for Spotify).
scope: StringSpace-separated list of granted scopes.
expires_at: u64Unix timestamp when the access token expires.
refresh_token: Option<String>Token used to obtain new access tokens.
Implementations§
Source§impl Token
impl Token
Sourcepub fn from_response(response: SpotifyTokenResponse) -> Self
pub fn from_response(response: SpotifyTokenResponse) -> Self
Create a token from Spotify’s API response.
Converts the relative expires_in to an absolute timestamp.
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Check if the token is expired or about to expire.
Returns true if the token expires within the buffer period.
Sourcepub fn seconds_until_expiry(&self) -> i64
pub fn seconds_until_expiry(&self) -> i64
Get seconds until the token expires.
Returns negative value if already expired.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Token
impl<'de> Deserialize<'de> for Token
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>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Token
impl RefUnwindSafe for Token
impl Send for Token
impl Sync for Token
impl Unpin for Token
impl UnwindSafe for Token
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