agentlink_sdk/services/
auth_service.rs1use std::sync::Arc;
4
5use crate::error::SdkResult;
6use crate::http::HttpClient;
7use crate::protocols::auth::{
8 CheckLinkIDResponse, LoginRequest, LoginResponse, SendCodeRequest, SendCodeResponse,
9 SetLinkIDRequest, SetLinkIDResponse,
10};
11
12pub struct AuthService {
14 http: Arc<HttpClient>,
15}
16
17impl AuthService {
18 pub fn new(http: Arc<HttpClient>) -> Self {
20 Self { http }
21 }
22
23 pub async fn login_with_email_code(&self, email: &str, code: &str) -> SdkResult<LoginResponse> {
32 let request = LoginRequest {
33 identifier: email.to_string(),
34 code: code.to_string(),
35 };
36 self.http.post("/auth/login/email-code", &request).await
37 }
38
39 pub async fn send_verification_code(&self, email: &str) -> SdkResult<SendCodeResponse> {
48 let request = SendCodeRequest {
49 code_type: "email".to_string(),
50 target: email.to_string(),
51 };
52 self.http.post("/auth/send-code", &request).await
53 }
54
55 pub async fn check_linkid(&self, linkid: &str) -> SdkResult<CheckLinkIDResponse> {
63 let path = format!("/auth/linkid/check?linkid={}", linkid);
64 self.http.get(&path).await
65 }
66
67 pub async fn set_linkid(&self, linkid: &str) -> SdkResult<SetLinkIDResponse> {
75 let request = SetLinkIDRequest {
76 linkid: linkid.to_string(),
77 };
78 self.http.post("/auth/linkid/set", &request).await
79 }
80}
81
82