PHPackages                             risan/laravel-auth-service - 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. risan/laravel-auth-service

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

risan/laravel-auth-service
==========================

Laravel stateful authentication service provider.

v1.1.0(10y ago)124MITPHP

Since Jan 4Pushed 10y ago1 watchersCompare

[ Source](https://github.com/risan/laravel-auth-service)[ Packagist](https://packagist.org/packages/risan/laravel-auth-service)[ Docs](https://github.com/risan/laravel-auth-service)[ RSS](/packages/risan-laravel-auth-service/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (4)Versions (3)Used By (0)

Laravel Authentication Service
==============================

[](#laravel-authentication-service)

[![Build Status](https://camo.githubusercontent.com/681bb164e927f776d2a7f682147cdf81b75a956d2e9b8661cc18f618f81f6b9d/68747470733a2f2f7472617669732d63692e6f72672f726973616e2f6c61726176656c2d617574682d736572766963652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/risan/laravel-auth-service)[![HHVM Status](https://camo.githubusercontent.com/07b8b73023ed6b567aa441cd4c1c3765f37716ddd56709ca576347e8fc316025/687474703a2f2f6868766d2e683463632e64652f62616467652f726973616e2f6c61726176656c2d617574682d736572766963652e7376673f7374796c653d666c6174)](http://hhvm.h4cc.de/package/risan/laravel-auth-service)[![StyleCI](https://camo.githubusercontent.com/844f858669d29258d7bde45051b0495324dcb9ab2ad19a9254facc8549c26ebd/68747470733a2f2f7374796c6563692e696f2f7265706f732f34383932393931382f736869656c643f7374796c653d666c6174)](https://styleci.io/repos/48929918)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/1aac1ae4f36fcc8107c8a31fac6d4432b61186918b5718cb92e1023756a0d000/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f726973616e2f6c61726176656c2d617574682d736572766963652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/risan/laravel-auth-service/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/2e008692ec7ba21123d6a73721de0c8b825bb5f9cdea158a4368fec6b9d6c95d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f726973616e2f6c61726176656c2d617574682d736572766963652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/risan/laravel-auth-service/?branch=master)[![SensioLabs Insight](https://camo.githubusercontent.com/ac02947b51214a4d71248e53d15443c0e0b0f5e6472a8f3ddaf447b7b61f2efa/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f61336134366532372d616362662d343138372d613062642d3632376136373265373338392e737667)](https://insight.sensiolabs.com/projects/a3a46e27-acbf-4187-a0bd-627a672e7389)[![Latest Stable Version](https://camo.githubusercontent.com/418685bf0fed4a3b29877eaabba334f0c9a0b8b0bbe73ef963fa4b54938737d4/68747470733a2f2f706f7365722e707567782e6f72672f726973616e2f6c61726176656c2d617574682d736572766963652f762f737461626c65)](https://packagist.org/packages/risan/laravel-auth-service)[![License](https://camo.githubusercontent.com/853ef47a83bd3c5c9db1e43129054d9c733f812bc7ba92ce84e7e96b0cd5d803/68747470733a2f2f706f7365722e707567782e6f72672f726973616e2f6c61726176656c2d617574682d736572766963652f6c6963656e7365)](https://packagist.org/packages/risan/laravel-auth-service)

Stateful authentication service provider for the latest Laravel 5.2 version.

Laravel already offers a handy way to provide user authentication functionality. Laravel framework ships with `AuthenticatesUsers` trait which can be injected to your authentication controller. And actually, by default the provided `AuthController` class are using this handy trait.

This package's intention is to replace the `AuthenticatesUsers` trait from your authentication controller. By extracting the authentication logic into a seperate service provider, your authentication controller will be a lot more clean and readable.

This package is only for the latest Laravel 5.2 version and only supports the `StatefulGuard` implementation.

Table of Contents
-----------------

[](#table-of-contents)

- [Dependencies](#dependencies)
- [Installation](#installation)
    - [Package Installation](#package-installation)
    - [Service Provider Registration](#service-provider-registration)
    - [Facade Registration](#facade-registration)
    - [Publish Configuration File](#publish-configuration-file)
- [Configuration](#configuration)
- [Available Methods](#available-methods)
    - [Login](#login)
    - [Logout](#logout)
- [Basic Usage](#basic-usage)
- [Implementation in AuthController](#implementation-in-authcontroller)
    - [Using Facade](#using-facade)
    - [Without Facade](#without-facade)

Dependencies
------------

[](#dependencies)

This package relies on the following libraries:

- [Illuminate/Routing](https://github.com/illuminate/routing)
- [Illuminate/Contracts](https://github.com/illuminate/contracts)

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

[](#installation)

### Package Installation

[](#package-installation)

To install this library using [Composer](https://getcomposer.org/), simply run the following command inside your Laravel project directory:

```
composer require risan/laravel-auth-service
```

Or you may also add `risan/laravel-auth-service` package into your `composer.json` file:

```
"require": {
  "risan/laravel-auth-service": "~1.1"
}
```

Once the dependency is added, run the install command:

```
composer install
```

### Service Provider Registration

[](#service-provider-registration)

Once the package has been installed, you need to register package's service provider. Open your `config/app.php` file, and add `AuthService\AuthServiceProvider::class` into your `providers` list like so:

```
'providers' => [
    ...
    AuthService\AuthServiceProvider::class,

],
```

### Facade Registration

[](#facade-registration)

If you would like to use facade to access this package, you need to register the `AuthService\Facades\AuthService::class` in `aliases` directive. Open up your `config/app.php` file, and update the `aliases` directive like so:

```
'aliases' => [
    ...
    'AuthService' => AuthService\Facades\AuthService::class,

],
```

This way, you may access the package functionality using `AuthService` facade.

### Publish Configuration File

[](#publish-configuration-file)

The last step to setup this package is to publish the configuration file. On your command prompt, run the following artisan command:

```
php artisan vendor:publish --provider="AuthService\AuthServiceProvider"
```

This command will copy a default package's configuration file in `config/authservice.php`.

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

[](#configuration)

Once the package's configuration file is published, you may locate the file in `config\authservice.php`. The default configuration file will look like this:

```
return [
    'auth_event_listener_class' => AuthService\AuthEventListener::class,
    'login_failed_message' => 'Credentials do not match.',
    'after_login_success_path' => 'protected',
    'after_logout_success_path' => 'login'
];
```

- **auth\_event\_listener\_class**

    This configuration tells the service provider which authentication event listener class to use. By default it will use the provided `AuthService\AuthEventListener` class. However you may also override it with your own event listener implementation as long as it confronts the `AuthService\Contracts\AuthEventListenerInterface` contract.
- **login\_failed\_message**

    This is the error message that will be used when user's credentials is invalid. By default this error message will be flashed out to the session if login is failed.
- **after\_login\_success\_path**

    This is the path where user will be redirected to if he/she successfully logged in.
- **after\_logout\_success\_path**

    This is the path where user will be redirected to if he/she logged out from application.

Available Methods
-----------------

[](#available-methods)

### Login

[](#login)

To log the user in, simply call the `login()` method:

```
AuthService::login(array $credentials, $remember = false);
```

This method will attempt to log the user in and will return an instance of `Illuminate\Http\RedirectResponse`.

### Logout

[](#logout)

To log the user out, we may use the `logout()` method:

```
AuthService::logout();
```

This method will also return an instance of `Illuminate\Http\RedirectResponse`.

Basic Usage
-----------

[](#basic-usage)

Here is some basic example to perform login and logout functionality, assuming that we are using the facade.

```
use AuthService;

// Log the user in.
$credentials = ['email' => 'john@example.com', 'password' => 'secret'];
AuthService::login($credentials);

// Log the user out.
AuthService::logout();
```

Implementation in AuthController
--------------------------------

[](#implementation-in-authcontroller)

For a complete implementation, we will create a simple authentication controller that handles the login and logout request.

### Using Facade

[](#using-facade)

```
namespace App\Http\Controllers\Auth;

use AuthService;
use App\Http\Controllers\Controller;
use App\Http\Requests\Auth\LoginRequest;

class AuthController extends Controller
{
    /**
     * Create a new authentication controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest', ['except' => 'getLogout']);
    }

    /**
     * Show the login page.
     *
     * @return Illuminate\Http\Response
     */
    public function getLogin()
    {
        return view('auth.login');
    }

    /**
     * Handle login request.
     *
     * @param  App\Http\Requests\Auth\LoginRequest $request
     * @return Illuminate\Http\Response
     */
    public function postLogin(LoginRequest $request)
    {
        $credentials = $request->only(['email', 'password']);

        return AuthService::login($credentials, $request->has('remember'));
    }

    /**
     * Log the user out.
     *
     * @return Illuminate\Http\Response
     */
    public function getLogout()
    {
        return AuthService::logout();
    }
}
```

### Without Facade

[](#without-facade)

```
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Http\Requests\Auth\LoginRequest;
use AuthService\Contracts\AuthServiceInterface;

class AuthController extends Controller
{
    protected $authService;

    /**
     * Create a new authentication controller instance.
     *
     * @return void
     */
    public function __construct(AuthServiceInterface $authService)
    {
        $this->middleware('guest', ['except' => 'getLogout']);

        $this->authService = $authService;
    }

    /**
     * Show the login page.
     *
     * @return Illuminate\Http\Response
     */
    public function getLogin()
    {
        return view('auth.login');
    }

    /**
     * Handle login request.
     *
     * @param  App\Http\Requests\Auth\LoginRequest $request
     * @return Illuminate\Http\Response
     */
    public function postLogin(LoginRequest $request)
    {
        $credentials = $request->only(['email', 'password']);

        return $this->authService->login($credentials, $request->has('remember'));
    }

    /**
     * Log the user out.
     *
     * @return Illuminate\Http\Response
     */
    public function getLogout()
    {
        return $this->authService->logout();
    }
}
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~65 days

Total

2

Last Release

3716d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3825242?v=4)[Risan Bagja Pradana](/maintainers/risan)[@risan](https://github.com/risan)

---

Top Contributors

[![risan](https://avatars.githubusercontent.com/u/3825242?v=4)](https://github.com/risan "risan (50 commits)")

---

Tags

laravelAuthenticationloginlogout

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/risan-laravel-auth-service/health.svg)

```
[![Health](https://phpackages.com/badges/risan-laravel-auth-service/health.svg)](https://phpackages.com/packages/risan-laravel-auth-service)
```

###  Alternatives

[auth0/login

Auth0 Laravel SDK. Straight-forward and tested methods for implementing authentication, and accessing Auth0's Management API endpoints.

2745.0M3](/packages/auth0-login)[maize-tech/laravel-magic-login

Laravel Magic Login

1808.1k](/packages/maize-tech-laravel-magic-login)[alajusticia/laravel-logins

Session management in Laravel apps, user notifications on new access, support for multiple separate remember tokens, IP geolocation, User-Agent parser

2011.0k](/packages/alajusticia-laravel-logins)

PHPackages © 2026

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