2017 © Pedro Peláez
 

library token-auth

A simple token based authentication guard for Laravel 5.4

image

iget-master/token-auth

A simple token based authentication guard for Laravel 5.4

  • Wednesday, February 22, 2017
  • by iget-master
  • Repository
  • 3 Watchers
  • 11 Stars
  • 686 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Laravel 5.2 - Token-based Guard

Using this guard, you can login your user like the default Laravel session guard, but the authorization will be persisted using a token passed through Authorization HTTP Header., (*1)

Installation

  1. Require iget-master/token-auth on composer
  2. Add the IgetMaster\TokenAuth\TokenAuthServiceProvider::class services provider on app.php configuration file.
  3. Change your guard driver to iget-token on auth.php

Usage

As on Laravel's default session guard, you must use Auth::attempt using the user credentials to try to login. If successful, you can use Auth::getToken() to get the 16 characters random Authorization Token., (*2)

On subsequent requests, the user should pass a Authorization http header with this token. If the token is valid, the user will be authenticated and you will be able to get current user using Auth::user()., (*3)

If you are using the Laravel's default AuthController, you must update it, since you should send to the user the Authorization Token. Here is an example of AuthController@getLogin method:, (*4)

/**
 * @param \Request $request
 * @return \Illuminate\Http\JsonResponse
 */
public function getLogin(Request $request)
{
    $success = false;

    if (Auth::attempt($request->only(['email', 'password']))) {
        $success = true;
        $token = Auth::getToken();
        $user_id = Auth::user()->id;
    }

    return response()->json(compact('success', 'token', 'user_id'));
}

Remember to include the Request class at top of your controller class:, (*5)

use Illuminate\Http\Request;

You should change session.lifetime configuration to change the token's lifetime., (*6)

The Versions

22/02 2017

dev-L5.4

dev-L5.4

A simple token based authentication guard for Laravel 5.4

  Sources   Download

The Requires

 

by Elias Soares

22/02 2017

v2.0.0

2.0.0.0

A simple token based authentication guard for Laravel 5.4

  Sources   Download

The Requires

 

by Elias Soares

03/06 2016

dev-master

9999999-dev

A simple token based authentication guard for Laravel 5.2

  Sources   Download

The Requires

 

by Elias Soares

03/06 2016

v1.1.2

1.1.2.0

A simple token based authentication guard for Laravel 5.2

  Sources   Download

The Requires

 

by Elias Soares

03/06 2016

v1.1.1

1.1.1.0

A simple token based authentication guard for Laravel 5.2

  Sources   Download

The Requires

 

by Elias Soares

03/06 2016

v1.1.0

1.1.0.0

A simple token based authentication guard for Laravel 5.2

  Sources   Download

The Requires

 

by Elias Soares

06/01 2016

v1.0.0

1.0.0.0

A simple token based authentication guard for Laravel 5.2

  Sources   Download

The Requires

 

by Elias Soares