Changeset View
Changeset View
Standalone View
Standalone View
services/identity/src/grpc_services/authenticated.rs
Show All 18 Lines | use super::protos::auth::{ | ||||
GetDeviceListRequest, GetDeviceListResponse, Identity, InboundKeyInfo, | GetDeviceListRequest, GetDeviceListResponse, Identity, InboundKeyInfo, | ||||
InboundKeysForUserRequest, InboundKeysForUserResponse, KeyserverKeysResponse, | InboundKeysForUserRequest, InboundKeysForUserResponse, KeyserverKeysResponse, | ||||
LinkFarcasterAccountRequest, OutboundKeyInfo, OutboundKeysForUserRequest, | LinkFarcasterAccountRequest, OutboundKeyInfo, OutboundKeysForUserRequest, | ||||
OutboundKeysForUserResponse, RefreshUserPrekeysRequest, | OutboundKeysForUserResponse, RefreshUserPrekeysRequest, | ||||
UpdateDeviceListRequest, UpdateUserPasswordFinishRequest, | UpdateDeviceListRequest, UpdateUserPasswordFinishRequest, | ||||
UpdateUserPasswordStartRequest, UpdateUserPasswordStartResponse, | UpdateUserPasswordStartRequest, UpdateUserPasswordStartResponse, | ||||
UploadOneTimeKeysRequest, | UploadOneTimeKeysRequest, | ||||
}; | }; | ||||
use super::protos::auth::{UserIdentityRequest, UserIdentityResponse}; | |||||
use super::protos::unauth::Empty; | use super::protos::unauth::Empty; | ||||
#[derive(derive_more::Constructor)] | #[derive(derive_more::Constructor)] | ||||
pub struct AuthenticatedService { | pub struct AuthenticatedService { | ||||
db_client: DatabaseClient, | db_client: DatabaseClient, | ||||
} | } | ||||
fn get_auth_info(req: &Request<()>) -> Option<(String, String, String)> { | fn get_auth_info(req: &Request<()>) -> Option<(String, String, String)> { | ||||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | let transformed_devices = devices_map | ||||
.into_iter() | .into_iter() | ||||
.map(|(key, device_info)| (key, InboundKeyInfo::from(device_info))) | .map(|(key, device_info)| (key, InboundKeyInfo::from(device_info))) | ||||
.collect::<HashMap<_, _>>(); | .collect::<HashMap<_, _>>(); | ||||
let identifier = self | let identifier = self | ||||
.db_client | .db_client | ||||
.get_user_identifier(user_id) | .get_user_identifier(user_id) | ||||
.await | .await | ||||
.map_err(handle_db_error)?; | .map_err(handle_db_error)? | ||||
.ok_or_else(|| tonic::Status::not_found("user not found"))?; | |||||
let identity_info = IdentityInfo::try_from(identifier)?; | let identity_info = IdentityInfo::try_from(identifier)?; | ||||
Ok(tonic::Response::new(InboundKeysForUserResponse { | Ok(tonic::Response::new(InboundKeysForUserResponse { | ||||
devices: transformed_devices, | devices: transformed_devices, | ||||
identity: Some(Identity { | identity: Some(Identity { | ||||
identity_info: Some(identity_info), | identity_info: Some(identity_info), | ||||
}), | }), | ||||
Show All 14 Lines | let keyserver_info = self | ||||
.await | .await | ||||
.map_err(handle_db_error)? | .map_err(handle_db_error)? | ||||
.map(OutboundKeyInfo::from); | .map(OutboundKeyInfo::from); | ||||
let identifier = self | let identifier = self | ||||
.db_client | .db_client | ||||
.get_user_identifier(&message.user_id) | .get_user_identifier(&message.user_id) | ||||
.await | .await | ||||
.map_err(handle_db_error)?; | .map_err(handle_db_error)? | ||||
.ok_or_else(|| tonic::Status::not_found("user not found"))?; | |||||
let identity_info = IdentityInfo::try_from(identifier)?; | let identity_info = IdentityInfo::try_from(identifier)?; | ||||
let identity = Some(Identity { | let identity = Some(Identity { | ||||
identity_info: Some(identity_info), | identity_info: Some(identity_info), | ||||
}); | }); | ||||
let response = Response::new(KeyserverKeysResponse { | let response = Response::new(KeyserverKeysResponse { | ||||
▲ Show 20 Lines • Show All 236 Lines • ▼ Show 20 Lines | self | ||||
.db_client | .db_client | ||||
.remove_farcaster_id(user_id) | .remove_farcaster_id(user_id) | ||||
.await | .await | ||||
.map_err(handle_db_error)?; | .map_err(handle_db_error)?; | ||||
let response = Empty {}; | let response = Empty {}; | ||||
Ok(Response::new(response)) | Ok(Response::new(response)) | ||||
} | } | ||||
async fn find_user_identity( | |||||
&self, | |||||
request: tonic::Request<UserIdentityRequest>, | |||||
) -> Result<Response<UserIdentityResponse>, tonic::Status> { | |||||
use identity::IdentityInfo; | |||||
let message = request.into_inner(); | |||||
let identifier = self | |||||
.db_client | |||||
.get_user_identifier(&message.user_id) | |||||
.await | |||||
.map_err(handle_db_error)? | |||||
.ok_or_else(|| tonic::Status::not_found("user not found"))?; | |||||
let identity_info = IdentityInfo::try_from(identifier)?; | |||||
let identity = Some(Identity { | |||||
identity_info: Some(identity_info), | |||||
}); | |||||
let response = Response::new(UserIdentityResponse { identity }); | |||||
return Ok(response); | |||||
} | |||||
} | } | ||||
// raw device list that can be serialized to JSON (and then signed in the future) | // raw device list that can be serialized to JSON (and then signed in the future) | ||||
#[derive(serde::Serialize, serde::Deserialize)] | #[derive(serde::Serialize, serde::Deserialize)] | ||||
struct RawDeviceList { | struct RawDeviceList { | ||||
devices: Vec<String>, | devices: Vec<String>, | ||||
timestamp: i64, | timestamp: i64, | ||||
} | } | ||||
▲ Show 20 Lines • Show All 132 Lines • Show Last 20 Lines |