Skip to content
This repository was archived by the owner on Jul 6, 2024. It is now read-only.

Commit 5e5f26f

Browse files
committed
feat: Inherit authentication from existing client
Allow `ClientBuilder` to create new clients which share the existing authentication session from another clients.
1 parent 3827591 commit 5e5f26f

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "proton-api-rs"
33
authors = ["Leander Beernaert <lbb-dev@pm.me>"]
4-
version = "0.4.0"
4+
version = "0.5.0"
55
edition = "2021"
66
license = "AGPL-3.0-only"
77
description = "Unofficial implemention of proton REST API in rust"

src/client/client_builder.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,16 @@ impl ClientBuilder {
216216
Ok(Client { http_client, user })
217217
}
218218

219+
/// Creates a new client which inherits the authentication state from another client.
220+
pub fn with_client_auth(self, client: &Client) -> Result<Client, RequestError> {
221+
let http_client = self.0.build()?;
222+
223+
Ok(Client {
224+
http_client,
225+
user: client.user.clone(),
226+
})
227+
}
228+
219229
/// Check connectivity
220230
pub async fn ping(&self) -> Result<(), RequestError> {
221231
let http_client = self.0.clone().build()?;

src/client/types/auth.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl<'a> FIDO2Auth<'a> {
129129
}
130130

131131
#[doc(hidden)]
132-
#[derive(Debug)]
132+
#[derive(Debug, Clone)]
133133
pub struct UserAuth {
134134
pub uid: Secret<UserUid>,
135135
pub access_token: SecretString,

src/domain/user.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ impl secrecy::Zeroize for UserUid {
1818
}
1919
}
2020

21+
impl secrecy::CloneableSecret for UserUid {}
22+
2123
impl secrecy::DebugSecret for UserUid {}
2224

2325
impl UserUid {

0 commit comments

Comments
 (0)