Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3377158
D12303.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D12303.diff
View Options
diff --git a/services/identity/src/http/handlers.rs b/services/identity/src/http/handlers.rs
new file mode 100644
--- /dev/null
+++ b/services/identity/src/http/handlers.rs
@@ -0,0 +1,50 @@
+use super::{
+ errors::{create_error_response, http400},
+ ErrorResponse, HttpRequest,
+};
+use comm_lib::auth::UserIdentity;
+use hyper::header::AUTHORIZATION;
+use hyper::StatusCode;
+use tracing::error;
+
+#[tracing::instrument(skip_all)]
+async fn verify_csat(
+ req: &HttpRequest,
+ db_client: &crate::DatabaseClient,
+) -> Result<(), ErrorResponse> {
+ let Some(auth_header) = req.headers().get(AUTHORIZATION) else {
+ return Err(create_error_response(
+ StatusCode::UNAUTHORIZED,
+ "missing Authorization header",
+ ));
+ };
+
+ let bearer_token = auth_header
+ .to_str()
+ .map_err(|_| http400("malformed Authorization header"))?
+ .strip_prefix("Bearer ")
+ .ok_or_else(|| http400("malformed Authorization header"))?;
+
+ let UserIdentity {
+ user_id,
+ device_id,
+ access_token,
+ } = bearer_token
+ .parse()
+ .map_err(|_| http400("malformed Authorization header"))?;
+
+ let result = db_client
+ .verify_access_token(user_id, device_id, access_token)
+ .await;
+ match result {
+ Ok(true) => Ok(()),
+ Ok(false) => Err(create_error_response(
+ StatusCode::FORBIDDEN,
+ "invalid credentials",
+ )),
+ Err(err) => {
+ error!("CSAT verification error: {err:?}");
+ Err(err.into())
+ }
+ }
+}
diff --git a/services/identity/src/http/mod.rs b/services/identity/src/http/mod.rs
--- a/services/identity/src/http/mod.rs
+++ b/services/identity/src/http/mod.rs
@@ -1,6 +1,7 @@
use hyper::{Body, Request, Response};
mod errors;
+mod handlers;
type HttpRequest = Request<Body>;
type HttpResponse = Response<Body>;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 28, 4:10 AM (20 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2592715
Default Alt Text
D12303.diff (1 KB)
Attached To
Mode
D12303: [identity] Add HTTP function to verify CSAT
Attached
Detach File
Event Timeline
Log In to Comment