Server-Side Application to Generate JWT
It is up to your web developer how to implement JWT generation. For example, if you use Wordpress, you can develop a PHP script to receive dynamic AJAX calls and generate the token.
Example of a PHP application
- <?php
- require_once __DIR__ . '/vendor/autoload.php';
- use Firebase\JWT\JWT;
- //-- when keys are loaded from file
- $passphrase = '';
- $privateKeyFile = __DIR__ . '/jwt-private.pem';
- $privateKey = openssl_pkey_get_private(
- file_get_contents($privateKeyFile),
- $passphrase
- );
- $publicKeyFile = __DIR__ . '/jwt-public.pem';
- $publicKey = file_get_contents($publicKeyFile);
- $iat = time();
- $interval = 5; //-- minutes
- $jti = bin2hex(random_bytes(16));
- $data = array(
- 'iss' => 'com-organizacion-acme',
- 'aud' => 'app.hotelrsv.com',
- 'iat' => $iat,
- 'exp' => $iat + $interval * 60,
- 'jti' => $jti,
- 'hotelrsv_id_h' => 100,
- 'username' => 'johndoe',
- 'other_fields' => 'foo bar'
- );
- $token = JWT::encode($data, $privateKey, 'RS256');
- $aToken = array('token' => $token);
- header('Content-Type: application/json');
- echo json_encode($aToken);
JavaScript to Request the JWT and Inject it into the DOM
You can add the token dynamically to any Booking Button by simply adding the
data-hotelrsv-tokenized attribute to the HTML element.
Since the token is valid for a maximum of 12 minutes, it is recommended to generate it dynamically for each call to a booking button.
For this we provided a Javascript "Hook Interface" or Hook in Javascript called
nvhHookBeforeRsvAppLauncher that allows you to execute Javascript before the booking engine is triggered. It is there where you can dynamically define the call to your server application to generate the JWT dynamically.