Struct 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<T: Into<String>>( client_id: T, client_secret: Option<T>, redirect_url: T, ) -> Result<Self, OauthError>

Creates a new OauthClient for the PKCE flow

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>, OauthError>

Try and authenticate the client using a redirect response to get an authenticated Oauth client back

Source

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

Source

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

Source

pub fn load_client_id_from_env() -> Result<String, OauthError>

Load the MAL_CLIENT_ID environment variable

Source

pub fn load_client_secret_from_env() -> Result<String, OauthError>

Load the MAL_CLIENT_SECRET environment variable

Source

pub fn load_redirect_url_from_env() -> Result<String, OauthError>

Load the MAL_REDIRECT_URL environment variable

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<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

Source

pub async fn refresh(self) -> Result<Self, OauthError>

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> Freeze for OauthClient<State>

§

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.

Source§

impl<T> Instrument for T

Source§

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

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

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

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,