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>

source

pub fn new() -> Result<Self, OauthError>

source

pub fn generate_auth_url(&mut self) -> String

Generate an authorization URL for the user to navigate to, to begin the authorization process

source

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.

source

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

source

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>

source

pub fn get_access_token_secret(&self) -> &String

Get the access token secret value

source

pub fn get_refresh_token_secret(&self) -> &String

Get the refresh token secret value

source

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

source

pub fn save_to_config(&self) -> Result<(), OauthError>

Save the Oauth credentials to the config

source

pub async fn refresh(self) -> Result<Self, Box<dyn Error>>

Refresh the access token using the refresh token

Trait Implementations§

source§

impl<State: Debug> Debug for OauthClient<State>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<State> RefUnwindSafe for OauthClient<State>
where State: RefUnwindSafe,

§

impl<State> Send for OauthClient<State>
where State: Send,

§

impl<State> Sync for OauthClient<State>
where State: Sync,

§

impl<State> Unpin for OauthClient<State>
where State: Unpin,

§

impl<State> UnwindSafe for OauthClient<State>
where State: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more