Page MenuHomePhabricator

D11951.diff
No OneTemporary

D11951.diff

diff --git a/services/identity/src/client_service.rs b/services/identity/src/client_service.rs
--- a/services/identity/src/client_service.rs
+++ b/services/identity/src/client_service.rs
@@ -704,9 +704,9 @@
let nonce = challenge_response.verify_and_get_nonce(&device_id)?;
self.verify_and_remove_nonce(&nonce).await?;
- let user_identifier = self
+ let user_identity = self
.client
- .get_user_identifier(&user_id)
+ .get_user_identity(&user_id)
.await
.map_err(handle_db_error)?
.ok_or_else(|| tonic::Status::not_found("user not found"))?;
@@ -728,11 +728,12 @@
}
let login_time = chrono::Utc::now();
+ let identifier = user_identity.identifier;
let token = AccessTokenData::with_created_time(
user_id.clone(),
device_id,
login_time,
- user_identifier.into(),
+ identifier.into(),
&mut OsRng,
);
let access_token = token.access_token.clone();
@@ -774,11 +775,11 @@
let nonce = challenge_response.verify_and_get_nonce(&device_id)?;
self.verify_and_remove_nonce(&nonce).await?;
- let (identifier_response, device_list_response) = tokio::join!(
- self.client.get_user_identifier(&user_id),
+ let (identity_response, device_list_response) = tokio::join!(
+ self.client.get_user_identity(&user_id),
self.client.get_current_device_list(&user_id)
);
- let user_identifier = identifier_response
+ let user_identity = identity_response
.map_err(handle_db_error)?
.ok_or_else(|| tonic::Status::not_found("user not found"))?;
@@ -796,11 +797,12 @@
}
let login_time = chrono::Utc::now();
+ let identifier = user_identity.identifier;
let token = AccessTokenData::with_created_time(
user_id.clone(),
device_id,
login_time,
- user_identifier.into(),
+ identifier.into(),
&mut OsRng,
);
let access_token = token.access_token.clone();
diff --git a/services/identity/src/database.rs b/services/identity/src/database.rs
--- a/services/identity/src/database.rs
+++ b/services/identity/src/database.rs
@@ -22,7 +22,7 @@
ddb_utils::EthereumIdentity, reserved_users::UserDetail, siwe::SocialProof,
};
use crate::{
- ddb_utils::{Identifier, OlmAccountType},
+ ddb_utils::{DBIdentity, OlmAccountType},
grpc_services::protos,
};
use crate::{error::Error, grpc_utils::DeviceKeysInfo};
@@ -723,15 +723,15 @@
/// Retrieves username for password users or wallet address for wallet users
/// Returns `None` if user not found
#[tracing::instrument(skip_all)]
- pub async fn get_user_identifier(
+ pub async fn get_user_identity(
&self,
user_id: &str,
- ) -> Result<Option<Identifier>, Error> {
+ ) -> Result<Option<DBIdentity>, Error> {
self
.get_item_from_users_table(user_id)
.await?
.item
- .map(Identifier::try_from)
+ .map(DBIdentity::try_from)
.transpose()
.map_err(|e| {
error!(
diff --git a/services/identity/src/ddb_utils.rs b/services/identity/src/ddb_utils.rs
--- a/services/identity/src/ddb_utils.rs
+++ b/services/identity/src/ddb_utils.rs
@@ -14,6 +14,7 @@
use crate::{
constants::{
+ USERS_TABLE_FARCASTER_ID_ATTRIBUTE_NAME,
USERS_TABLE_SOCIAL_PROOF_ATTRIBUTE_NAME, USERS_TABLE_USERNAME_ATTRIBUTE,
USERS_TABLE_WALLET_ADDRESS_ATTRIBUTE,
},
@@ -170,6 +171,11 @@
}
}
+pub struct DBIdentity {
+ pub identifier: Identifier,
+ pub farcaster_id: Option<String>,
+}
+
pub enum Identifier {
Username(String),
WalletAddress(EthereumIdentity),
@@ -180,14 +186,20 @@
pub social_proof: SocialProof,
}
-impl TryFrom<AttributeMap> for Identifier {
+impl TryFrom<AttributeMap> for DBIdentity {
type Error = crate::error::Error;
fn try_from(mut value: AttributeMap) -> Result<Self, Self::Error> {
+ let farcaster_id =
+ value.take_attr(USERS_TABLE_FARCASTER_ID_ATTRIBUTE_NAME)?;
+
let username_result = value.take_attr(USERS_TABLE_USERNAME_ATTRIBUTE);
if let Ok(username) = username_result {
- return Ok(Identifier::Username(username));
+ return Ok(DBIdentity {
+ identifier: Identifier::Username(username),
+ farcaster_id,
+ });
}
let wallet_address_result =
@@ -198,10 +210,13 @@
if let (Ok(wallet_address), Ok(social_proof)) =
(wallet_address_result, social_proof_result)
{
- Ok(Identifier::WalletAddress(EthereumIdentity {
- wallet_address,
- social_proof,
- }))
+ Ok(DBIdentity {
+ identifier: Identifier::WalletAddress(EthereumIdentity {
+ wallet_address,
+ social_proof,
+ }),
+ farcaster_id,
+ })
} else {
Err(Self::Error::MalformedItem)
}
diff --git a/services/identity/src/grpc_services/authenticated.rs b/services/identity/src/grpc_services/authenticated.rs
--- a/services/identity/src/grpc_services/authenticated.rs
+++ b/services/identity/src/grpc_services/authenticated.rs
@@ -167,7 +167,7 @@
let identifier = self
.db_client
- .get_user_identifier(user_id)
+ .get_user_identity(user_id)
.await
.map_err(handle_db_error)?
.ok_or_else(|| tonic::Status::not_found("user not found"))?;
@@ -187,7 +187,7 @@
let identifier = self
.db_client
- .get_user_identifier(&message.user_id)
+ .get_user_identity(&message.user_id)
.await
.map_err(handle_db_error)?
.ok_or_else(|| tonic::Status::not_found("user not found"))?;
@@ -620,7 +620,7 @@
let message = request.into_inner();
let identifier = self
.db_client
- .get_user_identifier(&message.user_id)
+ .get_user_identity(&message.user_id)
.await
.map_err(handle_db_error)?
.ok_or_else(|| tonic::Status::not_found("user not found"))?;
diff --git a/services/identity/src/grpc_utils.rs b/services/identity/src/grpc_utils.rs
--- a/services/identity/src/grpc_utils.rs
+++ b/services/identity/src/grpc_utils.rs
@@ -5,6 +5,7 @@
use crate::{
database::DeviceRow,
+ ddb_utils::DBIdentity,
ddb_utils::Identifier as DBIdentifier,
grpc_services::protos::{
auth::{EthereumIdentity, Identity, InboundKeyInfo, OutboundKeyInfo},
@@ -248,9 +249,9 @@
}
}
-impl From<DBIdentifier> for Identity {
- fn from(value: DBIdentifier) -> Self {
- match value {
+impl From<DBIdentity> for Identity {
+ fn from(value: DBIdentity) -> Self {
+ match value.identifier {
DBIdentifier::Username(username) => Identity {
username,
eth_identity: None,

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 30, 6:55 PM (20 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2602010
Default Alt Text
D11951.diff (6 KB)

Event Timeline