#github-webhook #github #axum #payload #extract #events #secure

axum-github-webhook-extract

A library to secure GitHub Webhooks and extract JSON event payloads in Axum

4 releases

0.2.0 Dec 11, 2023
0.1.2 Jun 10, 2023
0.1.1 Jun 10, 2023
0.1.0 Jun 10, 2023

#15 in #github-webhook

MIT license

10KB
128 lines

axum-github-webhook-extract

Build Crates.io Documentation

A library to secure GitHub Webhooks and extract JSON event payloads in Axum. See documentation for how to use the library.


lib.rs:

A library to secure GitHub Webhooks and extract JSON event payloads in Axum.

The library is an Extractor paired with State to provide the required Secret Token.

Usage looks like:

use axum_github_webhook_extract::{GithubToken, GithubEvent};

#[derive(Debug, Deserialize)]
struct Event {
    action: String,
}

async fn echo(GithubEvent(e): GithubEvent<Event>) -> impl IntoResponse {
    e.action
}

fn app() -> Router {
    let token = String::from("d4705034dd0777ee9e1e3078a12a06985151b76f");
    Router::new()
        .route("/", post(echo))
        .with_state(GithubToken(Arc::new(token)))
}

You will usually get the token from your environment or configuration. The event payload is under your control, just make sure to configure it to use JSON.

Dependencies

~5–12MB
~138K SLoC