laravel-fit-validator maintained by bencolmer
Laravel FIT Validator
This package allows you to validate and use Atlassian Forge Invocation Tokens (FITs) in Laravel.
Installation
- Install the package via composer:
composer require bencolmer/laravel-fit-validator
- Configure
.envvalues:
FIT_APP_ID="example:id::app/xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx" # The ID of your Forge application
FIT_JWKS_URL="https://forge.cdn.prod.atlassian-dev.net/.well-known/jwks.json" # The JWKS URL for your Forge application
- Add the
fitmiddleware to any routes that should validate Forge Invocation Tokens.
Route::middleware('fit')->group(function () {
//
});
Token Usage
The fit middleware will validate the Forge Invocation Token and add the validated payload to the request input array.
Example:
// in routes/api.php
Route::middleware('fit')->group(function () {
Route::get('example', [ExampleController::class, 'index']);
});
// in app/Http/Controllers/ExampleController.php
use Illuminate\Http\Request;
class ExampleController extends Controller
{
public function index(Request $request)
{
$fit = $request->input('fit');
// ...
}
}
Advanced Usage
You can configure the package to validate FIT tokens from multiple Forge applications:
- Publish package configuration
php artisan vendor:publish --provider="BenColmer\LaravelFITValidator\Providers\ServiceProvider"
- Add your Forge application details to the
applicationsarray inconfig/fit.php:
// ...
'applications' => [
// ...
// details for your other application
'otherApp' => [
'appId' => (string) env('FIT_OTHER_APP_ID', ''),
'jwksUrl' => (string) env('FIT_OTHER_JWKS_URL', ''),
]
],
- Update the
fitmiddleware to use the configuration for your new application
// in routes/api.php
Route::middleware('fit')->group(function () {
// validate FITs using the "default" application config
});
Route::middleware('fit:otherApp')->group(function () {
// validate FITs using the "otherApp" application config
});
Additional Configuration
The following options can also be modified by publishing the package configuration:
| Name | Default Value | Description |
|---|---|---|
middlewareAlias |
fit |
The alias for the FIT validation middleware |
issuer |
forge/invocation-token |
The expected Forge Invocation Token issuer |
jwksCacheDuration |
5 minutes | The cache duration for fetched JSON Web Key Sets. Setting this to null will disable caching |
Testing
Run tests via PHPUnit:
./vendor/bin/phpunit
Credits
License
Laravel FIT Validator is open-sourced software licensed under the MIT license.