1use std::{
2 env,
3 io::{BufReader, Read},
4 net::TcpStream,
5 sync::{Arc, Mutex},
6};
7
8use dotenv::dotenv;
9use http_scrap::Response;
10use rusty_oauth::{
11 scope::scope::{handle_scope, Scope},
12 Client, ClientId, ClientProviderUrl, ClientSecret,
13};
14
15pub fn google_outh(stream: &Arc<Mutex<TcpStream>>, login: &str) {
16 dotenv().ok();
17 let mut stream = stream.lock().unwrap();
22 let mut buffer = [0; 1024];
31 stream.read(&mut buffer);
32
33 let respone = String::from_utf8_lossy(&buffer);
34
35 let client_id =
41 ClientId::new("920623140590-gn10hikrt3e6b3pagil2pp1rs7tm8fub.apps.googleusercontent.com")
42 .unwrap();
43 let client_secret = ClientSecret::new("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").unwrap();
44
45 let client_url = ClientProviderUrl::new(rusty_oauth::Providers::GOOGLE);
46
47 let profile = Scope::Google(rusty_oauth::scope::google::GoogleScope::UserScope(
48 rusty_oauth::scope::google::UserScope::Profile,
49 ));
50 let email = Scope::Google(rusty_oauth::scope::google::GoogleScope::UserScope(
51 rusty_oauth::scope::google::UserScope::Email,
52 ));
53
54 let scope = handle_scope(&[profile, email]);
55 let mut client = Client::new(
56 &client_id,
57 &client_secret,
58 &client_url,
59 scope,
60 None,
61 None,
62 rusty_oauth::client::redirect_url::RedirectUrl::Google,
63 );
64 let response = Response::new(&respone);
65 let path = response.path();
66 println!("eertyui {}", path);
67
68 if path.starts_with(login) {
69 println!("{}", login);
70 client.build(&stream);
71 }
72 if path.starts_with("/api/auth") {
73 let token = client.client_token(path, &stream, "/").unwrap();
74 match token {
75 rusty_oauth::client::decode::decode::Token::Google(token) => {
76 println!("{:?}", token.email)
77 }
78 rusty_oauth::client::decode::decode::Token::Github(_) => {}
79 }
80 }
81}