---
title: "PHP, Python, .NET or Node.js: receive webhooks"
description: "Close the session in your app when the user closes it from Block-Auth."
url: "/sdk-integration-server-webhooks/"
language: "en"
guide: "PHP, Python, .NET, Node.js"
step: "More options, optional"
---

# Receive webhooks

Optional, recommended for production. Login works without it, but if the user signs out from Block-Auth (Identity, the extension or another device), your app won’t know.

## Receive webhooks

Block-Auth calls your backend when a user signs out of your app from Block-Auth (`signout`) or unlinks your app (`account.unlinked`), so you can close their session too.

1. In the Dashboard, open your application's **Authentication** settings. In the third URL field, shown as **"When user fails to log in"**, type the path `/blockauth/webhook` (your domain is already filled in).
2. Add the route. It checks the signature (headers `X-BlockAuth-Timestamp` and `X-BlockAuth-Signature`), checks that the `apiKey` is yours and ignores repeated `jti`:

**Body · What your server receives (not code to copy) (example only, not to copy)**

```json
{
  "event": "account.unlinked",
  "apiKey": "your_api_key",
  "address": "0x8f2a…c41d",
  "externalId": "42",
  "iat": 1762790400,
  "jti": "5c1e2b7a-…"
}
```

> **Placeholders in this code:**
>
> - Replace `your_api_key` with your API Key, or fill in your data in the SDK Quickstart and it is filled in for you.

**Node.js · server.js · where you create your Express app**

```javascript
const seen = new Map()

app.post('/blockauth/webhook', express.raw({ type: '*/*' }), (req, res) => {
  let event
  try {
    event = blockauth.verifyWebhook(req.body, req.get('X-BlockAuth-Timestamp'), req.get('X-BlockAuth-Signature'))
  } catch {
    return res.status(401).end()
  }
  if (event.apiKey !== BLOCKAUTH_API_KEY || seen.has(event.jti)) return res.status(409).end()
  seen.set(event.jti, Date.now())

  endSessionsOf(event.address)
  if (event.event === 'account.unlinked') markUnlinked(event.externalId)
  res.json({ ok: true })
})
```

**PHP · public/index.php · your entry point**

```php
if ($route === 'POST /blockauth/webhook') {
    try {
        $event = $blockauth->verifyWebhook(
            file_get_contents('php://input'),
            $_SERVER['HTTP_X_BLOCKAUTH_TIMESTAMP'] ?? '',
            $_SERVER['HTTP_X_BLOCKAUTH_SIGNATURE'] ?? ''
        );
    } catch (BlockAuthException $e) {
        json(401, ['ok' => false]);
    }
    if (($event['apiKey'] ?? null) !== getenv('BLOCKAUTH_API_KEY') || alreadyProcessed($event['jti'])) {
        json(409, ['ok' => false]);
    }
    endSessionsOf($event['address']);
    if ($event['event'] === 'account.unlinked') {
        markUnlinked($event['externalId']);
    }
    json(200, ['ok' => true]);
}
```

**Python · app.py · where you create your app**

```python
@app.post("/blockauth/webhook")
def webhook():
    try:
        event = blockauth.verify_webhook(
            request.get_data(),
            request.headers.get("X-BlockAuth-Timestamp", ""),
            request.headers.get("X-BlockAuth-Signature", ""),
        )
    except BlockAuthError:
        return jsonify(ok=False), 401
    if event.get("apiKey") != os.environ["BLOCKAUTH_API_KEY"] or already_processed(event["jti"]):
        return jsonify(ok=False), 409
    end_sessions_of(event["address"])
    if event["event"] == "account.unlinked":
        mark_unlinked(event.get("externalId"))
    return jsonify(ok=True)
```

**.NET · Program.cs**

```csharp
app.MapPost("/blockauth/webhook", async (HttpRequest request, AuthCodeClient blockauth) =>
{
    using var reader = new StreamReader(request.Body);
    var raw = await reader.ReadToEndAsync();
    try
    {
        var evt = blockauth.VerifyWebhook(
            raw,
            request.Headers["X-BlockAuth-Timestamp"],
            request.Headers["X-BlockAuth-Signature"]);
        if (AlreadyProcessed(evt.Jti)) return Results.Conflict();
        EndSessionsOf(evt.Address);
        if (evt.Event == "account.unlinked") MarkUnlinked(evt.ExternalId);
        return Results.Ok(new { ok = true });
    }
    catch (BlockAuthException)
    {
        return Results.Unauthorized();
    }
});
```

> **Placeholders in this code:**
>
> - `endSessionsOf`, `markUnlinked` are yours: replace them with your app’s own functions (your database, your cache…).
> - `endSessionsOf`, `markUnlinked`, `alreadyProcessed` are yours: replace them with your app’s own functions (your database, your cache…).
> - `end_sessions_of`, `mark_unlinked`, `already_processed` are yours: replace them with your app’s own functions (your database, your cache…).
> - `EndSessionsOf`, `MarkUnlinked`, `AlreadyProcessed` are yours: replace them with your app’s own functions (your database, your cache…).

`endSessionsOf`, `markUnlinked` and `alreadyProcessed` are yours: they depend on how your app stores sessions and users.
