-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate_delegated_recovery_challenge.rs
102 lines (91 loc) · 3.15 KB
/
create_delegated_recovery_challenge.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use async_trait::async_trait;
use dfns_sdk_rs::{
DfnsApiClient, DfnsBaseApiOptions, DfnsError,
api::auth::types::{
CreateDelegatedRecoveryChallengeRequest, CreateDelegatedRecoveryChallengeRequestBody,
},
signer::{
CredentialSigner, FirstFactorAssertion, FirstFactorAssertionKind, UserActionChallenge,
},
};
use std::sync::Arc;
struct ExampleSigner {
cred_id: String,
signature: String,
}
impl ExampleSigner {
fn new(cred_id: String, signature: String) -> Self {
Self { cred_id, signature }
}
}
#[async_trait]
impl CredentialSigner for ExampleSigner {
async fn sign(
&self,
_challenge: UserActionChallenge,
) -> Result<FirstFactorAssertion, DfnsError> {
Ok(FirstFactorAssertion {
credential_assertion: None,
kind: FirstFactorAssertionKind::Key,
password: Some(self.signature.clone()),
})
}
}
#[tokio::main]
async fn main() {
let signer = Arc::new(ExampleSigner::new(
"example-cred-id".to_string(),
"example-signature".to_string(),
));
let base_options = DfnsBaseApiOptions {
app_id: "your-app-id".to_string(),
auth_token: Some("your-auth-token".to_string()),
base_url: Some("https://api.dfns.ninja".to_string()),
app_secret: None,
};
let client = DfnsApiClient::new(base_options, Some(signer));
let request = CreateDelegatedRecoveryChallengeRequest {
body: CreateDelegatedRecoveryChallengeRequestBody {
credential_id: "example-credential-id".to_string(),
username: "[email protected]".to_string(),
},
};
match client
.auth()
.create_delegated_recovery_challenge(request)
.await
{
Ok(response) => {
println!("Delegated recovery challenge created successfully:");
println!(
" Temporary Auth Token: {}",
response.temporary_authentication_token
);
println!(" Challenge: {}", response.challenge);
println!(" OTP URL: {}", response.otp_url);
println!(" Attestation: {:?}", response.attestation);
if let Some(rp) = response.rp {
println!("\nRelying Party Info:");
println!(" ID: {}", rp.id);
println!(" Name: {}", rp.name);
}
println!("\nSupported Credential Kinds:");
println!(
" First Factor: {:?}",
response.supported_credential_kinds.first_factor
);
println!(
" Second Factor: {:?}",
response.supported_credential_kinds.second_factor
);
if !response.allowed_recovery_credentials.is_empty() {
println!("\nAllowed Recovery Credentials:");
for cred in response.allowed_recovery_credentials {
println!(" ID: {}", cred.id);
println!(" Encrypted Recovery Key: {}", cred.encrypted_recovery_key);
}
}
}
Err(e) => eprintln!("Error creating delegated recovery challenge: {:?}", e),
}
}