Struct mal_api::oauth::OauthClient
source · pub struct OauthClient<State = Unauthenticated> { /* private fields */ }
Expand description
Client used to navigate and manage Oauth credentials with MAL
Implementations§
source§impl OauthClient<Unauthenticated>
impl OauthClient<Unauthenticated>
pub fn new() -> Result<Self, OauthError>
sourcepub fn generate_auth_url(&mut self) -> String
pub fn generate_auth_url(&mut self) -> String
Generate an authorization URL for the user to navigate to, to begin the authorization process
sourcepub async fn authenticate(
self,
authorization_response: RedirectResponse
) -> Result<OauthClient<Authenticated>, Box<dyn Error>>
pub async fn authenticate( self, authorization_response: RedirectResponse ) -> Result<OauthClient<Authenticated>, Box<dyn Error>>
Try and authenticate the client to get an authenticated Oauth client back.
sourcepub fn load_from_config() -> Result<OauthClient<Authenticated>, OauthError>
pub fn load_from_config() -> Result<OauthClient<Authenticated>, OauthError>
Load Oauth credentials from the MAL config
It is recommended to refresh the client after loading to ensure that all of the tokens are still valid
sourcepub fn load_from_values(
access_token: String,
refresh_token: String,
expires_at: u64
) -> Result<OauthClient<Authenticated>, OauthError>
pub fn load_from_values( access_token: String, refresh_token: String, expires_at: u64 ) -> Result<OauthClient<Authenticated>, OauthError>
Load an authenticated OauthClient by passing the necessary values
It’s recommended to refresh the client after to ensure that the given values are still valid credentials.
Note
: This method still relies on the MAL_CLIENT_ID
, MAL_CLIENT_SECRET
, and
MAL_REDIRECT_URL
environment variables being set
source§impl OauthClient<Authenticated>
impl OauthClient<Authenticated>
sourcepub fn get_access_token_secret(&self) -> &String
pub fn get_access_token_secret(&self) -> &String
Get the access token secret value
sourcepub fn get_refresh_token_secret(&self) -> &String
pub fn get_refresh_token_secret(&self) -> &String
Get the refresh token secret value
sourcepub fn get_expires_at(&self) -> &u64
pub fn get_expires_at(&self) -> &u64
Get the time at which the token will expire
The time is represented as number of seconds since the Unix Epoch
sourcepub fn save_to_config(&self) -> Result<(), OauthError>
pub fn save_to_config(&self) -> Result<(), OauthError>
Save the Oauth credentials to the config