---
title: Authorizer
---

# Authorizer

<div class="documentation__toc"></div>

## Introduction

The `\Anomaly\Streams\Platform\Support\Authorizer` class allows you to easily add `permissions` logic to your application.
 
> By default the [users module](/docucmentation/users-module) handles permissions management.{.note}

## Basic Usage

### authorize

The `authorize` method allows you to authorize a `user` against a `permission` key. If no `user` is provided the currently logged in user will be used.

Permissions are generally hinted by their addon's `dot namespace` and formatted like `{namespace}::stream.action`.

> If a `permission` does not exist the authorizer will pass.{.notice}

```php
$authorizer = app(\Anomaly\Streams\Platform\Support\Authorizer::class);

if ($authorizer->authorize('anomaly.module.pages::pages.write', auth()->user())) {
    // Do something special.
}
 ```

### authorizeAll

The `authorizeAll` method allows you to authorize a `user` against all `permission` keys in the provided array. If no `user` is provided the currently logged in user will be used.

Permissions are generally hinted by their addon's `dot namespace` and formatted like `{namespace}::stream.action`.

> If no existing `permission` keys were passed the authorizer will pass.{.notice}

```php
$authorizer = app(\Anomaly\Streams\Platform\Support\Authorizer::class);

if ($authorizer->authorizeAll(array $permissions)) {
    // Do something special.
}
 ```

### authorizeRole

The `authorizeRole` method allows you to authorize a `user` against a `role`. If no `user` is provided the currently logged in user will be used.

```php
use Anomaly\Streams\Platform\User\Contract\RoleInterface;

$authorizer = app(\Anomaly\Streams\Platform\Support\Authorizer::class);

if ($authorizer->authorizeRole(RoleInterface $role, auth()->user())) {
    // Do something special.
}
 ```

### authorizeRoles

The `authorizeAnyRole` method allows you to authorize a `user` against any `roles` in a collection. If no `user` is provided the currently logged in user will be used.

```php
$authorizer = app(\Anomaly\Streams\Platform\Support\Authorizer::class);

if ($authorizer->authorizeRoles($roles)) {
    // Do something special.
}
 ```

### authorizeRoles

The `authorizeAnyRole` method allows you to authorize a `user` against any `roles` in a collection. If no `user` is provided the currently logged in user will be used.

```php
$authorizer = app(\Anomaly\Streams\Platform\Support\Authorizer::class);

if ($authorizer->authorizeRoles($roles)) {
    // Do something special.
}
 ```
