mastodon API rust lib elefren, fixed and updated. and also all ASYNC! NB. most examples are now wrong.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
752 B

use std::io::{self, BufRead, Write};
use crate::{errors::Result, registration::Registered, Client};
/// Finishes the authentication process for the given `Registered` object,
/// using the command-line
pub async fn authenticate(registration: Registered) -> Result<Client> {
let url = registration.authorize_url()?;
let stdout = io::stdout();
let stdin = io::stdin();
let mut stdout = stdout.lock();
let mut stdin = stdin.lock();
writeln!(&mut stdout, "Click this link to authorize: {}", url)?;
write!(&mut stdout, "Paste the returned authorization code: ")?;
stdout.flush()?;
let mut input = String::new();
stdin.read_line(&mut input)?;
let code = input.trim();
registration.complete(code).await
}