vendredi 31 août 2018

Laravel 5.6 Multi User Type Auth API

I have a site providing APIs for 2 different websites.

Example: merchant.mywebsite.com (merchant) mywebsite.com (normal users)

My User Model: I'm using polymorph for different type of users, userable_id determines the type of users, will have Admin, Merchant and Normal users, all have access to 3 different sites.

class User extends Authenticatable implements Auditable
{
   public function userable()
   {
      return $this->morphTo();
   }
}

API route:

Route::namespace('Api\V1')->prefix('v1')->group(function () {   

    Route::post('login', 'LoginController@login');
    Route::post('signup', 'LoginController@signup');



    Route::group(['middleware' => 'auth:api'], function() {
        Route::get('user', 'LoginController@user');
        Route::get('logout', 'LoginController@logout');        
    });
});

I would like to share the same auth functions for API call to Merchant and Normal Users, is there any way to do that?

For example, they will all need to auth in the same route:

mywebsite.com/api/v1/login but gets directed to their respective sites upon login and token.

Do i need to specify or make a custom column to identify the user type in oauth?

**I'm using Laravel Passport btw and all 3 sites are in different repos.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire