> For the complete documentation index, see [llms.txt](https://docs.opensoutheners.com/home/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.opensoutheners.com/home/laravel-scim/authorization.md).

# Authorization

The package uses Laravel's Gate system for authorization. Every SCIM operation checks a gate before proceeding.

## Gate abilities

| Operation       | Gate ability           | Extra arguments |
| --------------- | ---------------------- | --------------- |
| List resources  | `scim.{table}.viewAny` | -               |
| Get resource    | `scim.{table}.view`    | `[$id]`         |
| Create resource | `scim.{table}.create`  | -               |
| Update resource | `scim.{table}.update`  | `[$id]`         |
| Delete resource | `scim.{table}.delete`  | `[$id]`         |

The `{table}` is the model's database table name. For example, a `User` model with table `users` produces abilities like `scim.users.create`.

## Defining gates

In your `AuthServiceProvider` or `AppServiceProvider`:

```php
use Illuminate\Support\Facades\Gate;

// Allow all SCIM operations for any authenticated user
Gate::before(function ($user, $ability) {
    if (str_starts_with($ability, 'scim.')) {
        return true;
    }
});
```

Or define specific abilities:

```php
Gate::define('scim.users.viewAny', function ($user) {
    return $user->hasRole('scim-admin');
});

Gate::define('scim.users.create', function ($user) {
    return $user->hasRole('scim-admin');
});

Gate::define('scim.groups.viewAny', function ($user) {
    return $user->hasRole('scim-admin');
});

// ... etc
```

## Authorization order

Authorization is checked **before** request validation and model construction. This means:

1. Request comes in
2. Gate check runs (against the authenticated user)
3. If denied, a 403 response is returned immediately
4. If allowed, request validation and schema processing proceed

This avoids wasted work for unauthorized requests.

## Authentication

The package does not handle authentication itself. You should configure auth middleware in `config/scim.php`:

```php
'middleware' => ['auth:sanctum'],
```

The authenticated user from your middleware is the one passed to Gate checks.

{% hint style="warning" %}
If no middleware is configured and no user is authenticated, Gate checks will receive `null` as the user, which typically denies all operations. Always configure authentication middleware for SCIM endpoints.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.opensoutheners.com/home/laravel-scim/authorization.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
