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>
Sourcepub fn new<T: Into<String>>(
client_id: T,
client_secret: Option<T>,
redirect_url: T,
) -> Result<Self, OauthError>
pub fn new<T: Into<String>>( client_id: T, client_secret: Option<T>, redirect_url: T, ) -> Result<Self, OauthError>
Creates a new OauthClient for the PKCE flow
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>, OauthError>
pub async fn authenticate( self, authorization_response: RedirectResponse, ) -> Result<OauthClient<Authenticated>, OauthError>
Try and authenticate the client using a redirect response to get an authenticated Oauth client back
Sourcepub fn load_from_config<T: Into<String>>(
path: T,
) -> Result<OauthClient<Authenticated>, OauthError>
pub fn load_from_config<T: Into<String>>( path: T, ) -> Result<OauthClient<Authenticated>, OauthError>
Load an authenticated Oauth client from a MAL config file
It is recommended to refresh the client after loading to ensure that all of the tokens are still valid
Sourcepub fn load_from_values<T: Into<String>>(
access_token: T,
refresh_token: T,
client_id: T,
client_secret: Option<T>,
redirect_url: T,
expires_at: u64,
) -> Result<OauthClient<Authenticated>, OauthError>
pub fn load_from_values<T: Into<String>>( access_token: T, refresh_token: T, client_id: T, client_secret: Option<T>, redirect_url: T, 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
Sourcepub fn load_client_id_from_env() -> Result<String, OauthError>
pub fn load_client_id_from_env() -> Result<String, OauthError>
Load the MAL_CLIENT_ID environment variable
Sourcepub fn load_client_secret_from_env() -> Result<String, OauthError>
pub fn load_client_secret_from_env() -> Result<String, OauthError>
Load the MAL_CLIENT_SECRET environment variable
Sourcepub fn load_redirect_url_from_env() -> Result<String, OauthError>
pub fn load_redirect_url_from_env() -> Result<String, OauthError>
Load the MAL_REDIRECT_URL environment variable
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<T: Into<String>>(&self, path: T) -> Result<(), OauthError>
pub fn save_to_config<T: Into<String>>(&self, path: T) -> Result<(), OauthError>
Save the Oauth credentials to the config
This method is available if you want to persist your access, refresh, and expires_at values on the host
Sourcepub async fn refresh(self) -> Result<Self, OauthError>
pub async fn refresh(self) -> Result<Self, OauthError>
Refresh the access token using the refresh token