#oauth2 #oauth #keycloak #integration #flows #seamless

keycloak-oauth

Library designed for seamless integration with Keycloak's OAuth2 authentication flows

2 releases

0.0.2 Oct 17, 2024
0.0.1 Oct 17, 2024

#254 in Authentication

Download history 157/week @ 2024-10-11 135/week @ 2024-10-18

292 downloads per month

MIT license

23KB
495 lines

keycloak-oauth

keycloak-oauth is a basic Rust library designed to facilitate seamless integration with Keycloak's OAuth2 authentication flows.

Currently only supports device authentication flow.

[!CAUTION] The flow currently temporarily caches a token on disk in .temp_files/token.json. This will be upgraded to libsecret in the future

Getting started

use keycloak_oauth::{ClientConfiguration, KeycloakClient, ClientError};

#[tokio::main]
async fn main() -> Result<(), ClientError> {
    // Load configuration from environment variables or another source
    let config = ClientConfiguration::from_env();

    // Initialize the KeycloakClient
    let keycloak_client = KeycloakClient::new(config);

    // Authenticate and obtain the access token
    let access_token = keycloak_client.verify_and_refresh_token().await?;

    // Use the access token as needed
    println!("Obtained Access Token: {}", access_token);

    Ok(())
}

License

This project is licensed under the MIT License.

Dependencies

~9–23MB
~365K SLoC