laradevs/authremote

It is a component that allows to carry out and manage the authentication control through OAUTH2.0 for a Laravel application.

v1.1 2020-04-13 17:17 UTC

This package is auto-updated.

Last update: 2024-04-14 04:33:13 UTC


README

51764637?s=200&v=4

AUTH REMOTE

It is a component that allows to carry out and manage the authentication control through OAUTH2.0 for a Laravel application.

Installation

You can install the package via composer :

$ composer require laradevs/authremote

Next, You must register the service provider (optional) :

// config/app.php

'Providers' => [
   // ...
    \LaraDevs\AuthRemote\MainServiceProvider::class,
]

Next, you must publish the configuration file to define the OAUTH server credentials:

php artisan vendor:publish --provider="LaraDevs\AuthRemote\MainServiceProvider"

This is the contents of the published file :

return [
    'uri' => env('USER_PROVIDER_REST_URL', ''),
    'name_session_rest' => 'token_oauth',
    'headers' => [],
    'route_not_session'=>'start_route'
];

Set your URL Rest in .env file :

APP_NAME="Laravel"
# ...
USER_PROVIDER_REST_URL=putYourRestURL

Add in Array Services

'laravelpassport' => [
        'client_id' => env('LARAVELPASSPORT_KEY','http://YOUR_ROUTE_HOST_SERVER/api/user'),
        'client_secret' => env('LARAVELPASSPORT_SECRET'),
        'redirect' => env('LARAVELPASSPORT_REDIRECT_URI'),
        'host'=> env('LARAVELPASSPORT_HOST')
    ]

Add in Handle Exception in method render

 if ($exception instanceof \LaraDevs\AuthRemote\RestException) {
            return redirect()->route(config('rest-provider.route_not_session'));
 }

Add in Array Auth

  'providers' => [
        'users' => [
            'driver' => 'rest-users',
            'model' => \LaraDevs\AuthRemote\User::class
        ],
  ]

Route Login & Logout published automatic

Route::get('/auth-remote/{provider}', '\LaraDevs\AuthRemote\ActionsController@redirectToProvider')->name('laravel_passport');
Route::get('/auth-remote/{provider}/callback', '\LaraDevs\AuthRemote\ActionsController@handleProviderCallback');
Route::post('/auth-remote-logout','\LaraDevs\AuthRemote\ActionsController@logout')->name('laravel_passport.logout');

Add route name for initial route

Route::get('/', function () {
    return view('welcome');
})->name(config('rest-provider.route_not_session'));