pub struct Token {
pub access_token: String,
pub expires_in: Duration,
pub expires_at: Option<DateTime<Utc>>,
pub refresh_token: Option<String>,
pub scopes: HashSet<String>,
}Expand description
Spotify access token information
Fields§
§access_token: StringAn access token that can be provided in subsequent calls
expires_in: DurationThe time period for which the access token is valid.
expires_at: Option<DateTime<Utc>>The valid time for which the access token is available represented in ISO 8601 combined date and time.
refresh_token: Option<String>A token that can be sent to the Spotify Accounts service in place of an authorization code
scopes: HashSet<String>A list of scopes
which have been granted for this access_token
You may use the scopes! macro in
rspotify-macros to build it at
compile time easily.
Implementations§
Source§impl Token
impl Token
Sourcepub fn from_cache<T: AsRef<Path>>(path: T) -> ModelResult<Self>
pub fn from_cache<T: AsRef<Path>>(path: T) -> ModelResult<Self>
Tries to initialize the token from a cache file.
Sourcepub fn write_cache<T: AsRef<Path>>(&self, path: T) -> ModelResult<()>
pub fn write_cache<T: AsRef<Path>>(&self, path: T) -> ModelResult<()>
Saves the token information into its cache file.
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Check if the token is expired. It includes a margin of 10 seconds (which is how much a request would take in the worst case scenario).
Sourcepub fn auth_headers(&self) -> HashMap<String, String>
pub fn auth_headers(&self) -> HashMap<String, String>
Generates an HTTP token authorization header with proper formatting