Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

clerk-rs

> 安全
Open source

The official community-maintained Clerk SDK for Rust

176 stars0 likes1 views
WebsiteGitHub

About

The official community-maintained Clerk SDK for Rust

clerk-rs

The community-maintained Rust SDK for the Clerk Backend API, plus request-authentication middleware for Actix Web, Axum, Rocket, and Poem.

Version 0.5 targets Clerk Backend API version 2026-05-12. The generated API and model modules come from Clerk's official dated OpenAPI specification and use https://api.clerk.com/v1 by default.

Calling the Backend API

use clerk_rs::{apis::users_api, Clerk};

#[tokio::main]
async fn main() -> Result> {
    let clerk = Clerk::from_secret_key("your_secret_key");
    let user = users_api::get_user(&clerk.config, "user_id").await?;

    println!("{}", user.id);
    Ok(())
}

Every generated function accepts &ClerkConfiguration as its first argument:

use clerk_rs::{apis::organizations_api, ClerkConfiguration};

# async fn example() -> Result> {
let config = ClerkConfiguration::new("your_secret_key");
let organization = organizations_api::get_organization(
    &config,
    "organization_id",
    None,
    None,
).await?;
# Ok(())
# }

See the generated docs directory for all API groups, request types, and response models.

Authentication middleware

Enable the integration for your web framework:

toml
[dependencies]
clerk-rs = { version = "0.5", features = ["axum"] }

Protecting an Actix Web endpoint

Enable the actix feature, then wrap the application with ClerkMiddleware:

…

See the complete Actix Web example.

Protecting an Axum endpoint

Enable the axum feature, then add ClerkLayer to the router. The authenticated JWT is available through Axum's Extension extractor on protected routes:

…

The route list passed to ClerkLayer::new selects protected routes. Passing None protects every route. See the complete Axum example.

Protecting a Rocket endpoint

Enable the rocket feature, register ClerkGuardConfig, and add ClerkGuard to protected route handlers:

use clerk_rs::{
    validators::{
        jwks::MemoryCacheJwksProvider,
        rocket::{ClerkGuard, ClerkGuardConfig},
    },
    Clerk,
};
use rocket::{get, launch, routes};

#[get("/")]
fn index(_jwt: ClerkGuard) -> &'static str {
    "Hello world!"
}

#[launch]
fn rocket() -> _ {
    let clerk = Clerk::from_secret_key("your_secret_key");
    let guard_config = ClerkGuardConfig::new(
        MemoryCacheJwksProvider::new(clerk),
        None,
        true,
    );

    rocket::build()
        .mount("/", routes![index])
        .manage(guard_config)
}

See the complete Rocket example.

Protecting a Poem endpoint

Enable the poem feature, then apply ClerkPoemMiddleware to the route:

…

The authenticated JWT is available as Data or through req.data::(). The final constructor argument optionally lists routes excluded from authentication.

Live validator integration tests for all four frameworks are documented in tests/README.md. They are ignored during normal test runs and require credentials for a development Clerk instance.

API versioning

ClerkConfiguration::default() and ClerkConfiguration::new() send:

Clerk-API-Version: 2026-05-12

An older supported Clerk version can be selected explicitly:

rust
use clerk_rs::ClerkConfiguration;

let config = ClerkConfiguration::new("your_secret_key")
    .with_api_version("2025-11-10");

The Rust types still describe 2026-05-12; selecting an older wire version does not change compile-time types.

Regenerating the SDK

The repository vendors Clerk's exact specification at openapi/clerk-bapi-2026-05-12.yml and pins OpenAPI Generator in openapitools.json.

Install @openapitools/openapi-generator-cli, then run:

bash
./scripts/generate-openapi.sh

The script verifies the specification checksum, applies the narrowly scoped int64 normalization documented in scripts/prepare-openapi.mjs, regenerates src/apis, src/models, and docs, preserves the hand-written Clerk configuration, and formats the result.

TLS and framework features

  • rustls-tls (default)
  • native-tls
  • actix
  • axum
  • rocket
  • poem

Production users

  • Tembo
  • Rezon
  • Gitar
  • Have I Been Squatted
  • Open a PR and add your company here :)

License

MIT

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rustactix-webauthenticationauthorizationaxum

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category安全
PricingOpen source

> Related tools

O
OWASP ZAP
开源 Web 应用安全扫描器
O
owasp-wstg-tracker
Simple web app to track OWASP WSTG security testing progress
H
homebridge-mi-gateway-security
XiaoMi Gateway Security plugin for HomeBridge.