[][src]Struct modio::auth::Auth

pub struct Auth { /* fields omitted */ }

Authentication Flow interface to retrieve access tokens. See the mod.io Authentication docs for more information.

Example

use std::io::{self, Write};

use modio::{Credentials, Modio, Result};

fn prompt(prompt: &str) -> io::Result<String> {
    print!("{}", prompt);
    io::stdout().flush()?;
    let mut buffer = String::new();
    io::stdin().read_line(&mut buffer)?;
    Ok(buffer.trim().to_string())
}

#[tokio::main]
async fn main() -> Result<()> {
    let modio = Modio::new(Credentials::new("api-key"))?;

    let email = prompt("Enter email: ").expect("read email");
    modio.auth().request_code(&email).await?;

    let code = prompt("Enter security code: ").expect("read code");
    let token = modio.auth().security_code(&code).await?;

    // Consume the endpoint and create an endpoint with new credentials.
    let _modio = modio.with_credentials(token);

    Ok(())
}

Implementations

impl Auth[src]

pub async fn request_code(self, email: &str) -> Result<()>[src]

Request a security code be sent to the email of the user. [required: apikey]

pub async fn security_code(self, code: &str) -> Result<Credentials>[src]

Get the access token for a security code. [required: apikey]

pub async fn external<T>(self, auth_options: T) -> Result<Credentials> where
    T: Into<AuthOptions>, 
[src]

Authenticate via external services (Steam, GOG, itch.io, Switch, Xbox, Discord, Oculus).

See the mod.io docs for more information.

Examples

use modio::auth::SteamOptions;
let opts = SteamOptions::new("ticket");
modio.auth().external(opts).await?;

use modio::auth::GalaxyOptions;
let opts = GalaxyOptions::new("ticket").email("foobar@example.com");
modio.auth().external(opts).await?;

use modio::auth::ItchioOptions;
let opts = ItchioOptions::new("token").expired_at(now + two_weeks);
modio.auth().external(opts).await?;

Link an external account. Requires an auth token from the external platform.

See the mod.io docs for more information.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.