1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//! This will log in with the credentials provided upon compilation.
//!
//! Work only with the `oauth` feature and only personal client since public client isn't yet available
//!
//! You must edit the [`login.rs`](login.rs) file with your credentials in the login builder pattern to use this.
//!
//! # Usage
//!
//! ```
//! login
//! ```
#[cfg(feature = "oauth")]
use mangadex_api::v5::MangaDexClient;
#[cfg(feature = "oauth")]
use mangadex_api_types::{Password, Username};
#[tokio::main]
async fn main() {
#[cfg(feature = "oauth")]
if let Err(e) = run().await {
use std::process;
eprintln!("Application error: {e}");
process::exit(1);
}
#[cfg(not(feature = "oauth"))]
eprintln!("You should enable the `legacy-auth` and `legacy-account` features")
}
#[cfg(feature = "oauth")]
async fn run() -> anyhow::Result<()> {
// the old login system still work on api.mangadex.dev for now
use mangadex_api_schema::v5::oauth::ClientInfo;
let client = MangaDexClient::api_dev_client();
client
.set_client_info(&non_exhaustive::non_exhaustive!(ClientInfo {
client_secret: "YOUR CLIENT SECRET HERE".into(),
client_id: "YOUR CLIENT ID HERE".into(),
}))
.await?;
let _login_res = client
.oauth()
.login()
// You may also use an email address by replacing `username()` with `email()`.
.username(Username::parse("<YOUR_USERNAME_HERE>")?)
// The raw string prefix is used because one may have a password with characters
// Rust may try to escape or format such as `{}` or `\`.
.password(Password::parse(r#"<YOUR_PASSWORD_HERE>"#)?)
.build()?
.send()
.await?;
println!("{_login_res:#?}");
// We just clear the client info and the auth token and we're good to go.
client.clear_client_info().await?;
client.clear_auth_tokens().await?;
// The login and logout succeeded if the program doesn't exit prematurely.
Ok(())
}