Authentication
NEVER commit your Fireboost API key to GitHub! Always store it in a secure environment variable.
Authentication using the SDK
Using the official SDK is the recommended way to authenticate your requests to the Fireboost API.
The SDK automatically applies the required authentication headers for any request that necessitates authorized access.
Once the CacheManager is configured with a valid API key, it will handle authentication automatically for all cache operations. See example of private read below.
Setting up the CacheManager with the proper API key
use FireboostIO\SDK\CacheManager;
use FireboostIO\SDK\Adapter\SessionAdapter;
// Create a CacheManager instance with default SessionAdapter
$apiKey = 'your-api-key'; // Or set FIREBOOST_API_KEY environment variable
$cacheManager = new CacheManager(new SessionAdapter(), $apiKey);
// You can start using it right away
$data = $cacheManager->readCache('my-cache-key');
That's it! You can start using the SDK right away.
Authentication using the libraries
This approach is best suited if you want to build a custom SDK or have more fine‑grained control over your integration.
Authentication involves swapping your API key for a JWT.
Required Libraries
To handle authentication, install both of the following packages:
composer require fireboostio/fireboost-php-auth
composer require fireboostio/fireboost-php-client
Requesting a JWT
Send your API key to the /v1/login endpoint to receive a JSON Web Token (JWT), which you’ll use in subsequent authenticated requests.
use FireboostIO\Api\FireboostApi;
use Fireboostio\Encryptor\CredentialExtractor;
use FireboostIO\Model\LoginInput;
use FireboostIO\Configuration;
// Your Fireboost API key
$fireboostioKey = "apiKey_eyJhcGlLZXki...";
// initialize the JWT variable
$jwt = "";
// Create configuration with proper host URL
$config = new Configuration();
$config->setHost('https://{your-project-name}.api.fireboost.io');
// Create API client with configuration
$api = new FireboostApi(null, $config);
// Create encryptor
$encryptor = new CredentialExtractor();
$loginInputData = $encryptor->getLoginInputData($fireboostioKey);
try {
$response = $api->login(new LoginInput($loginInputData));
$jwt = $response->getJwtToken();
error_log('Success! JWT Token: ' . json_encode($jwt, JSON_PRETTY_PRINT));
} catch (Exception $e) {
error_log('Error: ' . $e->getMessage());
}
// use the $jwt in subsequent authenticated requests
Example response
{
"jwtToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NT.."
}