key
keycloak
cargo install keycloak
key

keycloak

Keycloak REST API Client

by Alexander Korolev

18.0.0 (see all)License:Unlicense OR MIT
cargo install keycloak
Readme

Keycloak Admin REST API

Dual-licensed under MIT or the UNLICENSE.

Features

Implements Keycloak Admin REST API version 18.0.

Usage

Requires Rust version >= 1.58.0.

Add dependency to Cargo.toml:

[dependencies]
keycloak = "18.0"
use keycloak::{
    types::*,
    {KeycloakAdmin, KeycloakAdminToken},
};


#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let url = std::env::var("KEYCLOAKADDR").unwrap_or_else(|| "http://localhost:9080".into());
let user = std::env::var("KEYCLOAKUSER").unwrap_or_else(|| "admin".into());
let password = std::env::var("KEYCLOAKPASSWORD").unwrap_or_else(|| "password".into());
let client = reqwest::Client::new();
let admin_token = KeycloakAdminToken::acquire(&url, &user, &password, &client).await?;



eprintln!("{:?}", admin_token);

let admin = KeycloakAdmin::new(&amp;url, admin_token, client);

admin
    .post(RealmRepresentation {
        realm: Some("test".into()),
        ..Default::default()
    })
    .await?;

admin
    .realm_users_post(
        "test",
        UserRepresentation {
            username: Some("user".into()),
            ..Default::default()
        },
    )
    .await?;

let users = admin
    .realm_users_get(
        "test", None, None, None, None, None, None, None, None, None, None, None, None, None,
        None,
    )
    .await?;

eprintln!("{:?}", users);

let id = users
    .iter()
    .find(|u| u.username == Some("user".into()))
    .unwrap()
    .id
    .as_ref()
    .unwrap()
    .to_string();

admin
    .realm_users_with_id_delete("test", id.as_str())
    .await?;

admin.realm_delete("test").await?;

Ok(())




}

}

Version agreement

If we have x.y.z version of keycloak, our package version would be x.y.(z * 100 + v) there v is a minor fix version to official x.y.z version.

Example: official version 13.0.1 is 13.0.100 for crate version. 13.0.102 means keycloak version 13.0.1 and minor fix version 2.

GitHub Stars

11

LAST COMMIT

2mos ago

MAINTAINERS

1

CONTRIBUTORS

4

OPEN ISSUES

5

OPEN PRs

0
VersionTagPublished
18.0.0
2mos ago
17.0.2
3mos ago
17.0.1
3mos ago
17.0.0
4mos ago
No alternatives found
No tutorials found
Add a tutorial