2017 © Pedro Peláez
 

library laravel-api-auth

Dead simple Laravel api authorization middleware

image

erjanmx/laravel-api-auth

Dead simple Laravel api authorization middleware

  • Tuesday, June 5, 2018
  • by erjanmx
  • Repository
  • 1 Watchers
  • 3 Stars
  • 337 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 6 Versions
  • 116 % Grown

The README.md

Build Status Latest Stable Version Total Downloads, (*1)

Laravel Api Auth

Laravel gives easy ways to handle api authorization using user based tokens, but sometimes you need to use a single token to give access to your application, especially when you're developing two apps that need to be connected, or perhaps you're in need of connecting Telegram-bot to your app endpoint using webhooks, (*2)

Laravel-api-auth makes that easy as breathe, no migrations, no models, (*3)

Installing package

If you're using Laravel prior to 5.5, consider using v0.1 branch, (*4)

$ composer require erjanmx/laravel-api-auth

Publish the Package configuration, (*5)

$ php artisan vendor:publish --provider="Apiauth\Laravel\CAuthServiceProvider"

Using package

Step 1

Change defaults in config/apiauth.php, (*6)

<?php

return [
    'services' => [

        'MY_APP' => [                          // this is the name of the middleware of route group to be protected
            'tokenName' => 'api_token',        // name of key that will be checked for secret value
            'token' => env('MY_APP_TOKEN'),    // secret value that is retrieved from env vars and needs to be passed in requests in order to get access to your protected urls

            'allowJsonToken' => true,        
            'allowBearerToken' => true,        
            'allowRequestToken' => true,       
        ]
    ],
];

Step 2

  • Add your secret value in .env file
// .env

...your other variables

MY_APP_TOKEN=my-secret

Step 3

  • Add group with middleware in your routes file

Route::group(['prefix' => 'api', 'middleware' => ['apiauth:MY_APP']], function () { // note the `MY_APP` that should match the name in your config we changed above Route::any('/', function () { return 'Welcome!'; }); });

That's it

Your urls within your group are accessible only if valid token provided, (*7)

  • In GET or POST request

image image, (*8)

  • In request header as Authorization Bearer (tokenName is ignored in this case)

image, (*9)

  • In json raw body

image, (*10)

You're free to change token name (api_token by default) in configuration file as well as authorization methods to be checked. Also you can set as many services as you want., (*11)

The Versions

05/06 2018

dev-master

9999999-dev

Dead simple Laravel api authorization middleware

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar erjanmx
by erjanmx-onlinesup

laravel api middleware auth token

05/06 2018

v1.0.1

1.0.1.0

Dead simple Laravel api authorization middleware

  Sources   Download

MIT

The Development Requires

by Avatar erjanmx

laravel api middleware auth token

10/01 2018

v1.0

1.0.0.0

Dead simple Laravel api authorization middleware

  Sources   Download

MIT

The Development Requires

by Avatar erjanmx

laravel api middleware auth token

10/01 2018

dev-package-autodiscovery

dev-package-autodiscovery

Dead simple Laravel api authorization middleware

  Sources   Download

MIT

The Development Requires

by Avatar erjanmx

laravel api middleware auth token

05/07 2017

v0.1.x-dev

0.1.9999999.9999999-dev

Dead simple Laravel api authorization middleware

  Sources   Download

MIT

The Development Requires

by Avatar erjanmx

laravel api middleware auth token

27/06 2017

v0.1

0.1.0.0

Auth

  Sources   Download

MIT

The Development Requires

by Avatar erjanmx