authorization-bridge

Crates.ioauthorization-bridge
lib.rsauthorization-bridge
version0.2.2
created_at2025-11-06 17:08:48.166309+00
updated_at2025-11-14 19:26:55.59912+00
descriptionAn Actix Web middleware for authenticating HTTP requests through a remote API. It validates Authorization headers or cookies and attaches user info to requests.
homepagehttps://github.com/SetliteWeb/authorization-middleware
repositoryhttps://github.com/SetliteWeb/authorization-middleware
max_upload_size
id1920019
size69,399
DAVID KIARIE MACHARIA (david-macharia)

documentation

https://docs.rs/auth_middleware

README

Create a simple README.md:

auth_middleware

An Actix Web middleware for authenticating requests using a remote API.

๐Ÿš€ Features

  • Extracts Authorization header or cookie
  • Calls a configurable remote API to verify the user
  • Attaches authenticated user info to request extensions

๐Ÿงฉ Example

use actix_web::{App, HttpServer, HttpResponse, web};
use auth_middleware::AuthMiddleware;

async fn index() -> HttpResponse {
    HttpResponse::Ok().body("Welcome to protected route!")
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| {
        App::new()
            .wrap(AuthMiddleware::new(
    vec!["/public".to_string(), "/pub_api/".to_string()], // cover both
    vec![Method::GET, Method::POST, Method::OPTIONS], // allow POST for uploads
))
            .route("/", web::get().to(index))
    })
    .bind(("127.0.0.1", 8080))?
    .run()
    .await
}

๐Ÿ”ง Environment

Set AUTH_API_URL to your authentication service endpoint:

AUTH_API_URL=http://localhost:8080/api/profile

๐Ÿ“œ License

MIT


---

## โš–๏ธ 5. `LICENSE`

Use MIT (common for Rust libraries):

```text
MIT License

Copyright (c) 2025 David Macharia

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction...

๐Ÿง  6. Initialize Git
cd auth_middleware
git init
git add .
git commit -m "Initial commit: Auth middleware for Actix Web"

๐Ÿš€ 7. Test locally

Before publishing, run:

cargo check
cargo test
cargo doc --open

๐Ÿชถ 8. Publish to crates.io

Log in with your GitHub account:

cargo login


(Youโ€™ll get your API token from https://crates.io/me
)

Publish the crate:

cargo publish


Thatโ€™s it! ๐ŸŽ‰
Your middleware will now be live on crates.io and installable via:

[dependencies]
auth_middleware = "0.1"


Would you like me to add a test example showing how another crate can mock a request and check that the middleware inserts the user properly?
Commit count: 0

cargo fmt