Add registration tool
This commit is contained in:
parent
2bd746c31a
commit
888ff7dea6
2 changed files with 62 additions and 0 deletions
|
@ -2,6 +2,15 @@
|
||||||
name = "kensho"
|
name = "kensho"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
default-run = "kensho"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "kensho"
|
||||||
|
path = "src/main.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "register"
|
||||||
|
path = "src/bin/register.rs"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
|
53
src/bin/register.rs
Normal file
53
src/bin/register.rs
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
use megalodon::generator;
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
env_logger::init();
|
||||||
|
|
||||||
|
let Ok(url) = env::var("MASTODON_URL") else {
|
||||||
|
println!("Specify MASTODON_URL!!");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let client = generator(megalodon::SNS::Mastodon, url, None, None);
|
||||||
|
let options = megalodon::megalodon::AppInputOptions {
|
||||||
|
scopes: Some(["read".to_string()].to_vec()),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
match client.register_app("kensho".to_string(), &options).await {
|
||||||
|
Ok(app_data) => {
|
||||||
|
let client_id = app_data.client_id;
|
||||||
|
let client_secret = app_data.client_secret;
|
||||||
|
println!("Authorization URL is generated");
|
||||||
|
println!("{}", app_data.url.unwrap());
|
||||||
|
|
||||||
|
println!("Enter authorization code from website: ");
|
||||||
|
let mut code = String::new();
|
||||||
|
std::io::stdin().read_line(&mut code).ok();
|
||||||
|
|
||||||
|
match client
|
||||||
|
.fetch_access_token(
|
||||||
|
client_id,
|
||||||
|
client_secret,
|
||||||
|
code.trim().to_string(),
|
||||||
|
megalodon::default::NO_REDIRECT.to_string(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(token_data) => {
|
||||||
|
println!("access_token: {}", token_data.access_token);
|
||||||
|
if let Some(refresh) = token_data.refresh_token {
|
||||||
|
println!("refresh_token: {}", refresh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
println!("{:#?}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
println!("{:#?}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue