rocket-apitoken 0.1.0

A very simple API Authorization module for Rocket web applications
Documentation
  • Coverage
  • 100%
    5 out of 5 items documented1 out of 5 items with examples
  • Size
  • Source code size: 48.97 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 4.7 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • kvinwang/rocket-apitoken
    1 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • kvinwang

rocket-apitoken

Crate API

A very simple API Authorization module for Rocket web applications

Overview

This module provides a simple token-based authorization system for Rocket web applications. It supports both enabled and disabled states, and validates Bearer tokens against a predefined set.

Usage Example

use rocket;
use rocket_apitoken::{ApiToken, Authorized};

#[post("/<method>?<json>", data = "<data>")]
async fn protected_endpoint(_auth: Authorized, /* other params */) {
    // If this executes, the request was authorized
    // ...
}

#[launch]
fn rocket() -> _ {
    let tokens = vec!["secret-token".to_string()];
    rocket::build()
        .manage(ApiToken::new(tokens, true))
        .mount("/api", routes![protected_endpoint])
}

Configuration

  • Create an ApiToken instance with a list of valid tokens and enabled state
  • Add it to Rocket's state using .manage()
  • Use the Authorized guard in your route handlers

When enabled, requests must include a valid token in the Authorization header. When disabled, all requests are authorized automatically.

License

This project is licensed under the MIT License - see the LICENSE file for details.