alive2212/laravel-mobile-passport

This is an illuminate package for one time authentication (OTP) with OAuth2 Base

Downloads

279

Stars

3

Version

v4.0.8

LaravelMobilePassport

Latest Version on Packagist Total Downloads Build Status StyleCI

This is where your description should go. Take a look at contributing.md to see a to do list.

Installation

Via Composer

$ composer require alive2212/laravel-mobile-passport

add to service provider 'config/app.php'

    'providers' => [
        ...
        
        /*
         * Authentication service
         */
        Alive2212\LaravelMobilePassport\LaravelMobilePassportServiceProvider::class,
    ],

if use Lumen add following service provider at then end of 'bootstrap/app.php'

$app->register(Alive2212\LaravelMobilePassport\LaravelMobilePassportServiceProvider::class);

$app->router->group([
    'namespace' => 'Alive2212\LaravelMobilePassport\Http\Controllers',
], function ($router) {
    require Alive2212\LaravelMobilePassport\LaravelMobilePassport::getDir() .
        '/lumen_routes.php';
});

migrate all database

$ php artisan migrate

add following code into AuthServiceProvider in 'boot' method

public function boot()
{
    $this->registerPolicies();

    Passport::routes();

    LaravelMobilePassport::initPassportTokenCan();

    LaravelMobilePassportSingleton::$otpCallBack = function (
        Request $request,
        User $user,
        AliveMobilePassportDevice $device,
        $token
    ) {
        // dispatch send sms job here to send notification

    };
    
    
    LaravelMobilePassportSingleton::$otpConfirmCallBack = function (
        Request $request,
        User $user,
        PersonalAccessTokenResult $token,
        ResponseModel $response
    ) {
        // put something here like update user name with request fields
        
    };
    
}
  • tip: if ENV_DEBUG in .env file set to false don't return any data in register by token

add 'phone_number' & 'country_code' into model $fillable variable:

    protected $fillable = [
        'name',
        'email',
        'password',
        'phone_number',
        'country_code',
    ];

publish vendor files with following command:

php artisan vendor:publish --tag laravel-mobile-passport.lang
php artisan vendor:publish --tag laravel-mobile-passport.config
php artisan vendor:publish --tag laravel-mobile-passport.migrations
php artisan vendor:publish --tag laravel-mobile-passport.models

User model must be extended from BaseAuthModel

In the next step you should install following package and it's version related to your laravel version.

  • phoenix/eloquent-meta
  • fico7489/laravel-pivot

Add flowing code into app\User.php

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function roles()
    {
        return $this->belongsToMany(
            AliveMobilePassportRole::class,
            'alive_mobile_passport_role_user',
            'user_id',
            'role_id'
        );
    }

Finally run following command to install passport dependency

$ art passport:install

Optional for add routes you can put following into boot method at AppServiceProvider

// add mobile passport routes
LaravelMobilePassport::routes(null,['middleware'=>'cors']);

Usage

1- create roles what you want in to alive_mobile_passport_roles *tip: title of roles must unique

You can use following to get current user scopes

$request['access_token'])

Change log

Please see the changelog for more information on what has changed recently.

Testing

$ composer test

Relation of this package with another one is:

  • array helper -> nothing
  • laravel excel helper -> nothing
  • laravel onion pattern -> nothing
  • laravel query helper -> nothing
  • laravel reflection helper -> nothing
  • laravel request helper -> nothing
  • laravel string helper -> nothing
  • laravel smart response -> array helper
  • laravel smart restful -> laravel excel helper, laravel onion pattern, laravel query helper, laravel reflection helper, laravel smart response, laravel string helper
  • laravel passport auth -> laravel smart restful

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email author email instead of using the issue tracker.

Credits

License

license. Please see the license file for more information.

Alive2212

Author

Alive2212