Skip to content

Commit d9e3f54

Browse files
JanZachmannclaude
andcommitted
refactor: update keycloak_client to use upstream version
- Replace keycloak_client.rs with upstream/main version - Update SingleSignOnProvider trait to use async fn in trait - Change config() from method to standalone function - Update test mocks to return Result directly instead of boxed futures 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent ece90c1 commit d9e3f54

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

src/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub fn create_frontend_config_file() -> Result<()> {
9898
.context("failed to create frontend config file")?;
9999

100100
config_file
101-
.write_all(keycloak_client::KeycloakProvider::config().as_bytes())
101+
.write_all(keycloak_client::config().as_bytes())
102102
.context("failed to write frontend config file")
103103
}
104104

src/keycloak_client.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ use base64::{Engine, prelude::BASE64_STANDARD};
33
use jwt_simple::prelude::{RS256PublicKey, RSAPublicKeyLike};
44
#[cfg(feature = "mock")]
55
use mockall::automock;
6-
use reqwest::Client;
76
use serde::{Deserialize, Serialize};
8-
use trait_variant::make;
97

108
#[derive(Debug, Deserialize, Serialize, Clone)]
119
pub struct TokenClaims {
@@ -27,24 +25,29 @@ macro_rules! keycloak_url {
2725
}};
2826
}
2927

30-
#[make(Send + Sync)]
3128
#[cfg_attr(feature = "mock", automock)]
32-
pub trait SingleSignOnProvider {
29+
#[allow(async_fn_in_trait)]
30+
pub trait SingleSignOnProvider: Send + Sync {
3331
async fn verify_token(&self, token: &str) -> anyhow::Result<TokenClaims>;
3432
}
3533

36-
#[derive(Clone, Default)]
37-
pub struct KeycloakProvider;
34+
#[derive(Clone)]
35+
pub struct KeycloakProvider {
36+
client: reqwest::Client,
37+
}
3838

39-
impl KeycloakProvider {
40-
pub fn config() -> String {
41-
let keycloak_url = &keycloak_url!();
42-
format!("window.__APP_CONFIG__ = {{KEYCLOAK_URL:\"{keycloak_url}\"}};")
39+
impl Default for KeycloakProvider {
40+
fn default() -> Self {
41+
Self {
42+
client: reqwest::Client::new(),
43+
}
4344
}
45+
}
4446

47+
impl KeycloakProvider {
4548
async fn realm_public_key(&self) -> Result<RS256PublicKey> {
46-
let client = Client::new();
47-
let resp = client
49+
let resp = self
50+
.client
4851
.get(keycloak_url!())
4952
.send()
5053
.await
@@ -68,3 +71,8 @@ impl SingleSignOnProvider for KeycloakProvider {
6871
Ok(claims.custom)
6972
}
7073
}
74+
75+
pub fn config() -> String {
76+
let keycloak_url = &keycloak_url!();
77+
format!("window.__APP_CONFIG__ = {{KEYCLOAK_URL:\"{keycloak_url}\"}};")
78+
}

tests/validate_portal_token.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ fn make_api(
4444
let mut single_sign_on_provider_mock = SingleSignOnProvider::default();
4545
single_sign_on_provider_mock
4646
.expect_verify_token()
47-
.returning(move |_| {
48-
let claims = claims.clone();
49-
Box::pin(async move { Ok(claims) })
50-
});
47+
.returning(move |_| Ok(claims.clone()));
5148

5249
Api {
5350
service_client: device_service_client_mock,

0 commit comments

Comments
 (0)