Skip to content

Commit 07c244f

Browse files
authored
feat(clients): Add v2 API clients and centralize client generation (#522)
This allows the new v2 APIs of ZITADEL to be used. BREAKING CHANGE: The modules for client instantiation have changed. There is no module "with access token" or "with service account" anymore. Instead, there is a centralized `ClientBuilder` in the clients module of the api to create and configure the gRPC clients. The new builder allows configuring auth methods beforehand and then create the according client out of it.
1 parent 13aea5a commit 07c244f

File tree

4 files changed

+330
-299
lines changed

4 files changed

+330
-299
lines changed

examples/fetch_profile_with_pat.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
use zitadel::api::{
2-
clients::with_access_token::create_auth_client, zitadel::auth::v1::GetMyUserRequest,
3-
};
1+
use zitadel::api::{clients::ClientBuilder, zitadel::auth::v1::GetMyUserRequest};
42

53
#[tokio::main]
64
async fn main() -> Result<(), Box<dyn std::error::Error>> {
75
const PERSONAL_ACCESS_TOKEN: &str =
86
"dEnGhIFs3VnqcQU5D2zRSeiarB1nwH6goIKY0J8MWZbsnWcTuu1C59lW9DgCq1y096GYdXA";
97
const ZITADEL_URL: &str = "https://zitadel-libraries-l8boqa.zitadel.cloud";
108

11-
let mut client = create_auth_client(ZITADEL_URL, PERSONAL_ACCESS_TOKEN).await?;
9+
let mut client = ClientBuilder::new(ZITADEL_URL)
10+
.with_access_token(PERSONAL_ACCESS_TOKEN)
11+
.build_auth_client()
12+
.await?;
1213
let user = client.get_my_user(GetMyUserRequest {}).await?.into_inner();
1314
println!("{:#?}", user);
1415

examples/fetch_profile_with_service_account.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use zitadel::{
2-
api::{clients::with_service_account::create_auth_client, zitadel::auth::v1::GetMyUserRequest},
2+
api::{clients::ClientBuilder, zitadel::auth::v1::GetMyUserRequest},
33
credentials::{AuthenticationOptions, ServiceAccount},
44
};
55

@@ -14,15 +14,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
1414
}"#;
1515
const ZITADEL_URL: &str = "https://zitadel-libraries-l8boqa.zitadel.cloud";
1616
let service_account = ServiceAccount::load_from_json(SERVICE_ACCOUNT)?;
17-
let mut client = create_auth_client(
18-
ZITADEL_URL,
19-
&service_account,
20-
Some(AuthenticationOptions {
21-
api_access: true,
22-
..Default::default()
23-
}),
24-
)
25-
.await?;
17+
let mut client = ClientBuilder::new(ZITADEL_URL)
18+
.with_service_account(
19+
&service_account,
20+
Some(AuthenticationOptions {
21+
api_access: true,
22+
..Default::default()
23+
}),
24+
)
25+
.build_auth_client()
26+
.await?;
2627
let user = client.get_my_user(GetMyUserRequest {}).await?.into_inner();
2728
println!("{:#?}", user);
2829

0 commit comments

Comments
 (0)