alive2212/laravel-mobile-passport

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

v1.0.27 2019-11-02 13:01 UTC

README

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/laravelmobilepassport

if use Laravel < 5.4 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
    ) {
        // dispach send sms job here to send notification
    };
    
    
    LaravelMobilePassportSingleton::$otpConfirmCallBack = function (
        Request $request,
        User $user,
        PersonalAccessTokenResult $token
    ) {
        // put somthing here like update user name with request fileds
    };
    
}

*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

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

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.