silverbux / laravel-angular-admin

Laravel + Angularjs + Bootstrap + AdminLTE binded by Gulp workflow Admin Dashboard Boilerplate / Starter.
http://silverbux.github.io/laravel-angular-admin/
MIT License
923 stars 414 forks source link

Laravel 5.2 + Dingo + JWT - Multiple Auth with different prefixes #116

Open carabationut opened 5 years ago

carabationut commented 5 years ago

Hi,

I have a major situation and I am stuck for a week or so with this.

So, this boilerplate works very well with multiple upgrades/updates from me for some components/server side and I have the next situation:

I want to implement (right now with no success) different auth methods using dingo and JWT, but each method to have it's prefix in url.

Short Description: I have an app in production with this boilerplate and is protected for admins with the User model/table. I want to add a table called Clients and I want a login valid from my Ionic app. They should not have the possibility to login in Admin section, that'w why I need different urls and because i want a better routes management.

Right now every request with token runs on the next URL:

https://domain/api/* => it's very ok this

For clients I want the next prefix to work:

https://domain/client/*

What I've done till now, but I struggle with DINGO API implementation:

config/auth.php

"guards" => [
     ....

     "clientapi" => [
         "driver" => "token",
         "provider" => "client",
     ]
]
"provider" => [
    .....
     "client" => [
          "driver" => "eloquent",
          "model" => App\Client:class,
     ],
]
"passwords" => [
    "client" => [
            "provider" => "client",
            "email" => "auth.emails.password",
            "table" => "password_resets",
            "expire" => 60,
        ],
] 

Created a clone after this file: config/api.php => config/clientapi.php and updated everything so the api should connect to what needs the most

I think my problem is here, or something like that:

app/Providers/RouteServiceProvider

use Illuminate\Routing\Router;
use Dingo\Api\Routing\Router as ApiRouter;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;

public function map(Router $router, ApiRouter $apiRouter)
{
        $apiRouter->version($this->version, function ($apiRouter) use ($router) {
            $apiRouter->group(['namespace' => $this->namespace], function ($api) use ($router) {
                $router->group(['namespace' => $this->namespace], function ($router) use ($api) {
                    require app_path('Http/routes.php');
                });
            });
        });

        $apiRouter->version('v2', function ($apiRouter) use ($router) {
            $apiRouter->group(['prefix' => 'clientapi', 'namespace' => $this->namespace], function ($api) use ($router) {
                $router->group(['prefix' => 'clientapi', 'namespace' => $this->namespace], function ($router) use ($api) {
                    require app_path('Http/routes-client.php');
                });
            });
        });
}

example of auth routes which sould be replicated for lcient

 // Password Reset Routes...  
$api->group(['middleware' => ['api']], function ($api) {
    $api->controller('auth', 'Auth\AuthController');

    $api->post('auth/password/email', 'Auth\PasswordResetController@sendResetLinkEmail');
    $api->get('auth/password/verify', 'Auth\PasswordResetController@verify');
    $api->post('auth/password/reset', 'Auth\PasswordResetController@reset');
});

Whatever I am trying to do or trying to adjust, seems to get me nowhere.

Every time I am trying to change $api in $cetateanapi request responds with 404 not found or errors like object not found.

I do not want only a guard method active inside controllers, I need to separate stuff from users(admins) and citizens.

Searched all over stackoverflow and laracasts forum but no luck.

I can't save the information on the same table because it is possible for an user to have a citizen account.

Thank you, Johnny