Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for email identity #3061

Merged
merged 33 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f2b078b
refactoring twitter helpers, extracting general web2 helpers
silva-fj Sep 3, 2024
1788243
adding dependencies to lc-identity-verification
silva-fj Sep 9, 2024
deda074
adding email module to web2
silva-fj Sep 9, 2024
7ebc4bb
setting up email_verification_store
silva-fj Sep 9, 2024
9992c1a
adding mailer interface
silva-fj Sep 9, 2024
e7554bb
renaming email code verification store
silva-fj Sep 10, 2024
3dd1d44
refatoring mailer, setting up sendgrid mailer
silva-fj Sep 10, 2024
49f32a8
adding sgx predules for http and http_req
silva-fj Sep 10, 2024
0d832fc
adding verification email template
silva-fj Sep 10, 2024
0846ac0
adding data-providers config for sendgrid
silva-fj Sep 10, 2024
28dd7db
refactoring mailer
silva-fj Sep 10, 2024
c20cb7f
implementing send_verification_email
silva-fj Sep 10, 2024
a417fdd
adding identity_requestEmailVerification to request email verification
silva-fj Sep 10, 2024
fa9b628
clean up unused imports
silva-fj Sep 11, 2024
99fdbf5
handling error in data-providers config
silva-fj Sep 11, 2024
2817af0
covering Email variant of Identity enum
silva-fj Sep 11, 2024
5d30fb5
adding validation data for email identity
silva-fj Sep 11, 2024
c2b0b32
cleaning up sendgrid_mailer
silva-fj Sep 11, 2024
3564bbb
refactoring email template to send only verification code instead of a
silva-fj Sep 11, 2024
06c870b
cleaning up data-providers config
silva-fj Sep 11, 2024
b77df08
fixing typo
silva-fj Sep 11, 2024
616816c
fixing formatting
silva-fj Sep 11, 2024
b27b572
Merge branch 'dev' into p-685-add-support-for-email-identity
silva-fj Sep 13, 2024
9b5e3b7
import types from alloc instead of std
silva-fj Sep 13, 2024
be5f465
Merge remote-tracking branch 'origin/dev' into p-685-add-support-for-…
silva-fj Sep 13, 2024
bf6e31e
updating cargo.lock
silva-fj Sep 13, 2024
1050b92
updating enclave-runtime Cargo.lock
silva-fj Sep 13, 2024
492622a
Revert "updating cargo.lock"
silva-fj Sep 13, 2024
be4cd6e
updating tee-worker's Cargo.lock
silva-fj Sep 13, 2024
e8742d7
improving errors a bit
silva-fj Sep 13, 2024
dfd494f
fixing clippy issues
silva-fj Sep 13, 2024
a70bcb1
Merge branch 'dev' into p-685-add-support-for-email-identity
silva-fj Sep 18, 2024
0b37521
Merge branch 'dev' into p-685-add-support-for-email-identity
silva-fj Sep 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 42 additions & 37 deletions tee-worker/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 15 additions & 5 deletions tee-worker/enclave-runtime/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 48 additions & 5 deletions tee-worker/enclave-runtime/src/rpc/common_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use itp_utils::{FromHexPrefixed, ToHexPrefixed};
use its_rpc_handler::direct_top_pool_api::add_top_pool_direct_rpc_methods;
use jsonrpc_core::{serde_json::json, IoHandler, Params, Value};
use lc_data_providers::DataProviderConfig;
use lc_identity_verification::web2::twitter;
use lc_identity_verification::web2::{email, twitter};
use litentry_macros::{if_development, if_development_or};
use litentry_primitives::{aes_decrypt, AesRequest, DecryptableRequest, Identity};
use log::debug;
Expand Down Expand Up @@ -418,6 +418,8 @@ pub fn add_common_api<Author, GetterExecutor, AccessShieldingKey, OcallApi, Stat
Ok(Value::String(format!("hello, {}", parsed)))
});

let twitter_client_id = data_provider_config.twitter_client_id.clone();

io_handler.add_sync_method("identity_getTwitterAuthorizeUrl", move |params: Params| {
debug!("worker_api_direct rpc was called: identity_getTwitterAuthorizeUrl");

Expand All @@ -435,10 +437,7 @@ pub fn add_common_api<Author, GetterExecutor, AccessShieldingKey, OcallApi, Stat
"Could not parse identity"
))),
};
let authorize_data = twitter::get_authorize_data(
&data_provider_config.twitter_client_id,
&redirect_url,
);
let authorize_data = twitter::get_authorize_data(&twitter_client_id, &redirect_url);
match twitter::OAuthStore::save_data(
account_id,
authorize_data.code_verifier,
Expand All @@ -460,6 +459,50 @@ pub fn add_common_api<Author, GetterExecutor, AccessShieldingKey, OcallApi, Stat
Err(_) => Ok(json!(compute_hex_encoded_return_error("Could not parse params"))),
}
});

io_handler.add_sync_method("identity_requestEmailVerification", move |params: Params| {
match params.parse::<(String, String)>() {
Ok((encoded_did, email)) => {
let account_id = match Identity::from_did(encoded_did.as_str()) {
Ok(identity) =>
if let Some(account_id) = identity.to_account_id() {
account_id
} else {
return Ok(json!(compute_hex_encoded_return_error("Invalid identity")))
},
Err(_) =>
return Ok(json!(compute_hex_encoded_return_error(
"Could not parse identity"
))),
};
let mut mailer = email::sendgrid_mailer::SendGridMailer::new(
data_provider_config.sendgrid_api_key.clone(),
data_provider_config.sendgrid_from_email.clone(),
);
let verification_code = email::generate_verification_code();

match email::VerificationCodeStore::insert(account_id, verification_code.clone()) {
Ok(_) => {
if let Err(_) =
email::send_verification_email(&mut mailer, email, verification_code)
{
return Ok(json!(compute_hex_encoded_return_error(
"Could not send verification email"
)))
}
let json_value =
RpcReturnValue::new(vec![], false, DirectRequestStatus::Ok);
Ok(json!(json_value.to_hex()))
},
Err(_) =>
return Ok(json!(compute_hex_encoded_return_error(
"Could not save verification code"
))),
}
},
Err(_) => Ok(json!(compute_hex_encoded_return_error("Could not parse params"))),
}
});
}

#[deprecated(note = "`state_executeAesGetter` should be preferred")]
Expand Down
Loading
Loading