https://github.com/octokit/webhooks-methods.js
Methods to handle GitHub Webhook requests
https://github.com/octokit/webhooks-methods.js
hacktoberfest octokit-js plugin webhooks
Last synced: 7 months ago
JSON representation
Methods to handle GitHub Webhook requests
- Host: GitHub
- URL: https://github.com/octokit/webhooks-methods.js
- Owner: octokit
- License: mit
- Created: 2021-04-10T00:14:01.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-05-20T15:41:34.000Z (8 months ago)
- Last Synced: 2025-05-20T15:51:24.389Z (8 months ago)
- Topics: hacktoberfest, octokit-js, plugin, webhooks
- Language: TypeScript
- Homepage:
- Size: 2.32 MB
- Stars: 25
- Watchers: 4
- Forks: 10
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# webhooks-methods.js
> Methods to handle GitHub Webhook requests
[](https://www.npmjs.com/package/@octokit/webhooks-methods)
[](https://github.com/octokit/webhooks-methods.js/actions?query=workflow%3ATest+branch%3Amain)
Table of contents
- [usage](#usage)
- [Methods](#methods)
- [`sign()`](#sign)
- [`verify()`](#verify)
- [`verifyWithFallback()`](#verifywithfallback)
- [Contributing](#contributing)
- [License](#license)
## usage
Browsers
🚧 `@octokit/webhooks-methods` is not meant to be used in browsers. The webhook secret is a sensitive credential that must not be exposed to users.
Load `@octokit/webhooks-methods` directly from [esm.sh](https://esm.sh)
```html
import {
sign,
verify,
verifyWithFallback,
} from "https://esm.sh/@octokit/webhooks-methods";
```
Node
Install with `npm install @octokit/core @octokit/webhooks-methods`
```js
import { sign, verify, verifyWithFallback } from "@octokit/webhooks-methods";
```
```js
await sign("mysecret", eventPayloadString);
// resolves with a string like "sha256=4864d2759938a15468b5df9ade20bf161da9b4f737ea61794142f3484236bda3"
await verify("mysecret", eventPayloadString, "sha256=486d27...");
// resolves with true or false
await verifyWithFallback("mysecret", eventPayloadString, "sha256=486d27...", ["oldsecret", ...]);
// resolves with true or false
```
## Methods
### `sign()`
```js
await sign(secret, eventPayloadString);
```
secret
(String)
Required.
Secret as configured in GitHub Settings.
eventPayloadString
(String)
Required.
Webhook request payload as received from GitHub.
If you have only access to an already parsed object, stringify it with JSON.stringify(payload)
Resolves with a `signature` string. Throws an error if an argument is missing.
### `verify()`
```js
await verify(secret, eventPayloadString, signature);
```
secret
(String)
Required.
Secret as configured in GitHub Settings.
eventPayloadString
(String)
Required.
Webhook request payload as received from GitHub.
If you have only access to an already parsed object, stringify it with JSON.stringify(payload)
signature
(String)
Required.
Signature string as calculated by sign().
Resolves with `true` or `false`. Throws error if an argument is missing.
### `verifyWithFallback()`
```js
await verifyWithFallback(
secret,
eventPayloadString,
signature,
additionalSecrets,
);
```
secret
(String)
Required.
Secret as configured in GitHub Settings.
eventPayloadString
(String)
Required.
Webhook request payload as received from GitHub.
If you have only access to an already parsed object, stringify it with JSON.stringify(payload)
signature
(String)
Required.
Signature string as calculated by sign().
additionalSecrets
(Array of String)
If given, each additional secret will be tried in turn.
This is a thin wrapper around [`verify()`](#verify) that is intended to ease callers' support for key rotation.
Resolves with `true` or `false`. Throws error if a required argument is missing.
## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md)
## License
[MIT](LICENSE)