mannysoft/api-auth

Laravel package for extending Laravel Passport

0.3 2019-10-16 02:16 UTC

This package is auto-updated.

Last update: 2024-04-16 12:27:56 UTC


README

Laravel package for authentication in API.

Installation

Require this package with composer.

composer require mannysoft/api-auth
php artisan migrate
php artisan passport:install
php artisan passport:keys
php artisan vendor:publish --provider="Mannysoft\ApiAuth\ServiceProvider" --tag="migrations"

Open your oauth_clients table and look for password_client

Change your .env

APP_OAUTH_CLIENT_ID=

APP_OAUTH_CLIENT_SECRET=

Laravel 5.5 uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.

add the Laravel\Passport\HasApiTokens trait to your App\User model. This trait will provide a few helper methods to your model which allow you to inspect the authenticated user's token and scopes:

<?php

namespace App;

use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use HasApiTokens, Notifiable;
}

Update your config/services.php if you are using login with facebook

'facebook' => [
    'client_id' => env('FACEBOOK_CLIENT_ID'),
    'client_secret' => env('FACEBOOK_CLIENT_SECRET'),
    'redirect' => env('FACEBOOK_REDIRECT'),
],

Update your config/api-auth.php depending in your needs

Finally, in your config/auth.php configuration file, you should set the driver option of the api authentication guard to passport. This will instruct your application to use Passport's TokenGuard when authenticating incoming API requests:

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'passport',
        'provider' => 'users',
    ],
],

Reset Password Email

To get started, override the sendPasswordResetNotification method on your User model. Within this method, you may send the notification using any notification class you choose. The password reset $token is the first argument received by the method:

/**
 * Send the password reset notification.
 *
 * @param  string  $token
 * @return void
 */
public function sendPasswordResetNotification($token)
{
    $this->notify(new \Mannysoft\ApiAuth\Notifications\ResetPasswordNotification($token, $this->email));
}

Routes available

Route Are Cool

Configuration

Config Value Default
login_facebook
login_accountkit
login_url
logout_url
forgot_password
change_password
username
reset_password_deep_link