From 2d1b959295e8f02591a10a7a96ddda29ffa4b765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Klocek?= Date: Sun, 12 Nov 2023 13:02:05 +0100 Subject: [PATCH] [identity] Add RPC for finding user ID Summary: [[ https://linear.app/comm/issue/ENG-4132/identity-service-rpc-to-check-if-a-username-exists | ENG-4132 ]]. Added RPC to find user ID by either username or wallet address. The API is the same as for GetOutboundKeys RPC, which will then be refactored to instead accept user ID. Test Plan: Created a test user, used BloomRPC to call the RPC with the username. It returned the user ID - confirmed with DDB. A unit test is added in the next diff. Reviewers: varun, ashoat, michal, wyilio Reviewed By: varun Subscribers: tomek, wyilio Differential Revision: https://phab.comm.dev/D9834 --- .../src/grpc_services/authenticated.rs | 29 +++++++++++++++++-- shared/protos/identity_authenticated.proto | 17 +++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/services/identity/src/grpc_services/authenticated.rs b/services/identity/src/grpc_services/authenticated.rs index 763d228a18..0b4966a2ae 100644 --- a/services/identity/src/grpc_services/authenticated.rs +++ b/services/identity/src/grpc_services/authenticated.rs @@ -1,6 +1,6 @@ use crate::{ client_service::handle_db_error, constants::request_metadata, - database::DatabaseClient, grpc_services::shared::get_value, + database::DatabaseClient, grpc_services::shared::get_value, token::AuthType, }; use tonic::{Request, Response, Status}; @@ -14,7 +14,8 @@ pub mod auth_proto { tonic::include_proto!("identity.authenticated"); } use auth_proto::{ - identity_client_service_server::IdentityClientService, KeyserverKeysResponse, + find_user_id_request, identity_client_service_server::IdentityClientService, + FindUserIdRequest, FindUserIdResponse, KeyserverKeysResponse, OutboundKeyInfo, OutboundKeysForUserRequest, RefreshUserPreKeysRequest, UploadOneTimeKeysRequest, }; @@ -169,4 +170,28 @@ impl IdentityClientService for AuthenticatedService { Ok(tonic::Response::new(Empty {})) } + + async fn find_user_id( + &self, + request: tonic::Request, + ) -> Result, tonic::Status> { + let message = request.into_inner(); + + use find_user_id_request::Identifier; + let (user_ident, auth_type) = match message.identifier { + None => { + return Err(tonic::Status::invalid_argument("no identifier provided")) + } + Some(Identifier::Username(username)) => (username, AuthType::Password), + Some(Identifier::WalletAddress(address)) => (address, AuthType::Wallet), + }; + + let user_id = self + .db_client + .get_user_id_from_user_info(user_ident, &auth_type) + .await + .map_err(handle_db_error)?; + + Ok(Response::new(FindUserIdResponse { user_id })) + } } diff --git a/shared/protos/identity_authenticated.proto b/shared/protos/identity_authenticated.proto index e74c03925b..1758f48252 100644 --- a/shared/protos/identity_authenticated.proto +++ b/shared/protos/identity_authenticated.proto @@ -23,6 +23,9 @@ service IdentityClientService { // to a user's keyserver rpc GetKeyserverKeys(OutboundKeysForUserRequest) returns (KeyserverKeysResponse) {} + + // Returns userID for given username or wallet address + rpc FindUserID(FindUserIDRequest) returns (FindUserIDResponse) {} } // Helper types @@ -62,3 +65,17 @@ message KeyserverKeysResponse { message OutboundKeysForUserRequest { string userID = 1; } + +// FindUserID + +message FindUserIDRequest { + oneof identifier { + string username = 1; + string walletAddress = 2; + } +} + +message FindUserIDResponse { + // none if user not found + optional string userID = 1; +}