Skip to main content

Registered

Struct Registered 

Source
pub struct Registered { /* private fields */ }
Expand description

Represents the state of the auth flow when the app has been registered but the user is not authenticated

Implementations§

Source§

impl Registered

Source

pub fn from_parts( base: &str, client_id: &str, client_secret: &str, redirect: &str, scopes: Scopes, force_login: bool, ) -> Registered

Skip having to retrieve the client id and secret from the server by creating a Registered struct directly

// Example

use mastodon_async::{prelude::*, registration::Registered};

tokio_test::block_on(async {
    let registration = Registered::from_parts(
        "https://example.com",
        "the-client-id",
        "the-client-secret",
        "https://example.com/redirect",
        Scopes::read_all(),
        false,
    );
    let url = registration.authorize_url().unwrap();
    // Here you now need to open the url in the browser
    // And handle a the redirect url coming back with the code.
    let code = String::from("RETURNED_FROM_BROWSER");
    let mastodon = registration.complete(&code).await.unwrap();

    println!("{:?}", mastodon.get_home_timeline().await.unwrap().initial_items);
});
Source§

impl Registered

Source

pub fn into_parts(self) -> (String, String, String, String, Scopes, bool)

Returns the parts of the Registered struct that can be used to recreate another Registered struct

// Example

use mastodon_async::{prelude::*, registration::Registered};

let orig_base = "https://example.social";
let orig_client_id = "some-client_id";
let orig_client_secret = "some-client-secret";
let orig_redirect = "https://example.social/redirect";
let orig_scopes = Scopes::all();
let orig_force_login = false;

let registered = Registered::from_parts(
    orig_base,
    orig_client_id,
    orig_client_secret,
    orig_redirect,
    orig_scopes.clone(),
    orig_force_login,
);

let (base, client_id, client_secret, redirect, scopes, force_login) = registered.into_parts();

assert_eq!(orig_base, &base);
assert_eq!(orig_client_id, &client_id);
assert_eq!(orig_client_secret, &client_secret);
assert_eq!(orig_redirect, &redirect);
assert_eq!(orig_scopes, scopes);
assert_eq!(orig_force_login, force_login);
Source

pub fn authorize_url(&self) -> Result<String>

Returns the full url needed for authorization. This needs to be opened in a browser.

Source

pub async fn complete<C>(&self, code: C) -> Result<Mastodon>
where C: AsRef<str>,

Create an access token from the client id, client secret, and code provided by the authorization url.

Trait Implementations§

Source§

impl Clone for Registered

Source§

fn clone(&self) -> Registered

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Registered

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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