pub struct Auth { /* private fields */ }
Expand description
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§
source§impl Auth
impl Auth
sourcepub async fn terms(self) -> Result<Terms>
pub async fn terms(self) -> Result<Terms>
Get text and links for user agreement and consent prior to authentication. [required: apikey]
See the mod.io docs for more information.
sourcepub async fn request_code(self, email: &str) -> Result<()>
pub async fn request_code(self, email: &str) -> Result<()>
Request a security code be sent to the email of the user. [required: apikey]
sourcepub async fn security_code(self, code: &str) -> Result<Credentials>
pub async fn security_code(self, code: &str) -> Result<Credentials>
Get the access token for a security code. [required: apikey]
sourcepub async fn external<T>(self, auth_options: T) -> Result<Credentials>where
T: Into<AuthOptions>,
pub async fn external<T>(self, auth_options: T) -> Result<Credentials>where
T: Into<AuthOptions>,
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Auth
impl !RefUnwindSafe for Auth
impl Send for Auth
impl Sync for Auth
impl Unpin for Auth
impl !UnwindSafe for Auth
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more