refactor: replace kenauth with auth module for improved consistency
ZhenYi committed
Modified app/src/main.rs app/src/main.rs +1 −1 View app/src/main.rs
@@ -57,7 +57,7 @@
5757 None => None,
5858 };
5959 let client = identity.as_ref().map(|runtime| {
60 std::sync::Arc::new(kenauth::KenAuthClient::local(
60 std::sync::Arc::new(auth::client::KenAuthClient::local(
6161 runtime.service().clone(),
6262 cfg.oauth.http_timeout_ms,
6363 ))
Modified app/Cargo.toml app/Cargo.toml +0 −1 View app/Cargo.toml
@@ -5,7 +5,6 @@
55publish = false
66
77[dependencies]
8kenauth = { workspace = true }
98serde_json = { workspace = true }
109anyhow = { workspace = true }
1110auth = { workspace = true }
Modified lib/chat/Cargo.toml lib/chat/Cargo.toml +0 −1 View lib/chat/Cargo.toml
@@ -13,7 +13,6 @@
1313queue = { workspace = true }
1414social = { workspace = true }
1515jwt = { workspace = true }
16kenauth = { workspace = true }
1716space = { workspace = true }
1817storage = { workspace = true }
1918actix-web = { workspace = true }
Modified lib/deletion/src/lib.rs lib/deletion/src/lib.rs +5 −5 View lib/deletion/src/lib.rs
@@ -1,7 +1,7 @@
11use std::time::Duration;
22
3use auth::client::error::KenAuthError;
34use export::AppState;
4use kenauth::KenAuthError;
55use kenshell::KenShellClient;
66use models::dir::{dir_overwrite_group, dir_overwrite_users, dirs};
77use models::repo::repos;
@@ -64,7 +64,7 @@
6464 DeletionError::KenShell(error.to_string())
6565}
6666
67fn client(state: &AppState) -> Result<&kenauth::KenAuthClient, DeletionError> {
67fn client(state: &AppState) -> Result<&auth::client::KenAuthClient, DeletionError> {
6868 state
6969 .kenauth
7070 .as_deref()
@@ -132,7 +132,7 @@
132132 user_id,
133133 user_id,
134134 true,
135 kenauth::proto::common::v1::PageRequest {
135 auth::protos::auth::common::v1::PageRequest {
136136 page_size: 100,
137137 page_token: String::new(),
138138 },
@@ -241,7 +241,7 @@
241241 .map_err(ken_auth)?
242242 .organization
243243 .ok_or_else(|| DeletionError::NotFound("organization not found".into()))?;
244 if organization.status != kenauth::proto::v1::OrganizationStatus::Archived as i32 {
244 if organization.status != auth::protos::auth::v1::OrganizationStatus::Archived as i32 {
245245 client
246246 .archive_organization(actor, &space_id.to_string(), reason)
247247 .await
@@ -590,7 +590,7 @@
590590 row.user_id,
591591 row.user_id,
592592 true,
593 kenauth::proto::common::v1::PageRequest {
593 auth::protos::auth::common::v1::PageRequest {
594594 page_size: 100,
595595 page_token: String::new(),
596596 },
Modified lib/deletion/Cargo.toml lib/deletion/Cargo.toml +1 −1 View lib/deletion/Cargo.toml
@@ -6,7 +6,7 @@
66[dependencies]
77config = { workspace = true }
88export = { workspace = true }
9kenauth = { workspace = true }
9auth = { workspace = true }
1010kenshell = { workspace = true }
1111models = { workspace = true }
1212sea-orm = { workspace = true }
Modified lib/export/src/health.rs lib/export/src/health.rs +2 −2 View lib/export/src/health.rs
@@ -10,7 +10,7 @@
1010struct HealthState {
1111 database: Option<Arc<AppDatabase>>,
1212 redis: AppRedis,
13 kenauth: Option<Arc<kenauth::KenAuthClient>>,
13 kenauth: Option<Arc<auth::client::KenAuthClient>>,
1414}
1515
1616async fn healthz() -> HttpResponse {
@@ -53,7 +53,7 @@
5353pub fn router_with(
5454 database: Option<Arc<AppDatabase>>,
5555 redis: AppRedis,
56 kenauth: Option<Arc<kenauth::KenAuthClient>>,
56 kenauth: Option<Arc<auth::client::KenAuthClient>>,
5757) -> Router {
5858 Router::<()>::new()
5959 .route("/healthz", get(healthz))
Modified lib/export/src/lib.rs lib/export/src/lib.rs +3 −3 View lib/export/src/lib.rs
@@ -37,8 +37,8 @@
3737 pub redis: AppRedis,
3838 pub storage: Arc<AppStorage>,
3939 pub config: AppConfig,
40 pub kenauth: Option<Arc<kenauth::KenAuthClient>>,
41 pub email_rpc: Option<Arc<kenauth::KenAuthClient>>,
40 pub kenauth: Option<Arc<auth::client::KenAuthClient>>,
41 pub email_rpc: Option<Arc<auth::client::KenAuthClient>>,
4242}
4343
4444impl AppState {
@@ -56,7 +56,7 @@
5656 pub async fn with_identity(
5757 config: AppConfig,
5858 database: Arc<AppDatabase>,
59 identity: Option<Arc<kenauth::KenAuthClient>>,
59 identity: Option<Arc<auth::client::KenAuthClient>>,
6060 ) -> Result<Self, ExportError> {
6161 let mut redis = AppRedis::connect(config.redis.clone()).await?;
6262 // 入队点遍布各业务 crate,但只有这里有配置:把开关写进句柄,让
Modified lib/export/src/oauth_client.rs lib/export/src/oauth_client.rs +1 −1 View lib/export/src/oauth_client.rs
@@ -1,6 +1,6 @@
11use std::sync::{Arc, OnceLock};
22
3use kenauth::KenAuthClient;
3use auth::client::KenAuthClient;
44
55static CLIENT: OnceLock<Arc<KenAuthClient>> = OnceLock::new();
66
Modified lib/export/src/users.rs lib/export/src/users.rs +6 −6 View lib/export/src/users.rs
@@ -1,6 +1,6 @@
11use std::collections::HashMap;
22
3use kenauth::proto::common::v1::UserPublic;
3use auth::protos::auth::common::v1::UserPublic;
44
55use crate::AppState;
66use crate::error::ExportError;
@@ -38,7 +38,7 @@
3838 .ok_or_else(|| ExportError::InvalidConfig("kenoauth is not configured".to_string()))?;
3939 match client.get_user_public(uid).await {
4040 Ok(user) => Ok(Some(user)),
41 Err(kenauth::KenAuthError::NotFound) => Ok(None),
41 Err(auth::client::error::KenAuthError::NotFound) => Ok(None),
4242 Err(error) => Err(ExportError::Connection(error.to_string())),
4343 }
4444}
@@ -52,13 +52,13 @@
5252 .as_ref()
5353 .ok_or_else(|| ExportError::InvalidConfig("kenoauth is not configured".to_string()))?;
5454 match client
55 .get_user_public_by_ref(kenauth::proto::common::v1::user_ref::Key::Email(
55 .get_user_public_by_ref(auth::protos::auth::common::v1::user_ref::Key::Email(
5656 email.to_string(),
5757 ))
5858 .await
5959 {
6060 Ok(user) => Ok(Some(user)),
61 Err(kenauth::KenAuthError::NotFound) => Ok(None),
61 Err(auth::client::error::KenAuthError::NotFound) => Ok(None),
6262 Err(error) => Err(ExportError::Connection(error.to_string())),
6363 }
6464}
@@ -72,13 +72,13 @@
7272 .as_ref()
7373 .ok_or_else(|| ExportError::InvalidConfig("kenoauth is not configured".to_string()))?;
7474 match client
75 .get_user_public_by_ref(kenauth::proto::common::v1::user_ref::Key::Username(
75 .get_user_public_by_ref(auth::protos::auth::common::v1::user_ref::Key::Username(
7676 username.to_string(),
7777 ))
7878 .await
7979 {
8080 Ok(user) => Ok(Some(user)),
81 Err(kenauth::KenAuthError::NotFound) => Ok(None),
81 Err(auth::client::error::KenAuthError::NotFound) => Ok(None),
8282 Err(error) => Err(ExportError::Connection(error.to_string())),
8383 }
8484}
Modified lib/export/Cargo.toml lib/export/Cargo.toml +1 −1 View lib/export/Cargo.toml
@@ -11,7 +11,7 @@
1111sea-orm = { workspace = true }
1212redis = { workspace = true }
1313tokio = { workspace = true, features = ["macros", "rt-multi-thread", "signal"] }
14kenauth = { workspace = true }
14auth = { workspace = true }
1515jwt = { workspace = true }
1616imaging = { workspace = true }
1717actix-web = { workspace = true }
Modified lib/issues/Cargo.toml lib/issues/Cargo.toml +0 −1 View lib/issues/Cargo.toml
@@ -13,7 +13,6 @@
1313models = { workspace = true }
1414queue = { workspace = true }
1515jwt = { workspace = true }
16kenauth = { workspace = true }
1716space = { workspace = true }
1817actix-web = { workspace = true }
1918http = { workspace = true }
Deleted lib/kenauth/src/lib.rs lib/kenauth/src/lib.rs +0 −3
@@ -1,3 +0,0 @@
1pub use auth::client::KenAuthClient;
2pub use auth::client::error::KenAuthError;
3pub use auth::protos::auth as proto;
Deleted lib/kenauth/Cargo.toml lib/kenauth/Cargo.toml +0 −7
@@ -1,7 +0,0 @@
1[package]
2name = "kenauth"
3version.workspace = true
4edition.workspace = true
5
6[dependencies]
7auth = { workspace = true }
Modified lib/space/src/services/spaces.rs lib/space/src/services/spaces.rs +1 −1 View lib/space/src/services/spaces.rs
@@ -38,7 +38,7 @@
3838}
3939
4040impl UserDto {
41 pub fn from_public(public: &kenauth::proto::common::v1::UserPublic) -> Self {
41 pub fn from_public(public: &auth::protos::auth::common::v1::UserPublic) -> Self {
4242 Self {
4343 user_id: public.user_id,
4444 username: public.username.clone(),
Modified lib/space/src/authority.rs lib/space/src/authority.rs +3 −3 View lib/space/src/authority.rs
@@ -1,5 +1,5 @@
1use auth::protos::auth as proto;
12use export::AppState;
2use kenauth::proto;
33use models::space::space_extras::{self, Entity as SpaceExtras};
44use models::space::space_member_extras::{self, Entity as MemberExtras};
55use models::space::space_members::{self, MemberStatus, MessageNotifications};
@@ -12,7 +12,7 @@
1212
1313pub const RPC_KEY: &str = "kenoauth is not configured";
1414
15pub fn client(state: &AppState) -> Result<&kenauth::KenAuthClient, SpaceError> {
15pub fn client(state: &AppState) -> Result<&auth::client::KenAuthClient, SpaceError> {
1616 state
1717 .kenauth
1818 .as_deref()
@@ -191,7 +191,7 @@
191191 {
192192 Ok(Some(member)) => member,
193193 Ok(None) => return Ok(None),
194 Err(kenauth::KenAuthError::Rejected(message))
194 Err(auth::client::error::KenAuthError::Rejected(message))
195195 if message.to_lowercase().contains("forbidden")
196196 || message.to_lowercase().contains("permission") =>
197197 {
Modified lib/space/src/errors.rs lib/space/src/errors.rs +8 −9 View lib/space/src/errors.rs
@@ -52,15 +52,15 @@
5252 }
5353}
5454
55impl From<kenauth::KenAuthError> for SpaceError {
56 fn from(error: kenauth::KenAuthError) -> Self {
55impl From<auth::client::error::KenAuthError> for SpaceError {
56 fn from(error: auth::client::error::KenAuthError) -> Self {
5757 match error {
58 kenauth::KenAuthError::NotFound => Self::NotFound,
59 kenauth::KenAuthError::Unauthenticated => Self::Unauthorized,
60 kenauth::KenAuthError::Unavailable(message) => {
58 auth::client::error::KenAuthError::NotFound => Self::NotFound,
59 auth::client::error::KenAuthError::Unauthenticated => Self::Unauthorized,
60 auth::client::error::KenAuthError::Unavailable(message) => {
6161 Self::Internal(format!("kenoauth unavailable: {message}"))
6262 }
63 kenauth::KenAuthError::Rejected(message) => {
63 auth::client::error::KenAuthError::Rejected(message) => {
6464 let lower = message.to_lowercase();
6565 if lower.contains("already") || lower.contains("taken") {
6666 Self::Conflict(message)
@@ -70,9 +70,8 @@
7070 Self::BadRequest(message)
7171 }
7272 }
73 kenauth::KenAuthError::Config(message) | kenauth::KenAuthError::Internal(message) => {
74 Self::Internal(message)
75 }
73 auth::client::error::KenAuthError::Config(message)
74 | auth::client::error::KenAuthError::Internal(message) => Self::Internal(message),
7675 }
7776 }
7877}
Modified lib/space/Cargo.toml lib/space/Cargo.toml +1 −1 View lib/space/Cargo.toml
@@ -12,7 +12,7 @@
1212imaging = { workspace = true }
1313models = { workspace = true }
1414jwt = { workspace = true }
15kenauth = { workspace = true }
15auth = { workspace = true }
1616prost-types = { workspace = true }
1717storage = { workspace = true }
1818actix-web = { workspace = true }
Modified lib/webapi/src/auth/handlers/devices.rs lib/webapi/src/auth/handlers/devices.rs +1 −1 View lib/webapi/src/auth/handlers/devices.rs
@@ -1,9 +1,9 @@
1use auth::protos::auth::common::v1::PageRequest;
12use export::http::{Query, State};
23use export::pagination::PageQuery;
34use export::rest::AppResponseData;
45use jwt::Session;
56use jwt::share::session;
6use kenauth::proto::common::v1::PageRequest;
77use serde::{Deserialize, Serialize};
88use sha2::{Digest, Sha256};
99use time::OffsetDateTime;
Modified lib/webapi/src/auth/handlers/sessions.rs lib/webapi/src/auth/handlers/sessions.rs +2 −2 View lib/webapi/src/auth/handlers/sessions.rs
@@ -1,10 +1,10 @@
1use auth::protos::auth::common::v1::{PageRequest, SessionInfo};
2use auth::protos::auth::v1::ListUserSessionsResponse;
13use export::http::{Path, Query, State};
24use export::pagination::{Page, PageQuery, paginate};
35use export::rest::{AppResponseData, NoData};
46use jwt::Session;
57use jwt::share::session;
6use kenauth::proto::common::v1::{PageRequest, SessionInfo};
7use kenauth::proto::v1::ListUserSessionsResponse;
88use serde::{Deserialize, Serialize};
99use time::OffsetDateTime;
1010use utoipa::ToSchema;
Modified lib/webapi/src/auth/handlers/two_factor.rs lib/webapi/src/auth/handlers/two_factor.rs +1 −1 View lib/webapi/src/auth/handlers/two_factor.rs
@@ -1,8 +1,8 @@
1use auth::protos::auth::common::v1::MfaStatus;
12use export::http::{HeaderMap, Json, State};
23use export::rest::{AppResponseData, NoData};
34use jwt::Session;
45use jwt::share::session;
5use kenauth::proto::common::v1::MfaStatus;
66use serde::{Deserialize, Serialize};
77use utoipa::ToSchema;
88
Modified lib/webapi/src/auth/oauth/project.rs lib/webapi/src/auth/oauth/project.rs +1 −1 View lib/webapi/src/auth/oauth/project.rs
@@ -12,7 +12,7 @@
1212/// anchors local preferences and foreign keys.
1313pub async fn upsert(
1414 service: &AuthService,
15 public: &kenauth::proto::common::v1::UserPublic,
15 public: &auth::protos::auth::common::v1::UserPublic,
1616) -> Result<user::Model, AuthError> {
1717 let db = service.db().write();
1818 let now = OffsetDateTime::now_utc();
Modified lib/webapi/src/auth/oauth/revalidate.rs lib/webapi/src/auth/oauth/revalidate.rs +2 −1 View lib/webapi/src/auth/oauth/revalidate.rs
@@ -81,7 +81,8 @@
8181 .await;
8282 Ok(next.call(request).await?.map_into_boxed_body())
8383 }
84 Err(kenauth::KenAuthError::Unauthenticated) | Err(kenauth::KenAuthError::NotFound) => {
84 Err(auth::client::error::KenAuthError::Unauthenticated)
85 | Err(auth::client::error::KenAuthError::NotFound) => {
8586 let mut response = HttpResponse::Unauthorized().json(serde_json::json!({
8687 "code": 401,
8788 "message": "session_revoked",
Modified lib/webapi/src/auth/services/profile.rs lib/webapi/src/auth/services/profile.rs +2 −2 View lib/webapi/src/auth/services/profile.rs
@@ -322,8 +322,8 @@
322322 }
323323}
324324
325fn map_kenauth(error: kenauth::KenAuthError) -> AuthError {
326 use kenauth::KenAuthError;
325fn map_kenauth(error: auth::client::error::KenAuthError) -> AuthError {
326 use auth::client::error::KenAuthError;
327327 match error {
328328 KenAuthError::NotFound => AuthError::NotFound,
329329 KenAuthError::Unauthenticated => AuthError::Unauthorized,
Modified lib/webapi/src/auth/services/users.rs lib/webapi/src/auth/services/users.rs +3 −3 View lib/webapi/src/auth/services/users.rs
@@ -1,6 +1,6 @@
11use std::collections::HashMap;
22
3use kenauth::proto::common::v1 as auth_public;
3use auth::protos::auth::common::v1 as auth_public;
44use models::users::user::{self, ProfileVisibility};
55use sea_orm::{ColumnTrait, EntityTrait, QueryFilter};
66
@@ -134,8 +134,8 @@
134134 }
135135}
136136
137fn map_kenauth(error: kenauth::KenAuthError) -> AuthError {
138 use kenauth::KenAuthError;
137fn map_kenauth(error: auth::client::error::KenAuthError) -> AuthError {
138 use auth::client::error::KenAuthError;
139139 match error {
140140 KenAuthError::NotFound => AuthError::NotFound,
141141 KenAuthError::Unauthenticated => AuthError::Unauthorized,
Modified lib/webapi/src/auth/share/rpc.rs lib/webapi/src/auth/share/rpc.rs +1 −1 View lib/webapi/src/auth/share/rpc.rs
@@ -1,8 +1,8 @@
11use std::sync::Arc;
22
3use auth::client::KenAuthClient;
34use export::AppState;
45use export::http::HeaderMap;
5use kenauth::KenAuthClient;
66use sha2::{Digest, Sha256};
77use time::OffsetDateTime;
88
Modified lib/webapi/Cargo.toml lib/webapi/Cargo.toml +0 −1 View lib/webapi/Cargo.toml
@@ -9,7 +9,6 @@
99chat = { workspace = true }
1010deletion = { workspace = true }
1111i18n = { workspace = true }
12kenauth = { workspace = true }
1312redis = { workspace = true }
1413maud = { workspace = true }
1514pulldown-cmark = { workspace = true }
Modified Cargo.lock Cargo.lock +3 −14 View Cargo.lock
@@ -1266,7 +1266,6 @@
12661266 "i18n",
12671267 "imaging",
12681268 "jwt",
1269 "kenauth",
12701269 "livekit-api",
12711270 "livekit-protocol",
12721271 "models",
@@ -1886,9 +1885,9 @@
18861885name = "deletion"
18871886version = "1.0.0"
18881887dependencies = [
1888 "auth",
18891889 "config 1.0.0",
18901890 "export",
1891 "kenauth",
18921891 "kenshell",
18931892 "models",
18941893 "sea-orm",
@@ -2390,12 +2389,12 @@
23902389version = "1.0.0"
23912390dependencies = [
23922391 "actix-web",
2392 "auth",
23932393 "bytes",
23942394 "config 1.0.0",
23952395 "http 1.5.0",
23962396 "imaging",
23972397 "jwt",
2398 "kenauth",
23992398 "models",
24002399 "opentelemetry",
24012400 "opentelemetry-http",
@@ -3639,7 +3638,6 @@
36393638 "http 0.2.12",
36403639 "i18n",
36413640 "jwt",
3642 "kenauth",
36433641 "models",
36443642 "queue",
36453643 "sea-orm",
@@ -3902,7 +3900,6 @@
39023900 "events",
39033901 "export",
39043902 "jwt",
3905 "kenauth",
39063903 "models",
39073904 "push",
39083905 "queue",
@@ -3919,13 +3916,6 @@
39193916]
39203917
39213918[[package]]
3922name = "kenauth"
3923version = "1.0.0"
3924dependencies = [
3925 "auth",
3926]
3927
3928[[package]]
39293919name = "kenshell"
39303920version = "1.0.0"
39313921dependencies = [
@@ -7303,13 +7293,13 @@
73037293dependencies = [
73047294 "actix-web",
73057295 "async-trait",
7296 "auth",
73067297 "config 1.0.0",
73077298 "deletion",
73087299 "export",
73097300 "i18n",
73107301 "imaging",
73117302 "jwt",
7312 "kenauth",
73137303 "models",
73147304 "prost-types 0.14.4",
73157305 "sea-orm",
@@ -8869,7 +8859,6 @@
88698859 "i18n",
88708860 "issues",
88718861 "jwt",
8872 "kenauth",
88738862 "maud",
88748863 "models",
88758864 "pulldown-cmark",
Modified Cargo.toml Cargo.toml +0 −1 View Cargo.toml
@@ -28,7 +28,6 @@
2828git = { path = "lib/git" }
2929i18n = { path = "lib/i18n" }
3030imaging = { path = "lib/imaging" }
31kenauth = { path = "lib/kenauth" }
3231crypt = { path = "lib/crypt" }
3332db = { path = "lib/db" }
3433email = { path = "lib/email" }
Modified Dockerfile Dockerfile +1 −1 View Dockerfile
@@ -31,7 +31,7 @@
3131# ---------------------------------------------------------------------------
3232FROM ${RUST_IMAGE} AS builder
3333
34# protoc:lib/kenauth 与 lib/kenshell 的 build.rs 都会编译 .proto。
34# protoc:lib/proto 与 lib/kenshell 的 build.rs 都会编译 .proto。
3535# libssl-dev / pkg-config:native-tls 链(reqwest 等处)需要 OpenSSL 头文件。
3636ENV PROTOC_INCLUDE=/usr/include \
3737 CARGO_TERM_COLOR=always