Crate axum_github_webhook_extract

Source
Expand description

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.

Structsยง

GithubEvent
Verify and extract Github Event Payload.
GithubToken
State to provide the Github Token to verify Event signature.