Skip to content

Auth

The SDK does two jobs: it signs users in against the platform’s OIDC server, and it authorises them with the vocabulary Laravel developers already use (can, @can, hasRole, policies), backed by FlowCatalyst roles and permissions. It also validates bearer tokens on API routes, for users and for service accounts alike. The model behind it is described in Tokens and Permissions and roles; the language-neutral walk-through is OIDC login.

A fresh Laravel application needs only configuration:

FLOWCATALYST_BASE_URL=https://your-instance.example.com
FLOWCATALYST_OIDC_ENABLED=true
FLOWCATALYST_NATIVE_LOGIN=true
FLOWCATALYST_OIDC_CLIENT_ID=your_oauth_client_id
FLOWCATALYST_OIDC_CLIENT_SECRET=your_oauth_client_secret
FLOWCATALYST_OIDC_SCOPE="openid profile email offline_access"
routes/web.php
Route::middleware('auth')->group(function () {
Route::get('/dashboard', DashboardController::class);
});

With FLOWCATALYST_NATIVE_LOGIN=true, a guest reaching an auth route is redirected into the FlowCatalyst login flow. The bridge is opt-in so the SDK never changes an existing application’s authentication behaviour. If your application defines its own login route, that route wins. Turn off just the redirect with FLOWCATALYST_OIDC_AUTO_GUEST_REDIRECT=false.

The SDK registers four routes (names are flowcatalyst.login, .callback, .logout and .refresh): /flowcatalyst/login, /flowcatalyst/callback, /flowcatalyst/logout and /flowcatalyst/refresh. On the platform, create an OAuth client with the authorization_code grant and the redirect URI https://your-app.example.com/flowcatalyst/callback. It must match exactly, including scheme, host, port, and localhost versus 127.0.0.1. The flow uses PKCE.

sequenceDiagram
  participant B as Browser
  participant A as Laravel app
  participant P as Platform
  B->>A: GET /dashboard (guest)
  A-->>B: redirect /flowcatalyst/login
  B->>P: /oauth/authorize (PKCE)
  P-->>B: sign-in page, then redirect with code
  B->>A: GET /flowcatalyst/callback?code=...
  A->>P: POST /oauth/token (code + verifier)
  P-->>A: id_token, access_token, refresh_token
  A-->>B: session established, redirect after login

Once authenticated, the user speaks the Spatie vocabulary. Wildcards in granted permissions are honoured (orders:*:*:* satisfies orders:admin:order:cancel).

$user->hasPermissionTo('orders:admin:order:cancel');
$user->hasRole('orders:admin');
$user->can('orders:admin:order:cancel'); // Gate, @can and policies route here
@can('orders:admin:order:cancel')
<button>Cancel order</button>
@endcan

Permission strings have four parts, application:context:aggregate:action. Role names are prefixed with their application code (orders:admin). See Permissions for how to declare them.

For FlowCatalyst identities the SDK installs a Gate::before hook that answers true when the principal holds the permission and otherwise defers to your policies.

Stateless (default) Local sync
Local users row none upserted by email on login
spatie/laravel-permission not needed used; roles and permissions mirrored
Permissions come from the token’s scope claim local Spatie tables
Auth::user() FlowCatalystAuthenticatable via fc-session / fc-token your Eloquent model via web
Enable FLOWCATALYST_OIDC_HANDLER=session FLOWCATALYST_OIDC_HANDLER=database

If FLOWCATALYST_OIDC_HANDLER is unset, the handler is database when FLOWCATALYST_NATIVE_LOGIN is on and session otherwise.

No migrations, no Spatie, nothing to keep in step: the access token already carries the granted permissions.

FLOWCATALYST_OIDC_HANDLER=session
FLOWCATALYST_OIDC_PERMISSION_RESOLVER=token # default; or api_me
  • Browser routes: ->middleware('auth:fc-session'), or make fc-session your default guard.
  • API routes (user and client_credentials tokens): ->middleware('auth:fc-token').

Both resolve a read-only FlowCatalystAuthenticatable with no database access. With api_me, permissions are fetched from GET /api/me (one HTTP call, cached for FLOWCATALYST_OIDC_ME_CACHE_TTL seconds, 60 by default) so changes show up sooner; it fails closed (no permissions) on any error.

The principal exposes more than permissions:

Method Meaning
hasRole, hasAnyRole, hasAllRoles, getRoleNames Role checks on the token’s roles.
hasPermissionTo, hasAnyPermission, hasAllPermissions, getPermissionNames Permission checks with wildcards.
getApplications, hasApplicationAccess($code) Applications the principal may use.
getClients, hasClientAccess($clientId), hasFullAccess() Client scope. hasFullAccess() is true for an anchor with all clients.
fcUser() The underlying FlowCatalystUser (claims such as getTier(), isAnchor()).
assignRole, givePermissionTo, removeRole, revokePermissionTo Always throw: roles are managed on the platform.
FLOWCATALYST_OIDC_HANDLER=database
FLOWCATALYST_OIDC_USER_MODEL="App\Models\User"

On login the SDK upserts the user by email, calls Auth::login(), and, if the model uses Spatie’s HasRoles trait, mirrors the token’s roles and each role’s permissions into the local tables. Role permissions are fetched with the service account (GET /api/roles/{role}) and cached per role for FLOWCATALYST_OIDC_ROLE_PERMISSIONS_CACHE_TTL seconds; that step is skipped silently if no service account is configured.

