@smbcloud / cli / commits / 8c3a460

wip

Seto committed Dec 12, 2025 at 15:19 UTC 8c3a460da953217acb7b4eefe8172bd5ed51e678
8 files changed +58 -11
.gitignore
+4 -1
@@ -1,2 +1,5 @@
1 /target
2 -*.log
\ No newline at end of file
2 +*.log
3 +
4 +# Editor
5 +.zed
Cargo.lock
+13 -1
@@ -1599,7 +1599,7 @@ dependencies = [
1599 "once_cell",
1600 "socket2",
1601 "tracing",
1602 - "windows-sys 0.52.0",
1602 + "windows-sys 0.60.2",
1603 ]
1604
1605 [[package]]
@@ -2134,6 +2134,7 @@ dependencies = [
2134 "smbcloud-model",
2135 "smbcloud-network",
2136 "smbcloud-networking",
2137 + "uuid",
2138 ]
2139
2140 [[package]]
@@ -2911,6 +2912,17 @@ version = "0.2.2"
2912 source = "registry+https://github.com/rust-lang/crates.io-index"
2913 checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
2914
2915 +[[package]]
2916 +name = "uuid"
2917 +version = "1.19.0"
2918 +source = "registry+https://github.com/rust-lang/crates.io-index"
2919 +checksum = "e2e054861b4bd027cd373e18e8d8d8e6548085000e41290d95ce0c373a654b4a"
2920 +dependencies = [
2921 + "getrandom 0.3.4",
2922 + "js-sys",
2923 + "wasm-bindgen",
2924 +]
2925 +
2926 [[package]]
2927 name = "valuable"
2928 version = "0.1.1"
crates/smbcloud-model/src/oauth.rs
+2 -2
@@ -17,8 +17,8 @@ pub struct TokenResponse {
17 #[derive(Serialize, Deserialize, Debug, Clone)]
18 #[tsync]
19 pub struct OauthRedirect {
20 - pub code: String,
21 - pub scope: String,
20 + pub code: Option<String>,
21 + pub scope: Option<String>,
22 pub authuser: i32,
23 pub prompt: String,
24 }
crates/smbcloud-networking-account/Cargo.toml
+2 -1
@@ -19,9 +19,10 @@ readme = "README.md"
19
20 [dependencies]
21 log = { workspace = true }
22 -reqwest = { workspace = true, features = ["json", "rustls-tls-native-roots"] }
22 openssl = { version = "0.10", features = ["vendored"] }
23 +reqwest = { workspace = true, features = ["json", "rustls-tls-native-roots"] }
24 serde_json = { workspace = true }
25 smbcloud-model = { workspace = true }
26 smbcloud-network = { workspace = true }
27 smbcloud-networking = { workspace = true }
28 +uuid = { version = "1", features = ["v4"] }
crates/smbcloud-networking-account/src/oauth/get_consent_url.rs
+24 -5
@@ -1,6 +1,25 @@
1 -pub fn get_consent_url(client_id: String, redirect_uri: String) -> String {
2 - format!(
3 - "https://accounts.google.com/o/oauth2/auth?client_id={}&redirect_uri={}&scope=email%20profile&response_type=code&access_type=offline",
4 - client_id, redirect_uri
5 - )
1 +use {crate::oauth::provider::Provider, uuid::Uuid};
2 +
3 +pub fn get_consent_url(provider: Provider) -> String {
4 + match provider {
5 + Provider::Google {
6 + client_id,
7 + redirect_uri,
8 + } => format!(
9 + "https://accounts.google.com/o/oauth2/auth?client_id={}&redirect_uri={}&scope=email%20profile&response_type=code&access_type=offline",
10 + client_id, redirect_uri
11 + ),
12 + Provider::Apple {
13 + client_id,
14 + redirect_uri,
15 + state,
16 + } => {
17 + let state_param = state.unwrap_or_else(|| Uuid::new_v4().to_string());
18 +
19 + format!(
20 + "https://appleid.apple.com/auth/authorize?client_id={}&redirect_uri={}&response_type=code&scope=email%20name&response_mode=form_post&state={}",
21 + client_id, redirect_uri, state_param
22 + )
23 + }
24 + }
25 }
crates/smbcloud-networking-account/src/oauth/get_token.rs
+1 -1
@@ -15,7 +15,7 @@ pub async fn get_token(
15 client_secret: String,
16 ) -> Result<TokenResponse, ErrorResponse> {
17 let base_url = format!("https://oauth2.googleapis.com/token");
18 - debug!("Exchange code with token: {}", oauth_redirect.code);
18 + debug!("Exchange code with token: {:?}", oauth_redirect.code);
19 let paylod = json!({
20 "client_id": client_id,
21 "client_secret": client_secret,
crates/smbcloud-networking-account/src/oauth/mod.rs
+1
@@ -1,3 +1,4 @@
1 pub mod get_consent_url;
2 pub mod get_profile;
3 pub mod get_token;
4 +pub mod provider;
crates/smbcloud-networking-account/src/oauth/provider.rs new
+11
@@ -0,0 +1,11 @@
1 +pub enum Provider {
2 + Google {
3 + client_id: String,
4 + redirect_uri: String,
5 + },
6 + Apple {
7 + client_id: String,
8 + redirect_uri: String,
9 + state: Option<String>,
10 + },
11 +}