Take Pireon's webhooks: a deactivation or a revocation counts at once
Some checks failed
Tests / lint (push) Has been cancelled
Tests / test (push) Has been cancelled
Tests / test-postgres (push) Has been cancelled
Tests / mcp (push) Has been cancelled

Until now, an account switched off or a token revoked at the identity
server kept working here: bearer tokens until the introspection cache
ran out, panel sessions until they ended, and machine tokens for good,
as they only look at the local account.

POST /api/v1/webhooks/pireon takes user.deactivated (the account goes
inactive, which stops its machine tokens and the panel; its sessions
end and its cached tokens are forgotten) and token.revoked (sessions
and cached tokens go). Pireon signs each delivery with the secret of
the client that registered the webhook, so either PIREON_WEBHOOK_SECRET
(password client) or PIREON_REDIRECT_WEBHOOK_SECRET («Entrar con
Pireon») verifies it; with neither, the endpoint refuses everything.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-16 17:01:57 +02:00
parent ec4f687ca8
commit d10ce1ca57
9 changed files with 361 additions and 0 deletions

View File

@@ -104,9 +104,33 @@ class PireonTokenGuard
Cache::put($key, $identity->toArray(), $ttl);
// Which cached tokens are whose, so a webhook can drop a person's.
$index = self::indexKey($identity->id);
Cache::put($index, array_values(array_unique([...(array) Cache::get($index, []), $key])), $ttl);
return $identity;
}
/**
* Forget every token of that person checked lately: the next request with
* any of them asks the identity server again.
*/
public static function forgetUser(int|string $oauthId): void
{
$index = self::indexKey($oauthId);
foreach ((array) Cache::get($index, []) as $key) {
Cache::forget((string) $key);
}
Cache::forget($index);
}
protected static function indexKey(int|string $oauthId): string
{
return 'pireon:introspect:user:'.$oauthId;
}
/**
* Mirror the identity locally so policies, ownership checks and foreign
* keys have a real row to work with. Local roles are left untouched.