mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 12:06:56 +08:00
feat(users): Send profile_id in JWT and user_info APIs (#5817)
This commit is contained in:
@ -108,13 +108,25 @@ pub async fn generate_jwt_auth_token_without_profile(
|
||||
Ok(Secret::new(token))
|
||||
}
|
||||
|
||||
pub async fn generate_jwt_auth_token_with_attributes_without_profile(
|
||||
state: &SessionState,
|
||||
user_id: String,
|
||||
merchant_id: id_type::MerchantId,
|
||||
org_id: id_type::OrganizationId,
|
||||
role_id: String,
|
||||
) -> UserResult<Secret<String>> {
|
||||
let token =
|
||||
AuthToken::new_token(user_id, merchant_id, role_id, &state.conf, org_id, None).await?;
|
||||
Ok(Secret::new(token))
|
||||
}
|
||||
|
||||
pub async fn generate_jwt_auth_token_with_attributes(
|
||||
state: &SessionState,
|
||||
user_id: String,
|
||||
merchant_id: id_type::MerchantId,
|
||||
org_id: id_type::OrganizationId,
|
||||
role_id: String,
|
||||
profile_id: Option<id_type::ProfileId>,
|
||||
profile_id: id_type::ProfileId,
|
||||
) -> UserResult<Secret<String>> {
|
||||
let token = AuthToken::new_token(
|
||||
user_id,
|
||||
@ -122,7 +134,7 @@ pub async fn generate_jwt_auth_token_with_attributes(
|
||||
role_id,
|
||||
&state.conf,
|
||||
org_id,
|
||||
profile_id,
|
||||
Some(profile_id),
|
||||
)
|
||||
.await?;
|
||||
Ok(Secret::new(token))
|
||||
|
||||
@ -358,3 +358,42 @@ pub async fn get_lineage_for_user_id_and_entity_for_accepting_invite(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_single_merchant_id_and_profile_id(
|
||||
state: &SessionState,
|
||||
user_role: &UserRole,
|
||||
) -> UserResult<(id_type::MerchantId, id_type::ProfileId)> {
|
||||
let merchant_id = get_single_merchant_id(state, user_role).await?;
|
||||
let (_, entity_type) = user_role
|
||||
.get_entity_id_and_type()
|
||||
.ok_or(UserErrors::InternalServerError)?;
|
||||
let profile_id = match entity_type {
|
||||
EntityType::Organization | EntityType::Merchant | EntityType::Internal => {
|
||||
let key_store = state
|
||||
.store
|
||||
.get_merchant_key_store_by_merchant_id(
|
||||
&state.into(),
|
||||
&merchant_id,
|
||||
&state.store.get_master_key().to_vec().into(),
|
||||
)
|
||||
.await
|
||||
.change_context(UserErrors::InternalServerError)?;
|
||||
|
||||
state
|
||||
.store
|
||||
.list_business_profile_by_merchant_id(&state.into(), &key_store, &merchant_id)
|
||||
.await
|
||||
.change_context(UserErrors::InternalServerError)?
|
||||
.pop()
|
||||
.ok_or(UserErrors::InternalServerError)?
|
||||
.get_id()
|
||||
.to_owned()
|
||||
}
|
||||
EntityType::Profile => user_role
|
||||
.profile_id
|
||||
.clone()
|
||||
.ok_or(UserErrors::InternalServerError)?,
|
||||
};
|
||||
|
||||
Ok((merchant_id, profile_id))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user