Google Meet: verify the token of Pub/Sub push requests
Merged
EH
2d ago+236+236+012345678901234567890123456789-2-2-0123456789
Context
Follows https://github.com/twentyhq/twenty/pull/30606 in the Google Meet app series started in https://github.com/twentyhq/twenty/pull/30587.
Google publishes Meet events to a Pub/Sub topic, and a Pub/Sub push subscription will forward them to a Twenty server route (a later PR). Pub/Sub authenticates each push request with a Google-signed JWT in the Authorization header. This PR adds the check for that token. Nothing calls it yet.
What this PR does
- Adds
verifyGooglePubsubPushTokenOrThrow. It verifies the token's signature against Google's public keys (https://www.googleapis.com/oauth2/v3/certs), that Google issued it, that it is not expired (60 seconds of clock tolerance), that its audience is the one configured on the push subscription, and that it was issued to the configured service account with a verified email. Any failure throwsPUSH_TOKEN_INVALID. - Adds
extractBearerToken, which reads a single bearer token from the header. - Adds the
josedependency for the JWT verification, the library the Teams app already uses to verify its inbound tokens. - The signing-key lookup can be injected, so the tests sign real tokens with a generated key pair and cover a wrong signer, audience, issuer, service account, an unverified email, an expired token and a missing token.
Checks
yarn lint,yarn typecheck,yarn test:unit(115 tests) andtwenty app buildpass locally.- Not run: integration tests (they need a running server, CI runs them), and no real Pub/Sub token was verified against Google's keys.