2017 © Pedro Peláez
 

library authen

User Authentication Identifiers for Laravel

image

laravie/authen

User Authentication Identifiers for Laravel

  • Saturday, July 28, 2018
  • by crynobone
  • Repository
  • 1 Watchers
  • 37 Stars
  • 11,626 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 11 Versions
  • 17 % Grown

The README.md

User Authentication Identifiers for Laravel

tests Latest Stable Version Total Downloads Latest Unstable Version License Coverage Status, (*1)

Imagine you need to login a user with either "email", "username" or "phone number" just like how Facebook allows it. This is not possible with Laravel since you're limited to only one unique username/identifier key. This package attempt to solve the issue by allowing to use a unified key "identifier" and you can customize which attributes Laravel should check during authentication., (*2)

Installation

To install through composer, run the following command from terminal:, (*3)

composer require "laravie/authen"

Usages

Service Provider

First you can attach the auth provider on App\Providers\AuthServiceProvider:, (*4)

<?php

namespace App\Providers;

use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Laravie\Authen\BootAuthenProvider;

class AuthServiceProvider extends ServiceProvider
{
    use BootAuthenProvider;

    /**
     * Register any authentication / authorization services.
     *
     * @return void
     */
    public function boot()
    {
        $this->registerPolicies();

        $this->bootAuthenProvider();
    }
}

User Model

Secondly, you need to update the related App\User (or the eloquent model mapped for auth)., (*5)

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravie\Authen\AuthenUser;

class User extends Authenticatable
{
    use Notifiable, AuthenUser;

    /**
     * Get the name of the unique identifier for the user.
     *
     * @return array<int, string>
     */
    public function getAuthIdentifiersName()
    {
        return ['email', 'username', 'phone_number'];
    }
}

With this setup, you can now check either email, username or phone_number during authentication., (*6)

Configuration

Lastly, you need to update the config config/auth.php:, (*7)

<?php

return [

    // ...

    'providers' => [
        'users' => [
            'driver' => 'authen',
            'model'  => App\User::class,
        ],
    ],

    // ...
];

Examples

Here's an example how to login., (*8)

<?php 

use Illuminate\Support\Facades\Auth;
use Laravie\Authen\Authen;

$data = [Authen::getIdentifierName() => 'crynobone@gmail.com', 'password' => 'foobar'];

if (Auth::attempt($data)) {
    // you can logged in, you can also pass your phone number of username to `identifier`.
}

The Versions

28/07 2018

dev-master

9999999-dev

User Authentication Identifiers for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

30/04 2018

v2.1.0

2.1.0.0

User Authentication Identifiers for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

13/11 2017

v2.0.0

2.0.0.0

User Authentication Identifiers for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

10/11 2017

v2.0.0-BETA1

2.0.0.0-beta1

User Authentication Identifiers for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

08/02 2017
15/12 2016

v1.0.0

1.0.0.0

User Authentication Identifiers for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

30/11 2016

v0.3.0

0.3.0.0

User Authentication Identifiers for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

29/11 2016

v0.2.1

0.2.1.0

User Authentication Identifiers for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

27/11 2016

v0.2.0

0.2.0.0

User Authentication Identifiers for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

24/11 2016

v0.1.1

0.1.1.0

User Authentication Identifiers for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

23/11 2016

v0.1.0

0.1.0.0

User Authentication Identifiers for Laravel

  Sources   Download

MIT

The Requires