PHPackages                             faaren-tech/faaren-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. faaren-tech/faaren-sdk

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

faaren-tech/faaren-sdk
======================

A sdk to interact with our authorization service

2.6.0(3y ago)05.2k↓33.3%MITPHP

Since Feb 16Pushed 3y ago4 watchersCompare

[ Source](https://github.com/FAAREN-tech/faaren-sdk)[ Packagist](https://packagist.org/packages/faaren-tech/faaren-sdk)[ RSS](/packages/faaren-tech-faaren-sdk/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (28)Used By (0)

FAAREN SDK
==========

[](#faaren-sdk)

Installation
------------

[](#installation)

```
composer require faaren-tech/faaren-sdk

// choose FaarenTech/AuthSdk/AuthSdkServiceProvider
php artisan vendor:publish
```

Customize the `service_url` parameter in config `auth-sdk.php` or set the value `FAAREN_AUTH_SERVICE_URL` in your `.env` file.

Usage
-----

[](#usage)

> Important! If you use this library in a docker context `FAAREN_AUTH_SERVICE_URL` has to be the IP address of your machine. Otherwise it will try to find a host in its own docker network. As an alternative you can add an `external_hosts` option to your docker-compose-container.

You can use the package everywhere by simply initializing it:

```
use FaarenTech\FaarenSDK\FaarenSdk;

class SomeClass {

    public function someFunction()
    {
        $sdk = FaarenSdk::init("yourApiToken");
        $token = $sdk->apiToken()->details();
        $permissions = $sdk->apiToken()->permissions();
    }

}
```

The Token-Object contains the following details, for example:

```
{
    "uuid": "tok_22j8HPsYoOKXEMIPHNpHQeBdhKFP",
    "subsidiary_uuid": "subsi_3mz4r520mPr770ZUYtCRdJtFHz",
    "user_uuid": "null OR user_uuid",
    "name": "null OR name",
    "type": "APP_TOKEN OR PERSONAL_TOKEN",
    "permissions": [
        "user:delete",
        "apiToken:create",
        "apiToken:read",
        "apiToken:list",
        "user:update"
    ],
    "plainTextToken": "55|mySecretToken"
}
```

The listed permissions, subsidiary\_uuid and user\_uuid can be used to make your app-specific authorization.

### Notifications

[](#notifications)

#### Mailings

[](#mailings)

You can simply trigger notifications via the Notification Service:

```
use FaarenTech\FaarenSDK\FaarenSdk;

class SomeClass {

    public function someFunction()
    {
        $sdk = FaarenSdk::init("yourApiToken");
        $mailing = $sdk
            ->notification()
            ->mail()
            ->setMailing('example')
            ->setMailData([
                "to" => "fabian@faaren.com",
                "from" => "example@faaren.com",
                "bcc" => "it@faaren.com",
                "whitelabel_config" => [
                    "foo" => "bar"
                ]
            ])
            ->send();
    }

}
```

If an error occurs while calling the Notification Service, a `\FaarenTech\FaarenSDK\Exceptions\NotificationServiceException` is thrown. The exception message will contain a hint what was going wrong, e.g. an validation error:

> "message": "Status 422: Notification could not be sent because: The to field is required.",

The used tokens and endpoints can be customized via you `.env` file. The available keys are listed in `/config/faaren-sdk.php` within the vendor directory or, if you have published the config, in your applications config-folder.

### Middlewares

[](#middlewares)

#### [AcceptsJsonMiddleware](src/Http/Middleware/AcceptsJsonMiddleware.php)

[](#acceptsjsonmiddleware)

#### [HasValidTokenMiddleware](src/Http/Middleware/HandleAppTokenMiddleware.php)

[](#hasvalidtokenmiddleware)

You can add the middleware group `faaren` to all routes you like. This middleware group contains the following middlewares:

- [HasValidTokenMiddleware](src/Http/Middleware/HandleAppTokenMiddleware.php) =&gt; Checks if the given token is valid and attaches the token details to the current request. The details are available with `$request->api_token`.

Using this middleware makes it easy to work with tokens. You can access the token details everywhere via the request object:

```
// Route
// Assign middleware
Route::middleware('faaren')
    ->get('/your-endpoint', [SomeController::class, 'someAction']);

// Access in SomeController.php
class SomeController {
    public function someAction(\Illuminate\Http\Request $request)
    {
        // The provided api token is valid
        // The ApiToken can be accessed via
        $token = $request->api_token;
    }
}

// Access in SomeFormRequest.php
class SomeFormRequest extends \Illuminate\Foundation\Http\FormRequest {
    public function authorize()
    {
        $token = $this->api_token;
    }
}

// Or everywhere via request() helper
```

### Form Requests

[](#form-requests)

This package provides a BaseRequest, the `FaarenRequest`. This Request implementes the `Illuminate\Contracts\Auth\Access\Authorizable` via the `Illuminate\Foundation\Auth\Access\Authorizable` trait. It can be used for any FormRequest you will create in your service.

This way it is possible to authorize incoming requests directly in your form request:

```
use FaarenTech\FaarenSDK\Request\FaarenRequest;

class YourRequest extends FaarenRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return $this->can('index', SomeModel::class);
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            //
        ];
    }
}
```

In your policy you won't pass in an instance of your User. Instead you pass in an instance of your form request. The underlying policy:

```
class YourPolicy
{
    use HandlesAuthorization;

    public function index(TemplateIndexRequest $request)
    {
        // Here you can access the methods from the FaarenRequest
        // Access the AppToken via $request->api_token;
        return true;
    }

    public function show(TemplateIndexRequest $request, SomeModel $someModel)
    {
        return true;
    }
}
```

### Define Resources

[](#define-resources)

Since version 1.1.0 we use "ResponseCollection" and "ResourceCollection" in our Resource-definitions.

To use your own Resource with our Schema, you need to extend your Resource from "ResponseResource" and not from "JsonResource" Then you need to change your "toArray" method to "toPayload" Example:

```
class YourAwesomeResource extends ResponseResource
{
    /**
     * @return array[]
     */
    public function toPayload()
    {
        return [
            'awesome' => true
        ];
    }
}
```

#### Resource Collection:

[](#resource-collection)

So your Resource gets mapped as YourAwesomeResourceCollection

```
class YourAwesomeResourceCollection extends \FaarenTech\FaarenSDK\Resources\ResponseCollection
{
    public $collects = YourAwesomeResource::class;
}
```

### Validation as Json in our Response-Schema

[](#validation-as-json-in-our-response-schema)

Your class needs to be extend from "FaarenRequest", and every validation error uses the schema

```
use FaarenTech\FaarenSDK\Request\FaarenRequest;

class ShowVehiclePoolRequest extends FaarenRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            //
        ];
    }

}
```

### Handle Exceptions as Json

[](#handle-exceptions-as-json)

Simple add the [AcceptsJsonMiddleware](src/Http/Middleware/AcceptsJsonMiddleware.php) to the relevant middleware groups or as a global middleware.

> Using the custom [Handler](src/Exceptions/Handler.php) is deprecated and will cause errors when you use it!

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~11 days

Recently: every ~44 days

Total

21

Last Release

1318d ago

Major Versions

1.1.3 → 2.0.02022-02-22

### Community

Maintainers

![](https://www.gravatar.com/avatar/4288116c61a0cee2d1e7417272fba4c6002a941dc7b645fe366edcbdce56182e?d=identicon)[faaren](/maintainers/faaren)

---

Top Contributors

[![domacs](https://avatars.githubusercontent.com/u/2152330?v=4)](https://github.com/domacs "domacs (18 commits)")[![Brotzka](https://avatars.githubusercontent.com/u/9106911?v=4)](https://github.com/Brotzka "Brotzka (15 commits)")[![busaku](https://avatars.githubusercontent.com/u/25269085?v=4)](https://github.com/busaku "busaku (4 commits)")[![dwyschka](https://avatars.githubusercontent.com/u/25348338?v=4)](https://github.com/dwyschka "dwyschka (4 commits)")[![FlorianLauterbach](https://avatars.githubusercontent.com/u/94018411?v=4)](https://github.com/FlorianLauterbach "FlorianLauterbach (1 commits)")

### Embed Badge

![Health badge](/badges/faaren-tech-faaren-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/faaren-tech-faaren-sdk/health.svg)](https://phpackages.com/packages/faaren-tech-faaren-sdk)
```

###  Alternatives

[namshi/jose

JSON Object Signing and Encryption library for PHP.

1.8k99.6M101](/packages/namshi-jose)[league/oauth1-client

OAuth 1.0 Client Library

99698.8M106](/packages/league-oauth1-client)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[league/oauth2-google

Google OAuth 2.0 Client Provider for The PHP League OAuth2-Client

41721.2M117](/packages/league-oauth2-google)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)[beatswitch/lock

A flexible, driver based Acl package for PHP 5.4+

870304.7k2](/packages/beatswitch-lock)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
