add generate-code-only

This commit is contained in:
2022-01-14 08:17:45 +08:00
parent af5e1f33c4
commit a3ccde7694

View File

@@ -1,6 +1,7 @@
use std::collections::HashMap;
use std::env;
use std::process::exit;
use std::str::FromStr;
use std::time::Duration;
use clap::{App, Arg};
@@ -31,6 +32,8 @@ async fn main() -> XResult<()> {
.arg(Arg::new("proxy").short('p').long("proxy").takes_value(true).help("Proxy"))
.arg(Arg::new("hide-qr").long("hide-qr").help("Hide QR"))
.arg(Arg::new("skip-certificate-check").short('k').long("skip-certificate-check").help("Skip certificate check"))
.arg(Arg::new("generate-code-only").short('G').long("generate-code-only").help("Generate code only"))
.arg(Arg::new("generate-code-count").short('C').long("generate-code-count").takes_value(true).help("Generate code count"))
.arg(Arg::new("config").short('c').long("config").takes_value(true).help("Config file"))
.get_matches();
@@ -83,6 +86,24 @@ async fn main() -> XResult<()> {
information!("token_endpoint: {}", &token_endpoint);
information!("userinfo_endpoint: {}", &userinfo_endpoint);
let generate_code_only = matches.is_present("generate-code-only");
if generate_code_only {
let generate_count_count = i32::from_str(matches.value_of("generate-code-count").unwrap_or("2")).unwrap_or(2);
for i in 0..generate_count_count {
debugging!("Get {} #{}", device_authorization_endpoint, i);
let mut params = HashMap::new();
params.insert("client_id", &openid_client_configuration.client_id);
params.insert("scope", &openid_client_configuration.scope);
let device_authorization_result = opt_result!(client.post(&device_authorization_endpoint)
.form(&params).send().await, "Get device authorization: {}, failed: {}", device_authorization_endpoint);
let device_authorization = opt_result!(
device_authorization_result.json::<DeviceAuthorizationResponse>().await, "Parse device authorization failed: {}");
success!("[{}] {}", i, device_authorization.get_complete_url());
}
return Ok(());
}
// xh POST https://oauth2.googleapis.com/device/code
// client_id==364023986785-o5mqsqd1ej2d1vmvcqai108b7m7v7vc9.apps.googleusercontent.com scope=openid
//{