Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3356339
D12414.id41264.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D12414.id41264.diff
View Options
diff --git a/shared/comm-lib/src/auth/types.rs b/shared/comm-lib/src/auth/types.rs
--- a/shared/comm-lib/src/auth/types.rs
+++ b/shared/comm-lib/src/auth/types.rs
@@ -38,6 +38,19 @@
}
}
+impl std::fmt::Display for AuthorizationCredential {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ match self {
+ AuthorizationCredential::UserToken(UserIdentity { user_id, .. }) => {
+ write!(f, "UserTokenCredential(user_id={})", user_id)
+ }
+ AuthorizationCredential::ServicesToken(_) => {
+ write!(f, "ServicesTokenCredential")
+ }
+ }
+ }
+}
+
#[derive(Debug, Clone, Serialize, Deserialize, derive_more::Constructor)]
pub struct ServicesAuthToken {
#[serde(rename = "servicesToken")]
diff --git a/shared/comm-lib/src/http/auth.rs b/shared/comm-lib/src/http/auth.rs
--- a/shared/comm-lib/src/http/auth.rs
+++ b/shared/comm-lib/src/http/auth.rs
@@ -1,6 +1,7 @@
use actix_web::{
body::{EitherBody, MessageBody},
dev::{Service, ServiceRequest, ServiceResponse, Transform},
+ error::{ErrorForbidden, ErrorInternalServerError},
FromRequest, HttpMessage,
};
use actix_web_httpauth::{
@@ -14,7 +15,8 @@
use tracing::debug;
use crate::auth::{
- is_csat_verification_disabled, AuthorizationCredential, UserIdentity,
+ is_csat_verification_disabled, AuthService, AuthorizationCredential,
+ UserIdentity,
};
impl FromRequest for AuthorizationCredential {
@@ -120,9 +122,25 @@
};
};
- // TODO: call identity service, for now just allow every request
- req.extensions_mut().insert(credential);
+ let auth_service = req
+ .app_data::<AuthService>()
+ .expect("FATAL: missing AuthService app data. Check HTTP server config.");
+ match auth_service.verify_auth_credential(&credential).await {
+ Ok(true) => tracing::trace!("Request is authenticated with {credential}"),
+ Ok(false) => {
+ tracing::trace!("Request is not authenticated. Token: {credential:?}");
+ // allow for invalid tokens if verification is disabled
+ if !is_csat_verification_disabled() {
+ return Err((ErrorForbidden("invalid credentials"), req));
+ }
+ }
+ Err(err) => {
+ tracing::error!("Error verifying auth credential: {err}");
+ return Err((ErrorInternalServerError("internal error"), req));
+ }
+ };
+ req.extensions_mut().insert(credential);
Ok(req)
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 6:27 PM (20 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2576956
Default Alt Text
D12414.id41264.diff (2 KB)
Attached To
Mode
D12414: [comm-lib] Verify CSAT in HTTP middleware
Attached
Detach File
Event Timeline
Log In to Comment