Repository: juspay/hyperswitch
File: crates/router/src/core/user.rs (Rust)

Code before:
    )
    .await
    .map_err(|e| {
        let message = e.current_context().error_message();
        e.change_context(UserErrors::ErrorCloningConnector(message))
    })
    .attach_printable("Failed to create cloned connector")
}

#[cfg(feature = "v1")]
pub async fn issue_embedded_token(
    state: SessionState,
    authentication_data: auth::AuthenticationData,
) -> UserResponse<user_api::IssueEmbeddedTokenResponse> {
    let profile_id = authentication_data
        .profile
        .ok_or(UserErrors::InvalidEmbeddedOperation(
            "No business profile ID provided".to_string(),
        ))
        .attach_printable("No profile_id provided in headers for embedded token")?
        .get_id()
        .clone();
    state
        .store
        .find_business_profile_by_merchant_id_profile_id(
            &authentication_data.platform.get_processor().get_key_store(),
            authentication_data
                .platform
                .get_processor()
                .get_account()
                .get_id(),
            &profile_id,
        )
        .await
        .map_err(|e| {
            if e.current_context().is_db_not_found() {
                e.change_context(UserErrors::InvalidEmbeddedOperation(
                    "Invalid business profile ID".to_string(),
                ))
                .attach_printable("Invalid profile id")
            } else {
                e.change_context(UserErrors::InternalServerError)
            }
        })?;
    auth::embedded::EmbeddedToken::new_token(
        state.tenant.tenant_id,
        authentication_data
            .platform
            .get_processor()
            .get_account()
            .get_org_id()

Review comment (security):
`get_key_store()` already returns &MerchantKeyStore
```suggestion
            authentication_data.platform.get_processor().get_key_store(),
```

Code after:
    )
    .await
    .map_err(|e| {
        let message = e.current_context().error_message();
        e.change_context(UserErrors::ErrorCloningConnector(message))
    })
    .attach_printable("Failed to create cloned connector")
}

#[cfg(feature = "v1")]
pub async fn issue_embedded_token(
    state: SessionState,
    processor: domain::Processor,
    business_profile: Option<domain::Profile>,
) -> UserResponse<user_api::IssueEmbeddedTokenResponse> {
    let profile_id = business_profile
        .ok_or(UserErrors::InvalidEmbeddedOperation(
            "No business profile ID provided".to_string(),
        ))
        .attach_printable("No profile_id provided in headers for embedded token")?
        .get_id()
        .clone();
    state
        .store
        .find_business_profile_by_merchant_id_profile_id(
            processor.get_key_store(),
            processor.get_account().get_id(),
            &profile_id,
        )
        .await
        .to_not_found_response(UserErrors::InvalidEmbeddedOperation(
            "Invalid business profile ID".to_string(),
        ))?;
    auth::embedded::EmbeddedToken::new_token(
        state.tenant.tenant_id,
        processor.get_account().get_org_id().clone(),
        processor.get_account().get_id().clone(),
        profile_id,
        &state.conf,
    )
    .await
    .map(|token| {
        ApplicationResponse::Json(user_api::IssueEmbeddedTokenResponse {
            token: token.into(),
        })
    })
}

#[cfg(feature = "v1")]
pub async fn embedded_token_info(
    _state: SessionState,