dingo / api

A RESTful API package for the Laravel and Lumen frameworks.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Laravel 5.2 + Dingo + JWT - Multiple Auth with different prefixes ???

carabationut opened this issue · comments

Q A
Bug? no
New Feature? don't know
Framework Laravel
Framework version 5.2.44
Package version 1.0.0
PHP version 7.2.0

Right now the Laravel is running as server side app with api communication.

Right now is working in production and is connected to a web angularjs app.

Actual Behaviour

I have an app in production 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 Users(Admin) section, that's why I need different urls and wanting a better routes management.

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

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

https://domain/api/* => it's very ok this (i want to keep this functionality)

Expected Behaviour

For clients I want the next prefix to work:

https://domain/client/*

Steps to Reproduce

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

Possible Solutions

I think I tried everything until now and I am stuck... Need help please. Thank you.

commented

Hi

By the sounds of things api/ is the prefix of the API route files. All API routes have to live under that prefix. If you would like to have another, you can probably set it up in your route service provider, but I don't think that is ever an approach you should take in a single app.

In any way, both the version of Dingo and Laravel that you are using are very old and neither of them are supported here (or by Laravel) anymore. You should upgrade to dingo 2 and at least laravel 5.5 to get support here - otherwise the code you are running is just too out of date to be able to support.