What is an Event Token?
Each time Flock either sends an event to the event listener URL, or opens a widget or browser, it includes an event token in the form of a JSON Web Signature (JWS). This is a quick method for verifying that the request really did originate from Flock and prevent spoofing attacks.
What is signed by the event token?
The JWS signs a JSON Web Token (JWT) with the following attributes:
|Attribute Name||Attirbute Type||Attribute Description|
|String||The app's id|
|String||The user's id|
|Number||Expiration time of the token|
|Number||Time at which the token was issued|
(JWT ID) A unique identifier for the token
iat are numeric values representing the number of seconds from 1970-01-01T00:00:00Z UTC until the specified UTC date/time, ignoring leap seconds.
Note that the same event token may be sent more than once.
What key and algorithm are used to sign the JWT?
The key used to sign the event token is the app secret. The algorithm used is HMAC SHA-256.
Token Generation Example
The example below demonstrates how an event token is generated. You can consult the JWS specification for further details about this process. However, for most languages you should be able to find a JWT library with JWS support out of the box, so you wouldn't need to implement the verification and decoding yourself.
Assuming that the following JWT payload needs to be signed:
Further, assuming that the app secret that would be used to sign the payload is
869eb1d0-419d-4747-98b4-6d81360a6681, the resultant HMAC-SHA256 signature (encoded using URL-safe base64) is
The following JOSE header is used (provides the algorithm and the type of payload):
Encoding the JOSE header and the JWT payload using URL-safe base64, and then joining the encoded header, payload and signature using the dot (".") yields the following event token: