slack_auth_middleware/lib.rs
1//! A layer that authenticates requests from Slack.
2//!
3//! This layer will check the `x-slack-signature` header and the `x-slack-request-timestamp` header
4//! to ensure that the request is coming from Slack.
5//! If the request is not coming from Slack, this layer will return a 401 Unauthorized response.
6//!
7//! # Example
8//!
9//! ```no_run
10//! use axum::{routing::get, Router};
11//! use slack_auth_middleware::{SlackAuthConfig, SlackAuthLayer};
12//! use tracing_subscriber;
13//!
14//! #[tokio::main]
15//! async fn main() {
16//! tracing_subscriber::fmt::init();
17//!
18//! let config = SlackAuthConfig {
19//! version_number: "v0".to_string(),
20//! slack_signing_secret: "123".to_string(),
21//! };
22//!
23//! let app = Router::new().route("/", get(root).layer(SlackAuthLayer::new(config)));
24//! let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
25//! axum::serve(listener, app).await.unwrap();
26//! }
27//!
28//! async fn root() -> &'static str {
29//! "Hello, World!"
30//! }
31//! ```
32//!
33
34mod middleware;
35
36pub use middleware::SlackAuthConfig;
37pub use middleware::SlackAuthLayer;
38// exposed, so you can test your API.
39pub use middleware::SecretSigner;