FLOWCATALYST_OIDC_SYNC_ROLES=true
FLOWCATALYST_OIDC_SYNC_ROLES_MODE=additive # or replace, to be authoritative
FLOWCATALYST_OIDC_SYNC_ROLE_PERMISSIONS=true
FLOWCATALYST_OIDC_CREATE_MISSING_ROLES=false
FLOWCATALYST_OIDC_ROLES_GUARD=web

If you store sessions in the database, run php artisan flowcatalyst:session-table once to widen sessions.user_id to a string, because FlowCatalyst principal ids are not integers.

The service provider registers these aliases and guards.

Name Behaviour
auth:fc-token Authenticates a bearer token (user or client_credentials); 401 otherwise. Stack guards to fall through, for example auth:fc-token,api.
auth:fc-session Authenticates the OIDC session principal.
fc.auth Resolves the principal (bearer wins over session) into $request->attributes['fc.principal']. Never rejects.
fc.bearer 401 JSON ({"error":"unauthorized"}) when nothing resolved. For API routes.
fc.session Redirects to /flowcatalyst/login?returnTo=... when nothing resolved. For web routes.
fc.any Either mechanism. On a miss, browser navigations are redirected to login and everything else gets 401 JSON.
fc.or-passport A FlowCatalyst token, or a legacy fallback chain.
fc.field Field-worker DPoP requests. See Field.
fc-signature, flowcatalyst.webhook Inbound delivery signatures. See Webhooks.

fc.bearer, fc.session and fc.any read the attribute set by fc.auth, so they go after it:

Route::middleware(['fc.auth', 'fc.bearer'])->get('/api/orders', OrdersController::class);

Migrating from Passport client credentials

Section titled “Migrating from Passport client credentials”

fc.or-passport lets one route accept FlowCatalyst service-account tokens while still honouring existing Passport machine tokens. A valid FlowCatalyst token wins and the fallback never runs. Anything else flows through the configured chain as if the middleware were absent.

config/flowcatalyst.php
'oidc' => [
'token_fallback_middleware' => ['client', 'passport.app.identity'],
],
Route::post('/api/stock-sync', $handler)->middleware('fc.or-passport');

An empty list means FlowCatalyst-only: unauthenticated requests pass through untouched so a downstream guard decides. Once the last Passport caller has moved, switch the route to auth:fc-token.

In stateless mode permissions live in a short-lived access token and go stale when roles change. POST /flowcatalyst/refresh (route('flowcatalyst.refresh')) uses the stored refresh token to mint a new access token and re-store the principal. It needs offline_access in the scope.

<form method="POST" action="{{ route('flowcatalyst.refresh') }}">
@csrf
<button type="submit">Refresh permissions</button>
</form>

A session principal is also capped to its access token’s real expiry and refreshed silently FLOWCATALYST_OIDC_SESSION_REFRESH_LEEWAY seconds before it. Set FLOWCATALYST_OIDC_CHECK_REVOCATION=true to ask the platform whether the session is still valid, cached for FLOWCATALYST_OIDC_REVOCATION_CACHE_TTL seconds (clamped to 5 to 600).

Sending users to a specific provider or brand

Section titled “Sending users to a specific provider or brand”
Setting Effect
FLOWCATALYST_OIDC_PROVIDER=idp_... Send logins straight to a named upstream identity provider. A ?provider= query parameter overrides it per request.
FLOWCATALYST_OIDC_CLIENT=<identifier> Brand the sign-in pages with that client’s login theme. A ?client= parameter overrides it. Cosmetic only; ignored in portal mode.
FLOWCATALYST_OIDC_SINGLE_LOGOUT=true Log out of the platform session too, not just the application.

Bind your own OidcUserHandler. A binding in your container always wins over the SDK default.

// AppServiceProvider::register()
$this->app->bind(\FlowCatalyst\Auth\Contracts\OidcUserHandler::class, MyHandler::class);

The interface has four methods:

use FlowCatalyst\Auth\Contracts\OidcUserHandler;
use FlowCatalyst\Auth\DTOs\FlowCatalystUser;
final class MyHandler implements OidcUserHandler
{
public function handleAuthenticatedUser(FlowCatalystUser $user): mixed
{
// $user->sub, ->email, ->name; ->getRoles(), ->getClientIds() ...
return $user;
}
public function handleLogout(): void { session()->flush(); }
public function getPostLoginRedirect(): string { return '/'; }
public function getPostLogoutRedirect(): string { return '/'; }
}

Extend DatabaseOidcUserHandler to keep the upsert and login and override only what you need.

The token guard turns a token into permission codes with a PermissionResolver. Precedence: a resolver you bind, then a bound RbacCatalogue (offline), then the configured default (token, reading the scope claim, or api_me). See Permissions.

Situation Result
No or invalid bearer token on auth:fc-token / fc.bearer 401
Guest on a web route with the bridge on Redirect into /flowcatalyst/login
OIDC callback failure Redirect to FLOWCATALYST_ERROR_REDIRECT (default /)
Token with token_use other than api or identity (for example a field token) Refused by the fc-token guard

Use FlowCatalyst\Testing\FlowCatalystTestPrincipal and InteractsWithFlowCatalyst::actingAsFlowCatalyst() to act as a principal without a real login. See Testing.