Skip to content

Commit

Permalink
fix(keycloak): get the right realm id
Browse files Browse the repository at this point in the history
  • Loading branch information
Threated committed Nov 30, 2023
1 parent 46dd136 commit e7043c4
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions central/src/keycloak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,19 +373,23 @@ async fn get_realm_permission_roles(token: &str, conf: &KeyCloakConfig) -> reqwe
#[serde(rename = "clientId")]
client_id: String
}
let permission_realm = if conf.keycloak_realm == "master" {
"master-realm"
} else {
"realm-management"
};
let res = CLIENT.get(&format!(
"{}/admin/realms/{}/clients/?q={}-realm&search",
conf.keycloak_url, conf.keycloak_realm, "realm-management"
"{}/admin/realms/{}/clients/?q={permission_realm}&search",
conf.keycloak_url, conf.keycloak_realm
))
.bearer_auth(token)
.send()
.await?
.json::<Vec<RealmId>>()
.await?;
let role_client = res.into_iter()
.find(|v| v.client_id.starts_with(&conf.keycloak_realm))
.expect(&format!("Failed to find realm id for {}", conf.keycloak_realm));
// GET /admin/realms/{realm}/clients/{id}/roles
.find(|v| v.client_id.starts_with(permission_realm))
.expect(&format!("Failed to find realm id for {permission_realm}"));
CLIENT.get(&format!(
"{}/admin/realms/{}/clients/{}/roles",
conf.keycloak_url, conf.keycloak_realm, role_client.id
Expand Down

0 comments on commit e7043c4

Please sign in to comment.