Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
> v2.0.5 ~ "App Review types that share a model"
> v2.0.6 ~ "Platform token sign-in for instance apps"

# v2.0.5 — App Review types that share a model
# v2.0.6 — Platform token sign-in for instance apps

## Added

- **A middleware group for the routes an app calls before its user signs in: `fleetbase.api-or-platform`.** It is `fleetbase.api` that also accepts the instance's platform token (`flb_platform_…`). An app built for the whole instance, such as Navigator, has no organization until its user signs in, so it can present the platform token on these routes instead of one organization's API key. API keys and access tokens work on them as before.
- `AuthenticateApiOrPlatformToken` checks a bearer token that starts with `flb_platform_` against the platform token and answers 401 if it is wrong; it is never tried as an API key. Any other credential goes to `AuthenticateOnceWithBasicAuth` unchanged.
- A request that authenticated with the platform token has no organization and no user. `PlatformApi::authenticated($request)` tells a controller which kind it is handling.
- New helpers: `PlatformApi::isPlatformToken()`, `PlatformApi::markAuthenticated()`, `PlatformApi::TOKEN_PREFIX`.
- **The platform token ships inside apps, so treat it as public.** Only put a route in this group if it is safe for anyone to call.

## Fixed

- **A second App Review type on the same model is read and changed as itself.** `AppReview::typeOf()` returns the first registered type whose model matches. Fleet-Ops registers an organization's Navigator app on `Company`, so any other type on `Company` (such as Fleet-Ops' customer apps) was always read, changed and checked as Navigator's.
- `accessFor()`, `isEnabledFor()`, `acceptsCode()`, `update()` and `status()` take an optional `?string $type` as their last argument. Left out, it is `typeOf($subject)`, so existing callers behave as before.
- A type registered for a different model never applies: `acceptsCode()` and `isEnabledFor()` answer false, `status()` reports no type, and `update()` throws.
- New `AppReview::resolveType($subject, $type)` gives the type a subject is checked as.
- The Console endpoint (`/int/v1/review-access/{type}/{id}`) and the OAuth endpoint (`/oauth/v1/review-access/{type}/{id}`) pass the route's `{type}` through, so each type keeps its own number, code and access row.
- **Requests carrying the platform token are rate limited per client address.** The limiter keys on the presented credential, and every installed app presents the same platform token, so they all shared one bucket: one busy or hostile client could lock every user out. An API key is still one bucket wherever it is sent from. The API consumers view lists these requests as **Platform token**.
- **A use of the platform token is written down at most once every five minutes.** `PlatformApi::markUsed()` saved `last_used_at` on every request, and each save clears the system settings cache.

## Upgrade Steps

- No migration. Extensions that register more than one type on the same model must pass the type to the calls above.
- No migration. `fleetbase.platform-api` and `fleetbase.api` are unchanged.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fleetbase/core-api",
"version": "2.0.5",
"version": "2.0.6",
"description": "Core Framework and Resources for Fleetbase API",
"keywords": [
"fleetbase",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

/**
* What a device is, so the people who support a driver can tell their phones
* apart: its name and model, its system, the app version on it, and when it
* was signed out of.
*/
return new class extends Migration {
protected array $columns = [
'name' => 191,
'model' => 191,
'manufacturer' => 191,
'os_version' => 64,
'app_version' => 64,
'app_build' => 64,
'locale' => 32,
'timezone' => 64,
];

public function up(): void
{
if (!Schema::hasTable('user_devices')) {
return;
}

Schema::table('user_devices', function (Blueprint $table) {
foreach ($this->columns as $column => $length) {
if (!Schema::hasColumn('user_devices', $column)) {
$table->string($column, $length)->nullable();
}
}
if (!Schema::hasColumn('user_devices', 'signed_out_at')) {
$table->timestamp('signed_out_at')->nullable();
}
});
}

public function down(): void
{
if (!Schema::hasTable('user_devices')) {
return;
}

Schema::table('user_devices', function (Blueprint $table) {
foreach (array_merge(array_keys($this->columns), ['signed_out_at']) as $column) {
if (Schema::hasColumn('user_devices', $column)) {
$table->dropColumn($column);
}
}
});
}
};
Loading
Loading