Reputation: 1474
When building a Conversational Action with the new Actions SDK or Action Builder, you can define a webhook to handle business logic. This webhook then receives fulfillment requests with the following headers, among others:
Google-Actions-API-Version: "3"
Google-Assistant-Signature: "eyJhbGciOiJSUzI1NiIsImtpZC..."
How should that signature be verified? It's a JWT claim, but the key ID with which it was signed does not exist in the GCP account linked with the Action, and is not mentioned in the new Actions SDK documentation or in the Node.js fulfillment library documentation.
Upvotes: 4
Views: 430
Reputation: 50701
The signature is a JSON Web Token, which is an encoded way of transmitting some assertions that have been signed in a verifiable way. There are libraries that will both decode and verify JWTs. The general steps (some of which you can cache or shortcut) are:
kid
(key id) and the payload to get the iss
(issuer) fields. You'll also want the nbf
(not before) and exp
(expiration) fields to verify this was set recently and the aud
field to verify that it matches your Google Cloud project ID.jwks_uri
field, which is the URL to get the current JWT certificates. For Google, this is probably "https://www.googleapis.com/oauth2/v3/certs"kid
that matches the kid
from the JWT. Note that these keys change frequently, but as long as you're within the window of the nbf
and exp
fields from the signature header, the key should exist in the certificate document.Upvotes: 3