PHPackages                             raid/core-auth - 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. raid/core-auth

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

raid/core-auth
==============

Raid Core Auth Package

098PHP

Since Oct 6Pushed 2y ago1 watchersCompare

[ Source](https://github.com/MohamedKhedr700/core-auth)[ Packagist](https://packagist.org/packages/raid/core-auth)[ RSS](/packages/raid-core-auth/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (4)Used By (0)

Core Auth Package
=================

[](#core-auth-package)

This package is responsible for handling all authentication models and channels in the system.

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

[](#installation)

```
composer require raid/core-auth
```

Configuration
-------------

[](#configuration)

```
php artisan core:publish-auth
```

Usage
-----

[](#usage)

```
class AuthController extends Controller
{
    /**
     * Invoke the controller method.
     */
    public function __invoke(Request $request, SystemAuthChannel $authChannel): JsonResponse
    {
        $credentials = $request->only([
            'email', 'phone', 'username', 'password',
        ]);

        $authChannel = $authChannel->authenticate(new User(), $credentials);

        // or using static call
        $authChannel = SystemAuthChannel::auth(User::class, $credentials);

        // or using facade
        $authChannel = Authentication::authenticate(new User(), $credentials);

        return response()->json([
            'channel' => $authChannel->channel(),
            'token' => $authChannel->stringToken(),
            'errors' => $authChannel->errors()->toArray(),
            'resource' => $authChannel->account(),
        ]);
    }
}
```

How to work this
================

[](#how-to-work-this)

The authentication process is divided into two parts.

The first part is the authenticatable class, and the second part is the auth channel.

The `Authenticatable` class is the class that will be authenticated, and it must implement `AuthenticatableInterface` interface.

The `AuthChannel` class is the class that will handle the authentication process, and it must implement `AuthChannelInterface` interface.

The `AuthChannel` uses the `Authenticatable` class to query the account using the given credentials.

The `Authenticatable` class must define `getAccount` method to query the account, and return an instance of `AccountInterface` interface.

The `Authenticatable` class can be the same or different from the `AccountInterface` class, but it must query the account and return an instance of `AccountInterface` interface if found.

Let's start with our `AccountInterface` class ex:`User` model, we can use this command to create an account model.

```
php artisan core:make-auth-model User
```

```
