Skip to content

Commit

Permalink
chore(webhooks): improve webhook docs
Browse files Browse the repository at this point in the history
* add chapter about data structure of a webhook event
* add info that you need to implement an endpoint on your application
* add info that a webhook JWT can be decoded with the JWK created in an earlier chapter
  • Loading branch information
Stefan Jacobi committed Feb 16, 2024
1 parent 8500b19 commit 4ad3094
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,31 @@ To import users run:

### Webhooks

#### Events
Webhooks are an easy way to get informed about changes in your Hanko instance (e.g. user or email updates).
Hanko provides the following event structure:
To use webhooks you have to provide an endpoint on your application which can process the events. Please be aware that your
endpoint need to respond with an HTTP status code 200. Else-wise the delivery of the event will not be counted as successful.

#### Events
When a webhook is triggered it will send you a **JSON** body which contains the event and a jwt.
The JWT contains 2 custom claims:

* **data**: contains the whole object for which the change was made. (e.g.: the whole user object when an email or user is changed/created/deleted)
* **evt**: the event for which the webhook was triggered

A typical webhook event looks like:

```json
{
"token": "the-jwt-token-which-contains-the-data",
"event": "name of the event"
}
```

To decode the webhook you can use the JWKs created in [Configure JSON Web Key Set generation](#configure-json-web-key-set-generation)

#### Event Types

Hanko sends webhooks for the following event types:

| Event | Triggers on |
|---------------------------|----------------------------------------------------------------------------------------------------|
Expand Down

0 comments on commit 4ad3094

Please sign in to comment.