When to Use
Use client credentials when:- A third-party system or integration needs to read or write data (e.g. syncing schools from an external platform).
- You are building an embedded experience on an external website that calls your API on behalf of your organization.
- You need an “admin API” that external automation tools can call.
- The request does not involve an individual user’s context.
How It Works
App client authenticates
The external application sends its
client_id and client_secret to the token endpoint and receives an access token.Token is used for API requests
The token is attached to subsequent requests in the
Authorization header. The app client’s Spatie roles and permissions determine what the request can access.Setting Up
1. Create an App Client
In Developer → Apps, create a new app client with Client credentials as the grant type. See App Clients for the full setup steps.2. Assign Permissions
On the client’s Permissions tab, assign the roles and/or individual permissions that the integration should have. Only grant the minimum permissions required.3. Obtain an Access Token
The external application exchanges its credentials for an access token:4. Make Authenticated Requests
Use the token in theAuthorization header on any /api/v1/* route:
cURL
Defining API Routes
API routes are defined inroutes/api.php under the /v1 prefix using the CoreApiAuthenticate middleware, which accepts both client credentials tokens and user access tokens:
routes/api.php
Auth::guard('api')->client() to retrieve the authenticated app client (returns null for user tokens), or $request->user() for user tokens.
Permission Checks
Inside a controller, you can check the app client’s permissions using the sameGate and can() methods as for users: