From 35a91a67009f39698df5ca30cbcec44b432e4407 Mon Sep 17 00:00:00 2001 From: Meng Zhang Date: Sun, 4 Feb 2024 21:31:51 -0800 Subject: [PATCH] fix: fill oauth secret to client (#1379) --- ee/tabby-webserver/src/oauth/github.rs | 5 +---- ee/tabby-webserver/src/oauth/google.rs | 4 +--- ee/tabby-webserver/src/schema/auth.rs | 3 +-- ee/tabby-webserver/src/schema/dao.rs | 4 ++-- ee/tabby-webserver/src/schema/mod.rs | 4 +--- 5 files changed, 6 insertions(+), 14 deletions(-) diff --git a/ee/tabby-webserver/src/oauth/github.rs b/ee/tabby-webserver/src/oauth/github.rs index 7fac0c2cacc2..f8b8b245ef40 100644 --- a/ee/tabby-webserver/src/oauth/github.rs +++ b/ee/tabby-webserver/src/oauth/github.rs @@ -63,10 +63,7 @@ impl GithubClient { code: String, credential: OAuthCredential, ) -> Result { - let Some(client_secret) = credential.client_secret else { - return Err(anyhow::anyhow!("Missing client secret")); - }; - + let client_secret = credential.client_secret; let params = [ ("client_id", credential.client_id.as_str()), ("client_secret", client_secret.as_str()), diff --git a/ee/tabby-webserver/src/oauth/google.rs b/ee/tabby-webserver/src/oauth/google.rs index efe1e7b5b3a0..dacf0152036e 100644 --- a/ee/tabby-webserver/src/oauth/google.rs +++ b/ee/tabby-webserver/src/oauth/google.rs @@ -64,9 +64,7 @@ impl GoogleClient { code: String, credential: OAuthCredential, ) -> Result { - let Some(client_secret) = credential.client_secret else { - return Err(anyhow::anyhow!("Missing client secret")); - }; + let client_secret = credential.client_secret; let Some(redirect_uri) = credential.redirect_uri else { return Err(anyhow::anyhow!("Missing redirect uri")); diff --git a/ee/tabby-webserver/src/schema/auth.rs b/ee/tabby-webserver/src/schema/auth.rs index 8a9a5928b24b..0bac6d9cddbf 100644 --- a/ee/tabby-webserver/src/schema/auth.rs +++ b/ee/tabby-webserver/src/schema/auth.rs @@ -335,8 +335,7 @@ pub struct OAuthCredential { pub provider: OAuthProvider, pub client_id: String, - /// Won't be passed to client side. - pub client_secret: Option, + pub client_secret: String, pub redirect_uri: Option, pub created_at: DateTime, pub updated_at: DateTime, diff --git a/ee/tabby-webserver/src/schema/dao.rs b/ee/tabby-webserver/src/schema/dao.rs index b7b0e2204d0b..35afd6500908 100644 --- a/ee/tabby-webserver/src/schema/dao.rs +++ b/ee/tabby-webserver/src/schema/dao.rs @@ -53,7 +53,7 @@ impl From for OAuthCredential { OAuthCredential { provider: OAuthProvider::Github, client_id: val.client_id, - client_secret: Some(val.client_secret), + client_secret: val.client_secret, redirect_uri: None, created_at: val.created_at, updated_at: val.updated_at, @@ -66,7 +66,7 @@ impl From for OAuthCredential { OAuthCredential { provider: OAuthProvider::Google, client_id: val.client_id, - client_secret: Some(val.client_secret), + client_secret: val.client_secret, redirect_uri: Some(val.redirect_uri), created_at: val.created_at, updated_at: val.updated_at, diff --git a/ee/tabby-webserver/src/schema/mod.rs b/ee/tabby-webserver/src/schema/mod.rs index a44ae7521c70..d8ee6f1e4c98 100644 --- a/ee/tabby-webserver/src/schema/mod.rs +++ b/ee/tabby-webserver/src/schema/mod.rs @@ -259,12 +259,10 @@ impl Query { ) -> Result> { if let Some(claims) = &ctx.claims { if claims.is_admin { - let Some(mut credentials) = - ctx.locator.auth().read_oauth_credential(provider).await? + let Some(credentials) = ctx.locator.auth().read_oauth_credential(provider).await? else { return Ok(None); }; - credentials.client_secret = None; return Ok(Some(credentials)); } }