百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

clerk-rs

> 安全
开源

Rust 由官方社区维护的 Clerk SDK

176 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

Rust 由官方社区维护的 Clerk SDK

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 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rustactix-webauthenticationauthorizationaxum

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类安全
定价开源

> 相关工具

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.