clerk-rs Rust SDK

repository·main·Indexed 41 days ago

https://github.com/darrenbaldwin07/clerk-rs

A community-maintained Rust SDK for the Clerk Backend API (v0.5.0). It provides type-safe access to Clerk services and includes request-authentication middleware for Rust web frameworks including Axum, Actix Web, Rocket, and Poem.

Tokens
178.2K
Snippets
508
Records
631
Agent score
51%

What's inside clerk-rs

  1. Overview of OrganizationsApi

    main
    The OrganizationsApi provides methods to manage organizations within a Clerk instance. This includes creating, deleting, retrieving, and updating organizations, as well as managing organization-specific billing credits, subscriptions, and logos. All requests are relative to https://api.clerk.com/v1 and require bearerAuth.
  2. Overview of the Users API

    main

    The UsersApi provides a comprehensive set of endpoints for managing users within Clerk. All URIs are relative to https://api.clerk.com/v1.

    Key capabilities include:

    • User Lifecycle: Create, retrieve, update, and delete users.
    • Security & Access: Ban/unban users, lock/unlock users, manage MFA (TOTP, backup codes), and manage passkeys or Web3 wallets.
    • Billing: Adjust user credit balances and retrieve subscription information.
    • Metadata: Replace or merge user metadata.
    • Authentication Management: Verify passwords and manage external accounts or OAuth tokens.
  3. Manage Directories via DirectoriesApi

    main

    The DirectoriesApi provides methods to manage Clerk directories. All URIs are relative to https://api.clerk.com/v1. Common operations include creating, retrieving, updating, deleting, and listing directories. Most operations require bearerAuth for authorization.

    // Summary of available methods:
    // POST /directories -> create_directory
    // GET /directories/{directory_id} -> get_directory
    // PATCH /directories/{directory_id} -> update_directory
    // DELETE /directories/{directory_id} -> delete_directory
    // GET /directories -> list_directories
  4. Manage API Keys via ApiKeysApi

    main

    The ApiKeysApi provides methods to manage Clerk API keys, including creation, retrieval, updating, deletion, and revocation. All requests are relative to https://api.clerk.com/v1 and require bearerAuth authorization.

    | Method | HTTP request | Description |
    |------------- | ------------- | ------------- |
    | **create_api_key** | **POST** /api_keys | Create an API Key |
    | **delete_api_key** | **DELETE** /api_keys/{apiKeyID} | Delete an API Key |
    | **get_api_key** | **GET** /api_keys/{apiKeyID} | Get an API Key by ID |
    | **get_api_key_secret** | **GET** /api_keys/{apiKeyID}/secret | Get an API Key Secret |
    | **get_api_keys** | **GET** /api_keys | Get API Keys |
    | **revoke_api_key** | **POST** /api_keys/{apiKeyID}/revoke | Revoke an API Key |
    | **update_api_key** | **PATCH** /api_keys/{apiKeyID} | Update an API Key |
    | **verify_api_key** | **POST** /api_keys/verify | Verify an API Key |
  5. Manage SCIM Directories

    main

    The ScimDirectoriesApi allows you to manage SCIM directories for your Clerk instance. All URIs are relative to https://api.clerk.com/v1.

    Available operations include:

    • Create: create_scim_directory using a CreateScimDirectoryRequest.
    • Retrieve: get_scim_directory by ID.
    • List: list_scim_directories with optional limit and offset for pagination.
    • Update: update_scim_directory using an UpdateScimDirectoryRequest.
    • Delete: delete_scim_directory which stops provisioning and invalidates the directory's API key.
    • Rotate Key: rotate_scim_directory_api_key to generate a new API key (the only way to retrieve the key after creation).
  6. Billing API Overview

    main

    The Billing API provides endpoints for managing organization and user credit balances, subscription items, discounts, and custom pricing. All URIs are relative to https://api.clerk.com/v1. Most endpoints require bearerAuth and use application/json for both Content-Type and Accept headers.

    POST /organizations/{organization_id}/billing/credits
    POST /users/{user_id}/billing/credits
    POST /billing/subscription_items/{subscription_item_id}/discounts
    DELETE /billing/subscription_items/{subscription_item_id}
    POST /billing/prices
    POST /billing/subscription_items/{subscription_item_id}/price_transition
    POST /billing/subscription_items/{subscription_item_id}/extend_free_trial
    GET /billing/prices
    GET /billing/statements/{statementID}
    GET /billing/statements
    GET /billing/statements/{statementID}/payment_attempts
    GET /billing/plans
    GET /billing/subscription_items
    GET /organizations/{organization_id}/billing/credits
    GET /organizations/{organization_id}/billing/subscription
    GET /users/{user_id}/billing/credits
    GET /users/{user_id}/billing/subscription
    DELETE /billing/subscription_items/{subscription_item_id}/discounts/{discount_id}
  7. Use ToggleTemplateDeliveryRequest to control Clerk message delivery

    main

    The ToggleTemplateDeliveryRequest model is used to specify whether Clerk should handle the delivery of emails or SMS messages when using a specific template.

    By setting the delivered_by_clerk property, you can opt-in or opt-out of Clerk's automated delivery mechanism for the current template.

    // Example usage of the property within a request
    let request = ToggleTemplateDeliveryRequest {
        delivered_by_clerk: Some(true), // Clerk will deliver the message
    };
  8. Manage directory group role mappings

    main

    Group role mappings allow you to map directory groups to organization roles. This feature must be enabled on the directory to function.

    Operations:

    • Create: create_directory_group_role_mapping(directory_id, create_directory_group_role_mapping_request) creates a new mapping.
    • List: list_directory_group_role_mappings(directory_id) returns mappings ordered by precedence.
    • Replace: replace_directory_group_role_mappings(directory_id, replace_directory_group_role_mappings_request) replaces the entire set of mappings. The order in the mappings array determines precedence (index 0 is precedence 1). Passing an empty array removes all mappings.
    • Delete: delete_directory_group_role_mapping(directory_id, mapping_id) deletes a specific mapping.
  9. Understand the OrganizationDomains model structure

    main

    The OrganizationDomains model is a container used when querying or receiving lists of organization domains. It consists of two primary fields:

    • data: A Vec<models::OrganizationDomain> containing the actual list of organization domain objects.
    • total_count: An i64 representing the total number of organization domains available in the system (useful for pagination).